Write a for loop statement to print the numbers from 1 to 10 in reverse order separated by star :
10*9*8*7*6*5*4*3*2*1
i try to do it but it show me like this :
10*9*8*7*6*5*4*3*2*1*
how do i write to show me like the first one ?
Write a for loop statement to print the numbers from 1 to 10 in reverse order separated by star :
10*9*8*7*6*5*4*3*2*1
i try to do it but it show me like this :
10*9*8*7*6*5*4*3*2*1*
how do i write to show me like the first one ?
Show your current code and maybe someone can point you in the right direction.
Jim
Code:int main(int argc, char *argv[]) { for (int start = 10; start >= 1 ; start=start-1){ printf("%d*",start); } return 0; }
here is my code
So your problem is that there is a star at the end of the string, but you don't want it there?
Why not loop down to 2, and then print the last 1 outside the loop?
Code:while(!asleep) { sheep++; }
you mean should i do another for loop ?
No, just don't print the first character in your present loop. Print it after the loop without the asterisk.
Jim
Code:int main(int argc, char *argv[]){ for (int start = 10; start >= 2 ; start=start-1){ printf("%d*",start); } for(int x =1; x>= 1; x--) { printf("%d",x); } return 0; }
is that right ?
No, I said you don't need two loops. Why do you have tow loops?
But you will need to define start before your loop.
JimCode:int main(int argc, char *argv[]){ int start; for (start = 10; start >= 2 ; start=start-1){
i am really sorry but my Engilsh is weak . but i don't understand
how I print the last 1 outside the loop
Code:Code:int main(int argc, char *argv[]) { int start; for (int start = 10; start >= 2 ; start=start-1) { printf("%d*",start); } return 0; }
why dont u use "if" statement?
so when the number gets to 1, the * will not print.