Escolar Documentos
Profissional Documentos
Cultura Documentos
// Spacing factor
");
}
for (j = 1; j <= i; j++) {
printf("%2c", star);
}
printf("\n");
--num;
}
return 0;
}
2.Print a pattern
*
*
* * *
* * *
* * * * *
* * * * *
* * * * * * * * * * *
This pattern is also simple just joining two triangle in a little different way.Here odd number
");
}
printf("\n");
}
3.Print a pattern
*
***
*****
*******
*****
***
*
*
***
*****
*******
*****
***
*
*/
#include<stdio.h>
int main()
{
int i,j,l,n,k=0;
printf("Enter the rows");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(l=n;l>i;l--)
{
printf(" ");
}
for(j=1;j<=i+k;j++)
{
printf("*");
}
k++;
printf("\n");
}
int k1=n-2;
for(i=n-1;i>=1;i--)
{
for(l=i;l<=n-1;l++)
{
printf(" ");
}
for(j=i+k1;j>=1;j--)
{
printf("*");
}
k1--;
printf("\n");
}return 0;
}
#include<cstdio>
int main()
{
int i,j,k,h,m,n;
printf("Please enter the rows of fish\n");
scanf("%d",&n);
//PRINTING THE UPWARD PART
for(i=n;i>=1;i--)
{
for(j=i;j>1;j--)
{
printf(" ");
}
for(k=n;k>=i;k--)
{
if(k==i) printf("*");
else printf("* ");
}
for(h=i;h>1;h--)
{
printf(" ");
}
for(m=n;m>=i;m--)
{
printf("*");
}
printf("\n");
}
//PRINTING THE DOWNARD PART
for(i=1;i<=n-1;i++)
{
for(j=1;j<i;j++)
{
printf(" ");
}
for(k=n-1;k>=i;k--)
{
printf(" *");
}
for(h=1;h<=i;h++)
{
printf(" ");
}
for(m=i;m<=n-1;m++)
{
printf("*");
}
printf("\n");
}return 0;
}
5.Print a pattern
*
**
***
****
*****
****
***
**
*
#include<stdio.h>
int main()
{
int i,j,n;
printf("Please enter the rows for the right andled triangle \n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
for(i=n-1;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
6.Print a pattern
*
**
***
****
*****
****
***
**
*
#include<stdio.h>
int main()
{
int i,j,k,n;
printf("Please enter the rows for the right andled triangle \n");
scanf("%d",&n);
for(i=n;i>=1;i--)
{
for(k=1;k<i;k++)
{
printf(" ");
}
for(j=n;j>=i;j--)
{
printf("*");
}
printf("\n");
}
for(i=1;i<=n-1;i++)
{
for(j=1;j<=i;j++)
{
printf(" ");
}
for(k=n-1;k>=i;k--)
{
printf("*");
}
printf("\n");
}
return 0;
}
7.Print a pattern
*****
****
***
**
*
**
***
****
*****
#include<stdio.h>
int main()
{
int i,j,k,n;
printf("Please enter the rows for the right andled triangle \n");
scanf("%d",&n);
for(i=n;i>=1;i--)
{
for(k=n;k>i;k--)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
for(i=2;i<=n;i++)
{
for(k=i;k<n;k++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
8.Print a pattern
*****
****
***
**
*
**
***
****
*****
#include<stdio.h>
int main()
{
int i,j,n;
printf("Please enter the rows for the right andled triangle \n");
scanf("%d",&n);
for(i=n;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
for(i=2;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
9.Print a pattern
**********
**** ****
*** ***
** **
*
*
** **
*** ***
**** ****
**********
#include<stdio.h>/*calling the header files*/
int main()
{
int i,j,k,n; /*intializing the variables which are needed*/
printf("Please enter the rows for the right andled triangle \n");
scanf("%d",&n);
/*Loop for the uppart part of the pattern*/
for(i=n;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("*");
}
for(k=n;k>i;k--)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
10.Print a pattern
ABCDEEDCBA
ABCD DCBA
ABC
CBA
AB
BA
A
A
AB
BA
ABC
CBA
ABCD DCBA
ABCDEEDCBA
#include<stdio.h>/*calling the header files*/
int main()
{
int i,j,k,n,c,c1=0; /*intializing the variables which are needed*/
printf("Please enter the rows for the right andled triangle \n");
scanf("%d",&n);
/*Loop for the uppart part of the pattern*/
for(i=n;i>=1;i--)
{
c=64;
for(j=1;j<=i;j++)
{
printf("%c",c+j);
}
for(k=n;k>i;k--)
{
printf(" ");
}
c=65+n-c1;
for(j=1;j<=i;j++)
{
printf("%c",c-j);
}
c1++;
printf("\n");
}
/*loop for lower part */
c1=2;
for(i=2;i<=n;i++)
{
c=64;
for(j=1;j<=i;j++)
{
printf("%c",c+j);
}
for(k=i;k<n;k++)
{
printf(" ");
}
c=65+c1;
for(j=1;j<=i;j++)
{
printf("%c",c-j);
}
c1++;
printf("\n");
}
return 0;
}