C program Code to write Pyramid and Pattern
I will show you more than 50 pattern programs that is helps to you make a good programming knowledge about pattern and automata programming.
Question
1: Write a program to half pyramid using *
*
*
*
*
* *
*
* * *
*
* * * *
Code
:
#include<stdio.h>
void
main(){
int
n,i,j;
printf("enter
number : ");
scanf("%d",&n);
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
printf("*
");
}
printf("\n");
}
}
output
:
Question 2: Write a program to half pyramid using *.
*
* * * *
*
* * *
*
* *
*
*
*
Code
:
#include<stdio.h>
void
main(){
int
i,n,j;
printf("enter
a number : ");
scanf("%d",
&n);
for(i=n;i>=0;--i){
for(j=i-1;j>=0;--j){
printf("*
");
}
printf("\n");
}
}
Output
:
Question 3: Write a program to half pyramid using *.
*
* * * *
*
* * *
*
* *
*
*
*
code
:
#include<stdio.h>
void
main(){
int
n,i,j;
printf("enter
a number : ");
scanf("%d",
&n);
for(i=1;i<=n;i++){
for(j=1;j<i;j++){
printf("
");
}
for(j=i;j<=n;j++){
printf("*");
}
printf("\n");
}
}
Output
:
Question 4: Write a program to half pyramid using *.
*
*
*
*
* *
*
* * *
*
* * * *
*
* * * *
*
* * *
*
* *
*
*
*
Code:
#include<stdio.h>
void
main(){
int
n,i,j;
printf("enter
a number : ");
scanf("%d",
&n);
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
printf("*
");
}
printf("\n");
}
for(i=n;i>=0;--i){
for(j=i-1;j>=0;--j){
printf("*
");
}
printf("\n");
}
}
Output
:
Comments
Post a Comment