Write a C program to print given triangle of numbers.
1
1 2
1 2 3
1 2 3 4
1
1 2
1 2 3
1 2 3 4
int main() {
int n, i, j;
printf("Enter the value for n:");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
/* print the values in triangle */
for (j = 1; j <= i; j++) {
printf("%d ", j);
}
/* print new line */
printf("\n");
}
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter the value for n:5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Enter the value for n:5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
No comments:
Post a Comment