Program No. 1
*
*
*
*
*
#include<stdio.h>
main()
{
int i=1;
while(i<=5)
{
printf("\n*");
i++;
}
}
i i<=5 o/p
Program No. 2
* * * * *
* * * * *
#include<stdio.h>
main()
{
int row,col;
row=col=1;
while(row<=2)
{
while(col<=5)
{
if(col%2==0)
printf(" ");
else
printf("*");
col++;
}
row++;
col=1;
printf("\n");
}
}
Tracing :
row col row<=2 col<=5 o/p
1 1 1<=2T 1<=5T *****
2 2<=5T
3 3<=5T
'
5 5<=5T
6 6<=5F
2 1 2<=2T 1<=5T *****
2 2<=5T
'
5 5<=5T
6 6<=5F
3 1 3<=2F
Program No. 3
**
**
**
**
**
*****
*****
#include<stdio.h>
main()
{
int row,col;
row=col=1;
while(row<=2)
{
while(col<=5)
{
if(col%2==0)
printf(" ");
else
printf("*");
col++;
}
row++;
col=1;
printf("\n");
}
}
Program No. 4
*****
****
*****
****
*****
#include <stdio.h>
int main()
{
int row,col;
row=col=1;
while(row<=5)
{
while(col<=5)
{
if(row%2==0 && col<=4)
printf("*");
else if(row%2!=0)
printf("*");
col++;
}
row++;
col=1;
printf("\n");
}
return 0;
}
Program No. 5
*****
* *
* *
* *
* *
#include <stdio.h>
int main()
{
int row,col;
row=col=1;
while(row<=5)
{
while(col<=5)
{
if(row==1)
printf("*");
else if(row>=2 && (col==1 || col==5))
printf("*");
else
printf(" ");
col++;
}
row++;
col=1;
printf("\n");
}
return 0;
}
Program No. 6
* *
* *
* *
* *
*****
#include <stdio.h>
int main()
{
int row,col;
row=col=1;
while(row<=5)
{
while(col<=5)
{
if(row==5)
printf("*");
else if(row<=4 && (col==1 || col==5))
printf("*");
else
printf(" ");
col++;
}
row++;
col=1;
printf("\n");
}
}
Program No. 7
*****
*
*
*
*****
#include <stdio.h>
int main()
{
int row,col;
row=col=1;
while(row<=5)
{
while(col<=5)
{
if(row==1 || row==5)
printf("*");
else if(row>=2 && row<=4 && col==1)
printf("*");
else
printf(" ");
col++;
}
row++;
col=1;
printf("\n");
}
}
Program No. 8
*****
*
***
*
*****
#include <stdio.h>
int main()
{
int row,col;
row=col=1;
while(row<=5)
{
while(col<=5)
{
if(row==1 || row==5)
printf("*");
else if((row==2 || row==4) && col==1)
printf("*");
else if(row==3 && col<=3)
printf("*");
col++;
}
row++;
col=1;
printf("\n");
}
return 0;
}
Program No. 9
*****
*
***
*
*
#include <stdio.h>
int main()
{
int row,col;
row=col=1;
while(row<=5)
{
while(col<=5)
{
if(row==1 )
printf("*");
else if(row==3 && col<=3)
printf("*");
else if((row==2 || row==4 || row==5) && col==1)
printf("*");
col++;
}
row++;
col=1;
printf("\n");
}
return 0;
}
Program No. 10
*****
*
*
*
*****
#include<stdio.h>
main()
{
int row,col;
row=col=1;
while(row<=5)
{
while(col<=5)
{
if(row==1 || row==5)
printf("*");
else if(row>1 && row<5 && col==3)
printf("*");
else
printf(" ");
col++;
}
row++;
col=1;
printf("\n");
}
}
Program No. 11
*
**
***
****
*****
#include <stdio.h>
main()
{
int row,col;
row=col=1;
while(row<=5)
{
while(col<=row)
{
printf("*");
col++;
}
row++;
col=1;
printf("\n");
}
}
Program No. 12
*****
****
***
**
*
#include <stdio.h>
main()
{
int row,col;
row=5;
col=1;
while(row>=1)
{
while(col<=row)
{
printf("*");
col++;
}
row--;
col=1;
printf("\n");
}
}
Program No. 13
*
**
***
****
*****
****
***
**
*
#include <stdio.h>
main()
{
int row,col;
row=col=1;
while(row<=5)
{
while(col<=row)
{
printf("*");
col++;
}
row++;
col=1;
printf("\n");
}
row=4;
col=1;
while(row>=1)
{
while(col<=row)
{
printf("*");
col++;
}
row--;
col=1;
printf("\n");
}
}
Program No. 14
*
**
***
****
*****
#include <stdio.h>
main()
{
int row,col,space=4,i=1;
row=col=1;
while(row<=5)
{
while(i<= space)
{
printf(" ");
i++;
}
while(col<=row)
{
printf("*");
col++;
}
row++;
col=1;
space--;
i=1;
printf("\n");
}
}
Program No. 15
*****
****
***
**
*
#include <stdio.h>
int main()
{
int row,col,space=0,i=1;
row=5;
col=1;
while(row>= 1)
{
while(i<= space)
{
printf(" ");
i++;
}
while(col<=row)
{
printf("*");
col++;
}
row--;
col=1;
space++;
i=1;
printf("\n");
}
return 0;
}
Program No. 16
*
**
***
****
*****
****
***
**
*
#include <stdio.h>
main()
{
int row,col,space=4,i=1;
row=col=1;
while(row<=5)
{
while(i<= space)
{
printf(" ");
i++;
}
while(col<=row)
{
printf("*");
col++;
}
row++;
col=1;
space--;
i=1;
printf("\n");
}
/*second half part*/
space=1;
i=1;
row=4;
col=1;
while(row>= 1)
{
while(i<= space)
{
printf(" ");
i++;
}
while(col<=row)
{
printf("*");
col++;
}
row--;
col=1;
space++;
i=1;
printf("\n");
}
}
Program No. 17
* *
** **
*** ***
**** ****
**********
#include <stdio.h>
int main()
{
int row,col,space=8,i=1;
row=col=1;
while(row<=5)
{
while(col<=row)
{
printf("*");
col++;
}
while(i<=space)
{
printf(" ");
i++;
}
col=1;
while(col<=row)
{
printf("*");
col++;
}
row++;
col=1;
space-=2;
i=1;
printf("\n");
}
return 0;
}
Program No. 18
**********
**** ****
*** ***
** **
* *
#include <stdio.h>
int main()
{
int row,col,space=0,i=1;
row=5;
col=1;
while(row>=1)
{
while(col<=row)
{
printf("*");
col++;
}
while(i<=space)
{
printf(" ");
i++;
}
col=1;
while(col<=row)
{
printf("*");
col++;
}
row--;
col=1;
space+=2;
i=1;
printf("\n");
}
return 0;
}
Program No. 19
**********
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
**********
#include <stdio.h>
int main()
{
int row,col,space=0,i=1;
row=5;
col=1;
while(row>=1)
{
while(col<=row)
{
printf("*");
col++;
}
while(i<=space)
{
printf(" ");
i++;
}
col=1;
while(col<=row)
{
printf("*");
col++;
}
row--;
col=1;
space+=2;
i=1;
printf("\n");
}
/*second part*/
space=6,i=1;
row=2;
col=1;
while(row<=5)
{
while(col<=row)
{
printf("*");
col++;
}
while(i<=space)
{
printf(" ");
i++;
}
col=1;
while(col<=row)
{
printf("*");
col++;
}
row++;
col=1;
space-=2;
i=1;
printf("\n");
}
return 0;
}
Program No. 20
*
***
*****
*******
*********
#include <stdio.h>
int main()
{
int n,row,col,space=4,i=1;
row=1;
col=1;
n=1;
while(row<=5)
{
while(i<=space)
{
printf(" ");
i++;
}
while(col<=n)
{
printf("*");
col++;
}
row++;
col=1;
space--;
i=1;
n=n+2;
printf("\n");
}
return 0;
}
Program No. 21
*********
*******
*****
***
*
#include <stdio.h>
int main()
{
int n,row,col,space=0,i=1;
row=5;
col=1;
n=9;
while(row>=1)
{
while(i<=space)
{
printf(" ");
i++;
}
while(col<=n)
{
printf("*");
col++;
}
row--;
col=1;
space++;
i=1;
n=n-2;
printf("\n");
}
return 0;
}
combine above two program
Comments
Post a Comment