Thread: Looping

  1. #1
    Registered User
    Join Date
    Nov 2012
    Location
    Quezon City, Philippines, Philippines
    Posts
    34

    Looping

    Can someone help me make a simple looping that will print an output of the following.. I cant make a print out of it Please help me..
    5
    1
    4
    2
    3
    3
    2
    4
    1
    5
    Thank you so much !

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Sure - What have you done so far
    Fact - Beethoven wrote his first symphony in C

  3. #3
    Registered User
    Join Date
    Nov 2012
    Location
    Quezon City, Philippines, Philippines
    Posts
    34
    Frankly speaking,
    This is what I just have for now =((

    Code:
    #include<stdio.h>
    main()
    {
           int n,m;
           for(n=5;n>=1;n--){
           printf("\n%d",n);
           }
           getch();
    }
    Am I doing it right?
    I still got 2 more hours before our Final Exam =((

    EDIT:
    Code:
    #include<stdio.h>
    main()
    {
           int n,m;
           for(n=5;n>=1;n--){
           if(n==5){
           printf("\n%d",n);
           }
           if(n==1){
           printf("\n%d",n);
           }
           }
           getch();
    }
    Last edited by chanhalzkie; 11-14-2012 at 08:13 PM.

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I am not sure what the significance of the numbers is supposed to be. I suppose putting them in an array would be cheating ...

  5. #5
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    I still got 2 more hours before our Final Exam...
    So this is the end of a C programming class?
    Fact - Beethoven wrote his first symphony in C

  6. #6
    Registered User
    Join Date
    Nov 2012
    Posts
    23
    Code:
    int i,j;
    for(i=5,j=1;i>0;i--,j++) printf("%d\n%d\n",i,j);
    or you can put them in an array and print them, what they rapresent?

  7. #7
    Registered User
    Join Date
    Nov 2012
    Location
    Quezon City, Philippines, Philippines
    Posts
    34
    Quote Originally Posted by Click_here View Post
    So this is the end of a C programming class?
    Yes I think for First Year, First Term..

  8. #8
    Registered User
    Join Date
    Nov 2012
    Location
    Quezon City, Philippines, Philippines
    Posts
    34
    Quote Originally Posted by root View Post
    Code:
    int i,j;
    for(i=5,j=1;i>0;i--,j++) printf("%d\n%d\n",i,j);
    or you can put them in an array and print them, what they rapresent?
    Thank you Thank you so much guys!!

  9. #9
    Registered User
    Join Date
    Nov 2012
    Posts
    23
    I don't really think that this exercise may help you to pass an exam 2 hours before it..

  10. #10
    Registered User
    Join Date
    Nov 2012
    Location
    Quezon City, Philippines, Philippines
    Posts
    34
    Quote Originally Posted by root View Post
    I don't really think that this exercise may help you to pass an exam 2 hours before it..
    This is already a big help for me..
    I just knew that you can actually print 2 outputs in just 1 printf xD
    Now I know what to do next
    Thank you thank you so much !

  11. #11
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    I just knew that you can actually print 2 outputs in just 1 printf
    Study hard my friend, study hard.
    Fact - Beethoven wrote his first symphony in C

  12. #12
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    The printf is not the most interesting thing about that code. The loop arguments are the interesting part.

  13. #13
    Registered User
    Join Date
    Nov 2012
    Location
    Quezon City, Philippines, Philippines
    Posts
    34
    Again, Thank you so much guys!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. looping do while
    By bazzano in forum C Programming
    Replies: 1
    Last Post: 03-07-2006, 01:46 AM
  2. help with looping.
    By tdoctasuess in forum C Programming
    Replies: 1
    Last Post: 05-13-2004, 01:00 PM
  3. Looping
    By hmr_smpsn_57 in forum C++ Programming
    Replies: 15
    Last Post: 02-24-2004, 05:08 PM
  4. Looping
    By Vorkosigan in forum C++ Programming
    Replies: 2
    Last Post: 01-22-2004, 07:45 PM
  5. help in tic tac toe with looping only
    By amreena in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2003, 07:42 AM