Write a C program to print following pattern up to n lines
Write a C Program to print Pyramid pattern.
*
* *
* * *
* * * *
* * * * *
#include<stdio.h>
int main()
{
int i,j,n,sp;
printf(“Enter no.of line want : “);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
printf(” “);
for(j=0;j<=i;j++)
printf(“* “);
printf(“\n”);
}
return 0;
}
Output:
Enter number of lines you want: 9
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
For improvement of your coding skills we give some tasks along with it. If you solve this tasks and send to our email (onlineexamshubteam@gmail.com) with your details. We will display your details(like Name, City, college, photo) in our site.
Task: Pattern Program in C, Write a c program to print n lines of following triangle. Following pattern contains 5 lines.
* * * * *
* * * *
* * *
* *
*
Write a C Program to print triangle pattern.
*
**
***
****
*****
#include<stdio.h>
int main()
{
int i,j,n;
printf(“Enter no.of lines you want : “);
scanf(“%d”,&n);
for(i=0;i < n;i++)
{
for(j=0;j<=i;j++)
printf(“* “)
printf(“\n”);
}
return 0;
}
Output:
Enter number of lines you want : 6
*
* *
* * *
* * * *
* * * * *
* * * * * *
For improvement of your coding skills we give some tasks along with it. If you solve this tasks and send to our email (onlineexamshubteam@gmail.com) with your details. We will display your details(like Name, City, college, photo) in our site.
Task: Pattern Program in C, Write a c program to print n lines of following triangle. Following pattern contains 5 lines.
*****
****
***
**
*
To print following pattern program in C.
*
**
***
****
*****
#include<stdio.h>
int main()
{
int i,j,n,sp;
printf(“Enter no.of line want : “);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
printf(” “);
for(j=0;j<=i;j++)
printf(“*”);
printf(“\n”);
}
return 0;
}
Output:
Enter number of lines you want : 6
*
**
***
****
*****
******
For improvement of your coding skills we give some tasks along with it. If you solve this tasks and send to our email (onlineexamshubteam@gmail.com) with your details. we will display your details(like Name, City, college, photo) in our site.
Task: Pattern Program in C, Write a c program to print n lines of following triangle. Following pattern contains 3 lines.
**
****
******
Write a c program to print pyramid pattern of numbers.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
#include<stdio.h>
int main()
{
int i,j,n,sp;
printf(“Enter no.of line want : “);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
printf(” “);
for(j=0;j<=i;j++)
printf(“%d “, j+1);
printf(“\n”);
}
return 0;
}
Output:
Enter number of lines you want: 4
1
1 2
1 2 3
1 2 3 4
For improvement of your coding skills we give some tasks along with it. If you solve this tasks and send to our email (onlineexamshubteam@gmail.com) with your details. we will display your details(like Name, City, college, photo) in our site.
Task: Pattern Program in C, Write a c program to print n lines of following triangle. Following pattern contains 4 lines.
1
123
12345
1234567
To print following half pyramid pattern program in C.
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
#include<stdio.h>
int main()
{
int i,j,n;
printf(“Enter no.of line want : “);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
printf(“%d “,i+1);
printf(“\n”);
}
return 0;
}
Output:
Enter number of lines you want : 7
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
For improvement of your coding skills we give some tasks along with it. If you solve this tasks and send to our email (onlineexamshubteam@gmail.com) with your details. We will display your details(like Name, City, college, photo) in our site.
Task: Pattern Program in C, Write a c program to print n lines of following triangle. Following pattern contains 5 lines.
A
B B
C C C
D D D D
E E E E E
Write a C Program to print numbers half pyramid.
1
2 3
4 5 6
7 8 9 10
#include<stdio.h>
int main()
{
int i,j,n,count=1;
printf(“Enter no.of line want : “);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
printf(“%d “,count++);
printf(“\n”);
}
return 0;
}
Output:
Enter number of lines you want : 3
1
2 3
4 5 6
For improvement of your coding skills we give some tasks along with it. If you solve this tasks and send to our email (onlineexamshubteam@gmail.com) with your details. We will display your details(like Name, City, college, photo) in our site.
Task: Pattern Program in C, Write a C Program to print numbers(Even numbers) half pyramid. Like following pattern
2
2 4
2 4 6
2 4 6 8
2 4 6 8 10
Write a C Program to print Pyramid pattern.
1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
#include <stdio.h>
int main()
{
int i,j,n;
printf(“Enter a number: “);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
for(j=0;j<(n*2)-(i*2);j++)
printf(” “);
for(j=0;j<=i;j++)
printf(“%d “,j+i+1);
for(j=i;j>0;j- -)
printf(“%d “,j+i);
printf(“\n”);
}
return 0;
}
Output:
Enter a number: 6
1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
6 7 8 9 10 11 10 9 8 7 6
Write a C Program to following pyramid pattern.
*
$ $
# # #
* * * *
$ $ $ $ $
# # # # # #
#include <stdio.h>
int main()
{
int i,j,n;
printf(“Enter a number: “);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
printf(” “);
for(j=0;j<=i;j++)
{
if(i%3==0)
printf(“* “);
else if(i%3==1)
printf(“$ “);
else
printf(“# “);
}
printf(“\n”);
}
return 0;
}
Output:
Enter a number: 8
*
$ $
# # #
* * * *
$ $ $ $ $
# # # # # #
* * * * * * * *
$ $ $ $ $ $ $ $
Write a C Program to following pyramid pattern.
*
*A*
*B*C*
*D*E*F*
*G*H*I*J*
#include<stdio.h>
void main()
{
int i,j,n;
char c=’A’;
printf(“Enter a number: “);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
printf(” “);
for(j=1;j<=i;j++)
printf(“*%c”,c++);
printf(“*\n”);
}
}
Output:
Enter a number: 6
*
*A*
*B*C*
*D*E*F*
*G*H*I*J*
*K*L*M*N*O*
Write a C Program to print following pattern.
12345
23451
34512
45123
51234
#include <stdio.h>
void main()
{
int i,j,n;
printf(“Enter a number: “);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf(“%d”,((j+i)%n)+1);
printf(“\n”);
}
}
Output:
Enter a number: 6
123456
234561
345612
456123
561234
612345
Write a C Program to print numbers half pyramid.
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
#include<stdio.h>
int main()
{
int i,j,k=1,n;
int m[15][15]={0};
printf(“Enter a number: “);
scanf(“%d”,&n);
for(i=0;i<n;i++)
for(j=i;j<n;j++)
m[j][i]=k++;
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
if(m[i][j]==0)
continue;
printf(“%d “,m[i][j]);
}
printf(“\n”);
}
return 0;
}
Output:
Enter a number: 6
1
2 7
3 8 12
4 9 13 16
5 10 14 17 19
6 11 15 18 20 21