Monday, 18 June 2012

Programming Exercise 1 : for

Write a program that accept one digit and display in triangle:
Example

input: 5
output
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

The C Program Is :

#include<stdio.h>
void main()

{
int i, n, j;
printf ("\n Please Enter Single Digit Number");
scanf("%d",&n);
for(i=1; i<=n; i++)
     {
      for(j=1; j<=i; j++)
      printf("%d",j);
      printf("\n");
      }
}

0 comments:

Post a Comment