Like Tree3Likes
  • 2 Post By TheBigH
  • 1 Post By jimblumberg

please i need help for my assignment

This is a discussion on please i need help for my assignment within the C Programming forums, part of the General Programming Boards category; Write a for loop statement to print the numbers from 1 to 10 in reverse order separated by star : ...

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    5

    please i need help for my assignment

    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 ?

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,680
    Show your current code and maybe someone can point you in the right direction.

    Jim

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    5
    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

  4. #4
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    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++;
    }

  5. #5
    Registered User
    Join Date
    Apr 2013
    Posts
    5
    you mean should i do another for loop ?

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    2,680
    No, just don't print the first character in your present loop. Print it after the loop without the asterisk.

    Jim

  7. #7
    Registered User
    Join Date
    Apr 2013
    Posts
    5
    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 ?

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    2,680
    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.
    Code:
    int main(int argc, char *argv[]){
        int start;
        for (start = 10; start >= 2 ; start=start-1){
    Jim
    TheBigH likes this.

  9. #9
    Registered User
    Join Date
    Apr 2013
    Posts
    5
    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;
    }


  10. #10
    Registered User CASHOUT's Avatar
    Join Date
    Jul 2011
    Location
    Florida
    Posts
    88
    Quote Originally Posted by abo5aleil View Post
    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;
    }


    Don't include the last number in your loop.
    Print the final value after the loop, so it's not subject to receive an *

  11. #11
    Registered User
    Join Date
    Feb 2013
    Posts
    40
    why dont u use "if" statement?
    so when the number gets to 1, the * will not print.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me with my ASSIGNMENT
    By khelly in forum C++ Programming
    Replies: 1
    Last Post: 12-01-2011, 06:22 AM
  2. i seriously need help for my assignment :(
    By tianwu in forum C Programming
    Replies: 14
    Last Post: 11-26-2011, 12:34 PM
  3. Replies: 3
    Last Post: 04-26-2009, 08:54 AM
  4. First assignment help
    By FirstC++ in forum C++ Programming
    Replies: 7
    Last Post: 07-01-2004, 07:57 AM
  5. Help With Assignment Please
    By MegaVortex in forum C++ Programming
    Replies: 8
    Last Post: 03-24-2004, 08:40 PM

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