Q. Write a C program to display the following pattern:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Ans.
/*program to design the above pattern*/
#include<stdio.h>
#include<conio.h>
void main()
int r,c,n=1;
clrscr();
for(r=1; r<=5; r++)
{
for(c=1; c<=r; c++)
{
printf("%3d",n++);
}
printf("\n");
}
getch();
}
Output:-
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
this program is error, some change are required;
ReplyDelete#include
main()
{
int r,c, n=1;
for(r=1; r<=5; r++)
{
for(c=1; c<=r; c++)
{
printf("%3d",n);
n++;
}
printf("\n");
}
getchar();
}
last code ma error che
ReplyDeletegetch();
Error has been fix.
ReplyDeleteThanks Kesav and Raj chovatiya for improving C programming.