1. Print the Half Pyramid of *.
Ans:
#include <stdio.h>
int main()
{
int i,j;
for(i=1;i<=5; i++){
for(j=1; j<=i; j++){
printf("* ");
}
printf("\n");
}
return 0;
} |
2. Print the inverted Half Pyramid of the *.
Ans:
#include <stdio.h>
int main()
{
int i,j;
for(i=5;i>=1; i--){
for(j=1; j<=i; j++){
printf("* ");
}
printf("\n");
}
return 0;
} |
3. Print the Right Half Pyramid of the *.
Ans:
#include <stdio.h>
int main()
{
int i,j;
for(i=1;i<=5; i++){
for(j=1; j<=5; j++){
if(i+j<=5){
printf(" ");
}
else {
printf("*");
}
}
printf("\n");
}
return 0;
} |
4. Print the Full Pyramid of the *.
Ans:
#include <stdio.h>
int main()
{
int i,j,space;
for(i=1; i<=5; i++){
for(space=1; space<=5-i; space++){
printf(" ");
}
for(j=1; j<=(2*i)-1; j++){
printf("* ");
}
printf("\n");
}
return 0;
} |
5. Print the Inverted Full Pyramid of the *.
Ans:
#include <stdio.h>
int main()
{
int i,j,space;
for(i=5; i>=1; i--){
for(space=1; space<=5-i; space++){
printf(" ");
}
for(j=1; j<=(2*i)-1; j++){
printf("* ");
}
printf("\n");
}
return 0;
} |
6. Print the Triangle of the *.
Ans:
#include <stdio.h>
int main()
{
int i,j,space;
for(i=1; i<=5; i++){
for(space=1; space<=5-i; space++){
printf(" ");
}
for(j=1; j<=i; j++){
printf("* ");
}
printf("\n");
}
return 0;
} |






Comments
Post a Comment