Thread: Help! How to enter values in a specific format

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    13

    Help! How to enter values in a specific format

    I want to enter the values in this format:
    2
    7 8 9
    1 2 3
    7 8
    4
    4 5 6
    7 5 3
    4 0 9
    7 3 6
    7 3
    7 6
    1 5
    0

    the first line is an integer 'n', following will be of 3 integers in each n lines, then 2 integers in each n-1 lines, if the next value is equal to ZERO then terminate else continue to accept the values in the same format.
    Code:
    #include<stdio.h>
    main()
    { int a[100][10]={0},b[100][10]={0},i,j=-1,n,nxt;
    
    do
    {
        i=-1;
        j++;
    scanf("%d",&n);
     do{
         i=i+1;
         scanf("%d",&a[i][j]);
         printf(" part1\n ");
     }while(i<3*n-1);
    
    i=-1;
     do{
         i=i+1;
         scanf("%d",&b[i][j]);
         printf(" part2\n ");
     }while(i<n-1);
     scanf("%d",&nxt);
    }while(nxt!=0);
     return 0;
     }
    please help

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Forget the code for awhile, and look for the pattern you see when you do this by hand, you'll want to work it through by hand, a few times. Note the pattern you follow as you do so:

    get a number: n
    print n rows of digits, with three digits each
    then print --n number of rows with (the new n's), number of digits

    until --n is one.

    You'll find this a lot easier if you use separate functions for the printing, and just call them in a loop.

    Have you used separate functions before?

    And welcome to the forum! :cool;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 11-27-2011, 04:45 PM
  2. picking out specific values from an array
    By jak9 in forum C Programming
    Replies: 7
    Last Post: 10-13-2010, 01:05 PM
  3. Restricting a type to a specific set of values...
    By DarkMasterBosel in forum C++ Programming
    Replies: 8
    Last Post: 01-01-2008, 11:16 PM
  4. Replies: 3
    Last Post: 01-23-2006, 07:25 PM
  5. Replies: 4
    Last Post: 03-22-2002, 05:30 PM

Tags for this Thread