Some Intresting Design which are written using #c programming.
Qn 1. Write a program to print this ?
*
* * *
* * * * *
* * * * * * *
* *
* * * * * * *Ans:- #include "stdio.h"
main()
{
int i,j,n,sp,st=1;
printf("Enter total rows");
scanf("%d",&n);
sp=n-1;
for(i=1;i<=n;i++)
{
for(j=1;j<=sp;j++)
printf(" ");
for(j=1;j<=st;j++)
printf("*");
printf("\n");
sp=sp-1;
st=st+2;
}
}
Qn 2. Write a program to print this ?
1
121
12321
1234321
123454321
Ans:- #include "stdio.h"
main()
{
int i,j,n,sp;
printf("Enter total rows");
scanf("%d",&n);
sp=n-1;
for(i=1;i<=n;i++)
{
for(j=1;j<=sp;j++)
printf(" ");
for(j=1;j<=i;j++)
printf("%d",j);
for(j=i-1;j>=1;j--)
printf("%d",j);
printf("\n");
sp=sp-1;
}
}
Qn 3. Write a program to print this ?
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Ans:-#include <stdio.h>
int main()
{
int rows, i, j, number= 1;
printf("Enter the number of rows: ");
scanf("%d",&rows);
for(i=1; i <= rows; i++)
{
for(j=1; j <= i; ++j)
{
printf("%d ", number);
++number;
}
printf("\n");
}
return 0;
}
Qn 4. Write a program to print this ?
1
3 2
4 5 6
10 9 8 7
11 12 13 14 15
Ans:- #include "stdio.h"
main()
{
int i,j,n,k=1;
printf("Enter total rows");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==0)
{
for(j=1;j<=i;j++)
{
printf("%d
",k);
k--;
}
k=k+i+1;
}
else
{
for(j=1;j<=i;j++)
{
printf("%d
" ,k);
k++;
}
k=k+i;
}
printf("\n");
}
}
Qn 4. Write a program to print this ?
1
2
3 4
5 6
7
8
9
Ans:- #include <stdio.h>
int main()
{
int rows, i, j,sp, number= 1;
printf("Enter the number of rows: ");
scanf("%d",&rows);
sp=2*rows-3;
for(i=1; i <= rows; i++)
{
for(j=1;j<i;j++)
printf(" ");
printf("%d",number);
number++;
for(j=1;j<=sp;j++)
printf(" ");
if(i!=rows)
{
printf("%d",number);
number++;
}
sp=sp-2;
printf("\n");
}
}
Qn 5. Write a program to print this ?
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Ans:- #include<stdio.h>
void main()
{
int r, v;
for(r=1; r<=5; r++)
{
for(v=l; v<=r; v++)
printf("%d", r);
printf("\n");
}
}
Social Plugin