Thread: try to do this !!!

  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
    28,413
    Hint:

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

    Where I use "**" to mean "to the power of"
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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.

Popular pages Recent additions subscribe to a feed