try to do this !!!

This is a discussion on try to do this !!! within the C Programming forums, part of the General Programming Boards category; hello all hulls I want to make a program that displays 1 /*deg=0*/ 11 /*degs =1*/ 121 /*degs =2*/ 1331 ...

  1. #1
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159

    Arrow try to do this !!!

    hello all hulls
    I want to make a program that displays

    1 /*deg=0*/
    11 /*degs =1*/
    121 /*degs =2*/
    1331 /*degs =3*/
    14641 /*degs =4/*
    .....
    deg is a variable

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    Hint:

    11**0 = 1
    11**1 = 11
    11**2 = 121

    Where I use "**" to mean "to the power of"
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I smell homework.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    thank you laserlight but you must use this
    Code:
    pow(11,0);

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    Quote Originally Posted by enjoy
    thank you laserlight but you must use this
    Code:
    pow(11,0);
    err...
    I was just giving some form of mathematical notation.
    Some people use "**", others use "^" (which I normally prefer), but in this case "^" could be confused with XOR.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    O.K i understand now
    thanks again

  7. #7
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    Code:
     :D 
    #include "stdio.h"
    void main()
    {
    	int i,deg;
    	printf("give me your deg please\n");
    	scanf("%d",&deg);
    	
    	for(i=0;i<=deg;i++)
    	{
    		
    	printf("%d\n",(11^i));
    	}
    }
    try to compile this !!!!!!
    with 0 is ok
    but deg>0 ====> wrong
    help me please

  8. #8
    Registered User
    Join Date
    May 2004
    Posts
    127
    The ^ operator is a bitwise exclusive OR, not exponentiation. Your code is also very bad. Here is an improvement that works better.
    Code:
    #include <math.h>
    #include <stdio.h>
    
    int main()
    {
      int i,deg;
      printf("give me your deg please\n");
      scanf("%d",&deg);
    
      for(i=0;i<=deg;i++)
      {
        printf("%.0f\n", pow(11.0,i));
      }
    
      return 0;
    }

  9. #9
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    Code:
    thank you neuhart
    but i don't like to use pow
    and i have this code
    try to optimize him
    Code:
    #include "stdio.h"
    void main()
    {
    	int i,deg,f=1,k;
    	printf("give me your deg please\n");
    	scanf("%d",&deg);
    	
    	for(i=0;i<=deg;i++)
    	{
    		if(i==0){f=11;}
    	else{for(k=0;k<i-1;k++){f=f*(11*11);}}
    	printf("%d\n",f);
    			}
    			
    
    }

  10. #10
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    so i try another code but he don't compile
    here is my code
    Code:
    #include "stdio.h"
    #define n 100
    void main()
    {
    	int deg,k,i,j,s,t[n][n];
    	
    	
    	printf("donnez votre deg\n");
    	scanf("%d",&deg);
    
    	for(j=0;j<deg;j++)
    {	
    	for(i=0;i<deg+1;i++)
    	
    	{
    		t[j][i]=0;
    	}
    }
    	
    	
    	
    	
    	for(j=0;j<deg;j++)
    {	
    for(i=0;i<deg+1;i++)
    {
    				
    			if(((i==0)&&(j==0))||((i==1)&&(j<2)))
    			{
    		    
    				t[j][i]=1;
    			
    			}
    		    
    			else 
    			{
    				s=0;
    				for(k=0;k<deg;k++)
    				{
    					s=s+t[j-1][i+k];
    				}
    			t[j][i]=s;
    			}
    	}
    }
    for(j=0;j<deg;j++)
    {	
    for(i=0;i<deg+1;i++)
    {
    	if (i==j+1){printf("\n");}
    	else
    	{
    	printf("%d",t[j][i]);
    	}
    }
    }
    }

  11. #11
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    Code:
    help me to compile only one please

  12. #12
    Registered User
    Join Date
    May 2004
    Posts
    127
    >but i don't like to use pow
    You don't have many choices. You can either use pow, an easier and cleaner approach, or you can do it manually.

    >try to optimize him
    Why are you trying to optimize code that doesn't even work correctly in the first place?

  13. #13
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > but i don't like to use pow
    So write a function called mypow() which looks almost identical to pow()

    And stop using void main()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21