Question- Write a program to produce the following output:
1
2 3
4 5 6
7 8 9 10
Solution-
Honestly speaking, I myself took help to solve this problem. nice problem. check this out.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b,n=6;
for(a=1;a<=10;a++)
{
if(a==1||a==2||a==4||a==7)
{
printf("\n");
for(b=1;b<=n;b++)
{
printf(" ");
n=n-1;
}
}
printf("%d ",a);
}
return ();
}
1
2 3
4 5 6
7 8 9 10
Solution-
Honestly speaking, I myself took help to solve this problem. nice problem. check this out.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b,n=6;
for(a=1;a<=10;a++)
{
if(a==1||a==2||a==4||a==7)
{
printf("\n");
for(b=1;b<=n;b++)
{
printf(" ");
n=n-1;
}
}
printf("%d ",a);
}
return ();
}
Your solution doesnt work
ReplyDeleteIt's not working!
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteA little correction
ReplyDelete#include
#include
main()
{
int a,b,s,p=1;
clrscr ();
for (a=1;a<=4;a++)
{ for (s=4;s>=a;s--){printf (" ");}
for (b=1;b<=a;b++)
{printf("%d ",p);
p++;}
printf("\n");
}
getch ();
}
A little correction
ReplyDelete#include
#include
main()
{
int a,b,s,p=1;
clrscr ();
for (a=1;a<=4;a++)
{ for (s=4;s>=a;s--){printf (" ");}
for (b=1;b<=a;b++)
{printf("%d ",p);
p++;}
printf("\n");
}
getch ();
}