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