Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*this code is to print a pyramid of stars*/
- #include<stdio.h>
- void fullPyramid();
- void leftPyramid();
- void rightPyramid();
- int main(){
- int choice;
- printf("\nwhat type of star pyramid do u want? \n 1. Full pyramid \n 2. Half pyramid\n enter choice:");
- scanf("%d",&choice);
- puts("\n\n");
- if(choice==1){
- fullPyramid();
- }
- else if(choice==2){
- printf("\n 3.Left Half pyramid\n 4.Right Half pyramid\n enter choice:");
- scanf("%d",&choice);
- if(choice==3){
- leftPyramid();
- }
- else if(choice==4){
- rightPyramid();
- }
- }
- return 0;
- }
- void fullPyramid(){
- int rows=1,n=0,temp=0;
- for(int z=0;z<100;z++){
- printf("---");
- }
- puts("\n\n");
- printf("enter the number of rows: ");
- scanf("%d",&n);
- temp=n;
- for(rows=1;rows<=n;rows++,temp--){//this is for number of rows
- for(int i=0;i<temp;i++){// this is for printing spaces
- printf(" ");
- }
- for(int i=0;i<(2*rows-1);i++){// this is for printing stars
- printf("*");
- }
- printf("\n");
- }
- }
- void leftPyramid(){
- int rows=1,n=0,temp=0;
- for(int z=0;z<100;z++){
- printf("---");
- }
- puts("\n\n");
- printf("enter the number of rows: ");
- scanf("%d",&n);
- temp=n;
- for(rows=1;rows<=n;rows++,temp--){//this is for number of rows
- for(int i=0;i<temp;i++){// this is for printing spaces
- printf(" ");
- }
- for(int i=0;i<rows;i++){// this is for printing stars
- printf("*");
- }
- printf("\n");
- }
- }
- void rightPyramid(){
- int rows=1,n=0,temp=0;
- for(int z=0;z<100;z++){
- printf("---");
- }
- puts("\n\n");
- printf("enter the number of rows: ");
- scanf("%d",&n);
- temp=n;
- for(rows=1;rows<=n;rows++,temp--){//this is for number of rows
- for(int i=0;i<rows;i++){// this is for printing stars
- printf("*");
- }
- for(int i=0;i<temp;i++){// this is for printing spaces
- printf(" ");
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement