Thread: Hints to write a program

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Start simple, and implement one thing at a time. Compile the program and run it (even if you can't see anything) after each thing you add.

    In this case, maybe you start by outputting a specific number horizontally that you type into the program, like 8. Compile and run it. Then maybe you add code that reads in a single integer. Compile and run it. Then maybe you combine those two so that it reads in a single integer and displays that horizontally instead of 8. Compile and run it. Then maybe you add a loop to do that 5 times. Compile and run it.

  2. #2
    Registered User
    Join Date
    Mar 2006
    Posts
    34
    My best guess is that the program has to do the following:

    Suppose 5,4,3,2,1 are the 5 integers input. Then the output should be something like:

    5 4 3 2 1
    4 3 2 1
    3 2 1
    2 1
    1

    I have done the following:

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    int main()
    {
    
     int a;
     int b;
    
    
     cout<<"Enter 5 Integers:";
     cin >> a,b;
    
     for( ; a>0; a--){
          for( ; b>0; b--);
     cout << a,b;
                      }
    
          system("PAUSE");
          return 0;
    }
    If I only use the first for statement, I get 54321 after inputing 5. But once I add the second integer, I only get output for the first integer, none for the second.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. Replies: 6
    Last Post: 01-01-2007, 07:36 AM
  3. Replies: 1
    Last Post: 10-13-2004, 12:15 PM
  4. Can I write & read file in same program?
    By chad03 in forum C Programming
    Replies: 2
    Last Post: 08-04-2003, 08:39 AM
  5. Challenge to write a program
    By Twisted.alice in forum A Brief History of Cprogramming.com
    Replies: 40
    Last Post: 05-15-2003, 12:00 PM