1. Write a Program to Print the following pattern:
*
* *
* * *
* * * *
* * * * *
#include<stdio.h>
main()
{
int i, j;
for(i = 5 ; i >= 1 ; i--)
{
for(j = i ; j <= 5 ; j++)
{
printf("*");
}
printf("\n");
}
}
2. Write a Program to Print the following pattern:
* * * * *
* * * *
* * *
* *
*
#include<stdio.h>
main()
{
int i, j;
for(i = 5 ; i >= 1 ; i--)
{
for(j = i ; j >= 1 ; j--)
{
printf("*");
}
printf("\n");
}
}
3. Write a Program to Print the following pattern:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
#include<stdio.h>
main()
{
int i,j;
for(i = 1 ; i < = 5 ; i++)
{
for(j = 1 ; j <= i ; j++)
{
printf("%d",i);
}
printf("\n");
}
}
4. Write a Program to Print the following pattern:
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
#include<stdio.h>
main()
{
int i,j;
for(i = 5 ; i >= 1 ; i--)
{
for(j = i ; j >= 1 ; j--)
{
printf("%d",i);
}
printf("\n");
}
}
5. Write a Program to Print the following pattern:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
#include<stdio.h>
main()
{
int i,j;
for(i = 1 ; i < = 5 ; i++)
{
for(j = 1 ; j <= i ; j++)
{
printf("%d",j);
}
printf("\n");
}
}
6. Write a Program to Print the following pattern:
*
* *
* * *
* * * *
* * * * *
#include<stdio.h>
#include<conio.h>
main()
{
int i,j,k,c=40;
clrscr();
for(i = 1 ; i <= 5 ; i++)
{
for(j = 1 ; j <= c ; j++)
{
printf(" ");
}
for(k = 1;k <= i; k++)
{
printf(" *");
}
printf("\n");
c--;
}
getch();
}
7. Write a Program to Print the following pattern:
* * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * *
#include<stdio.h>
#include<conio.h>
main()
{
int i , j , k , l , m , c ;
clrscr();
do
{
printf(" enter greatest no of *" );
scanf("%d",&m);
c=m;
for(i = 1 ; i <= m ; i++)
{
for(j = 1 ; j <= c ; j++)
{
if(j == m)
{
continue;
}
printf("*");
}
for(k = 1 ; k < i ; k++)
{
if(k == 1)
printf(" ");
else
printf(" ");
}
for(l = c ; l >= 1 ; l--)
{
printf("*");
}
c--;
printf("\n");
}
c=c+2;
for(i = m-1 ; i >= 1 ; i--)
{
for ( j = 1 ; j <= c ; j++)
{
if(j == m)
{
continue;
}
printf("*");
}
for(k = 1 ; k<i ; k++)
{
if( k == 1)
{
printf(" ");
}
else
{
printf(" ");
}
}
for( l = c ; l >= 1 ; l--)
{
printf("*");
}
c++;
printf("\n");
}
} while(m!=0);
getch();
}
* * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * *
#include<stdio.h>
#include<conio.h>
main()
{
int i , j , k , l , m , c ;
clrscr();
do
{
printf(" enter greatest no of *" );
scanf("%d",&m);
c=m;
for(i = 1 ; i <= m ; i++)
{
for(j = 1 ; j <= c ; j++)
{
if(j == m)
{
continue;
}
printf("*");
}
for(k = 1 ; k < i ; k++)
{
if(k == 1)
printf(" ");
else
printf(" ");
}
for(l = c ; l >= 1 ; l--)
{
printf("*");
}
c--;
printf("\n");
}
c=c+2;
for(i = m-1 ; i >= 1 ; i--)
{
for ( j = 1 ; j <= c ; j++)
{
if(j == m)
{
continue;
}
printf("*");
}
for(k = 1 ; k<i ; k++)
{
if( k == 1)
{
printf(" ");
}
else
{
printf(" ");
}
}
for( l = c ; l >= 1 ; l--)
{
printf("*");
}
c++;
printf("\n");
}
} while(m!=0);
getch();
}
No comments:
Post a Comment