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
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
Hint:
11**0 = 1
11**1 = 11
11**2 = 121
Where I use "**" to mean "to the power of"
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I smell homework.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
thank you laserlight but you must use this
Code:pow(11,0);
err...Originally Posted by enjoy
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
O.K i understand now
thanks again
try to compile this !!!!!!Code::D #include "stdio.h" void main() { int i,deg; printf("give me your deg please\n"); scanf("%d",°); for(i=0;i<=deg;i++) { printf("%d\n",(11^i)); } }
with 0 is ok
but deg>0 ====> wrong
help me please
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",°); for(i=0;i<=deg;i++) { printf("%.0f\n", pow(11.0,i)); } return 0; }
but i don't like to use powCode:thank you neuhart
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",°); 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); } }
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",°); 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]); } } } }
Code:help me to compile only one please
>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?
> 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.