View Single Post
Old 05-28-2005, 06:34 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,709
redhead is on a distinguished road
You need to think of nested loops, one loop running teh desired number of times for the rows you want to print, and one within running the required number of times, for the accepted columns.

hmmm.. lets see, I'll try to do this without testing..
Code:
#include <stdio.h>
#include <stdlib.h>
#define LENGTH 8 /* only upto 8 digit numbers accepted */
int main()
{
  char temp[LENGTH +1];
  int count = 0, i, j;
  printf("Input desired run: ");
  fflush(stdout);
  if(!fgets(temp, LENGTH, stdin)){
    printf("Error reading user input\n");
    return -1;
  }
  if(0 >= (count = atoi(temp))){
    printf("Error given number is unaccepted\n");
    return -1;
  }
  for(i = 0; i <= count; ++i)
    {
      for(j = 1; j <= i; ++j)
        printf("%d", j);
      printf("\n");
    }
  return 0;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote