C program to print different shapes using printf function


Different shapes by printf function in c

1
Write a c program to print following shape.
*****
*****
*****
Answer
#include<stdio.h>
void main(){
    int i,j;
  
    for(i=0;i<5;i++){
       for(j=0;j<5;j++){
           printf("*");
       }
       printf("\n");
    }
    return 0;
}

2
Write a c program to print following shape.
*
**
***
****
*****
******
*******
Answer
#include<stdio.h> 
int main(){
    int i,j;
    for(i=0;i<8;i++){
       for(j=0;j<i;j++){
           printf("*");
       }
       printf("\n");
    }
    return 0;
}

3
Write a c program to print following shape.
**
****
******
********
**********
************
Answer
#include<stdio.h>  
int main(){
    int i,j;
    for(i=0;i<8;i++){
       for(j=0;j<=2*i-3;j++){
           printf("*");
}
         printf("\n");
    }
    return 0;
}

4
Write a c program to print following shape.
*
***
*****
*******
*********
Answer
#include<stdio.h> 
int main(){
    int i,j;
    
    for(i=0;i<6;i++){
       for(j=0;j<=2*i-2;j++){
           printf("*");
       }
       printf("\n");
    }
    return 0;
}

5
Write a c program to print following shape.
*
****
*******
**********
Answer
#include<stdio.h> 
int main(){
    int i,j;
    
    for(i=0;i<5;i++){
       for(j=0;j<3*i-2;j++){
           printf("*");
       }
       printf("\n");
    }
    return 0;
}

6
Write a c program to print following shape.
******
*****
****
***
**
*
Answer
#include<stdio.h> 
int main(){
    int i,j;
    
    for(i=0;i<6;i++){
       for(j=0;j<6-i;j++){
           printf("*");
       }
       printf("\n");
    }
    return 0;
}

7
Write a c program to print following shape.
********
******
****
**
Answer
#include<stdio.h> 
int main(){
    int i,j;
    
    for(i=0;i<6;i++){
       for(j=0;j<8-2*i;j++){
           printf("*");
       }
       printf("\n");
    }
    return 0;
}

8
Write a c program to print following shape.
*********
*******
*****
***
*
Answer

#include<stdio.h> 

int main(){
    int i,j;
    
    for(i=0;i<6;i++){
       for(j=0;j<=8-2*i;j++){
           printf("*");
       }
       printf("\n");
    }
    return 0;
}

9
Write a c program to print following shape.
**
****
********
****************
Answer
#include<stdio.h> 
#include<math.h>
int main(){
    int i,j;
    
    for(i=0;i<4;i++){
       for(j=0;j<2*pow(2,i);j++){
           printf("*");
       }
       printf("\n");
    }
    return 0;
}

10
Write a c program to print following shape.
*
**
****
********
Answer
#include<stdio.h> 
#include<math.h>
int main(){
    int i,j;
    
    for(i=0;i<4;i++){
       for(j=0;j<pow(2,i);j++){
           printf("*");
       }
       printf("\n");
    }
    return 0;
}

11
Write a c program to print following shape.
*
***
*********
***************************
Answer
#include<stdio.h> 
#include<math.h>
void main(){
    int i,j;
    
    for(i=0;i<4;i++){
       for(j=0;j<pow(3,i);j++){
           printf("*");
       }
       printf("\n");
    }
    return 0;
}

12
Write a c program to print following shape.
***
*********
Answer
#include<stdio.h> 
#include<math.h>
int main(){
    int i,j;
    for(i=0;i<3;i++){
       for(j=0;j<3*pow(3,i);j++){
           printf("*");
       }
       printf("\n");
    }
    return 0;
}

13
Write a c program to print following shape.
 *
 * *
 * * *
 * * * *
Answer
#include<stdio.h> 
#include<math.h>
int main(){
    int i,j;
    char c='*';
    
    for(i=0;i<5;i++){
       for(j=0;j<i;j++){
           printf("%*c",2,c);
       }
       printf("\n");
    }
    return 0;
}

14
Write a c program to print following shape.
*
**
***
****
Answer
#include<stdio.h> 
#include<math.h>
int main(){
    int i,j;
    char * c="*******";
    
    for(i=0;i<5;i++){
       printf("%*.*s\n",i,i,c);
    }
    return 0;
}

15
Write a c program to print following shape.
      *
      **
      ***
      ****
Answer

#include<stdio.h> 
#include<math.h>
int main(){
    int i,j;
    char * c="*******";
    
    for(i=0;i<5;i++){
       printf("%*.*s\n",i+6,i,c);
    }
    return 0;
}

16

Write a c program to print following shape.
      *
     **
    ***
   ****
  *****
 ******
*******
Answer

#include<stdio.h> 
int main(){
    char *ptr="*******";
    int i,j;
    
    for(i=0;i<8;i++){
       printf("%*.*s\n",8,i,ptr);
    }
    return 0;
}

17

Write a c program to print following shape.
    *
   ***
  *****
 *******
*********
Answer

#include<stdio.h> 
int main(){
    char *ptr="*********";
    int i,j;
    
    for(i=0;i<5;i++){
       printf("%*.*s\n",5+i,2*i+1,ptr);
    }
    return 0;
}

18

Write a c program to print following shape.
    *
   ***
  *****
 *******
*********
*********
 *******
  *****
   ***
    *
Answer

#include<stdio.h> 
int main(){
    char *ptr="*********";
    int i,j;
    
    for(i=0;i<10;i++){
       if(i<5)
         printf("%*.*s\n",5+i,2*i+1,ptr);
       else
         printf("%*.*s\n",14-i,19-2*i,ptr);
    }
    return 0;
}

19

Write a c program to print following shape.
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *
Answer

#include<stdio.h> 
int main(){
    char *ptr="*********";
    int i,j;
    
    for(i=0;i<9;i++){
       if(i<5)
         printf("%*.*s\n",5+i,2*i+1,ptr);
       else
         printf("%*.*s\n",13-i,17-2*i,ptr);
    }
    return 0;
}

20

Write a c program to print following shape.
 *********
 *******
  *****
   ***
    *
Answer

#include<stdio.h> 
int main(){
    char *ptr="*********";
    int i,j;
    
    for(i=0;i<5;i++){
       printf("%*.*s\n",9-i,9-2*i,ptr);
    }
    return 0;
}

21

Write a c program to print following shape.
    *
   **
  ***
 ****
*****
 ****
  ***
   **
    *
Answer

#include<stdio.h> 
int main(){
    char *ptr="*****";
    int i,j;
    
    for(i=0;i<10;i++){
       if(i<6)
         printf("%*.*s\n",5,i,ptr);
       else
         printf("%*.*s\n",5,10-i,ptr);
    }
    return 0;
}


22

Write a c program to print following shape.
*
**
***
****
*****
****
***
**
*
Answer

#include<stdio.h>  
int main(){
    char *ptr="*****";
    int i,j;
    
    for(i=1;i<10;i++){
       if(i<6)
         printf("%*.*s\n",0,i,ptr);
       else
         printf("%*.*s\n",0,10-i,ptr);
    }
    return 0;
}

23

Write a c program to print following shape.
    *
   ***
  *****
 *******
*********
*********
*********
***   ***
***   ***
***   ***
***   ***
Answer

#include<stdio.h> 
int main(){
    char *ptr="*********";
    int i,j;
    
    for(i=0;i<11;i++){
       if(i<5)
           printf("%*.*s\n",5+i,2*i+1,ptr);
       else{
           if(i==7){
               *(ptr+3)=' ';
               *(ptr+4)=' ';
               *(ptr+5)=' ';
           }
           printf("%*.*s\n",9,9,ptr);
       }
    }
    return 0;
}

Post a Comment