Ushtrime                          MSc.
Olta Petritaj
1.      Display a pattern of stars
Code:
#include<stdio.h>
#include<conio.h>
int main()
{
           int i,j,n;
            printf("enter value :" );
            scanf("%d",&n);
            for(i=1;i<=n;i++)
            {
                       for(j=1;j<=i;j++)
                       printf(" ");
                       for(j=1;j<=n-i;j++)
                       printf("*");
                       printf("\n");
            }
getch();
}
2.         Display triangle of stars
Code:
/* Program display following Pattern */
/* *
    **
    ***
    **** */
#include<stdio.h>
#include<conio.h>
int main()
{
  int i,j,row;
    printf("Enter How many Rows : ");
    scanf("%d",&row);
    for(i=1;i<=row;i++)
    {
              for(j=1;j<=i;j++)
                printf("*");
              printf("\n");
    }
    getch();
}
               Ushtrime                                    MSc. Olta Petritaj
3.         Display a right triangle of numbers
Code:
/* display following pattern
     1
    121
  12321
*/
#include<stdio.h>
#include<conio.h>
int main()
{
  int i,j,n;
  printf("Enter no of line \n");
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    /* Control space */
    for(j=1;j<=n-i;j++)
             printf(" ");
    /* Display regular number */
    for(j=1;j<=i;j++)
     printf("%d",j);
     /* Display revewrse number */
      for(j=i-1;j>=1;j--)
               printf("%d",j);
     printf("\n");
    }
    getch();
}
4.         Display two opposite triangles using for loop
Code:
/* display following pattern
    *
   ***
  *****
   ***
     *
*/
#include<stdio.h>
#include<conio.h>
int main()
{
  int i,j,n;
               Ushtrime                             MSc. Olta Petritaj
    printf("Enter no of line \n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
      for(j=1;j<=n-i;j++)
      printf(" ");
      for(j=1;j<=2*i-1;j++)
       printf("*");
      printf("\n");
    }
    for(i=n-2;i>=1;i--)
    {
      for(j=1;j<=n-i;j++)
      printf(" ");
      for(j=1;j<=2*i-1;j++)
       printf("*");
      printf("\n");
    }
    getch();
}
5.         Produce a pyramid of *s using for loop
Code:
/* display following pattern
    *
   ***
  *****
*/
#include<stdio.h>
#include<conio.h>
int main()
{
  int i,j,n;
    printf("Enter no of line \n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
      for(j=1;j<=n-i;j++)
      printf(" ");
      for(j=1;j<=2*i-1;j++)
       printf("*");
      printf("\n");
               Ushtrime                                            MSc. Olta Petritaj
    }
    getch();
}
6.         Produce a Floyd's Triangle of numbers
Code:
/* Q. program to produce the following form of Floyd's Triangle.
     1
     01
     101
     0101 */
#include<stdio.h>
#include<conio.h>
int main()
{
  int i,j,n,a,b;
  printf("Enter No of Line : ");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
  {
    if(i%2==0)
    { a=1;b=0;}
    else
    { a=0;b=1;}
     for(j=1;j<=i;j++)
              if(j%2==0)
                printf("%d",a);
              else
                printf("%d",b);
     printf("\n");
    }
    getch();
}
7.      Display Floyd's Triangle
Code:
/* Q. program to produce the following form of Floyd's Triangle.
   0
   10
   010
   1010 */
#include<stdio.h>
#include<conio.h>
           Ushtrime                       MSc. Olta Petritaj
int main()
{
  int i,j,n,a,b;
    printf("Enter No of Line : ");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
      if(i%2==0)
      { a=0;b=1;}
      else
      { a=1;b=0;}
     for(j=1;j<=i;j++)
              if(j%2==0)
                printf("%d",a);
              else
                printf("%d",b);
     printf("\n");
    }
    getch();
}
8.    Display pyramid of numbers
Code:
/* Program display following Pattern */
/* 1
   22
  333
 4 4 4 4 */
#include<stdio.h>
#include<conio.h>
int main()
{
  int i,j,row;
    printf("Enter How many Rows : ");
    scanf("%d",&row);
    for(i=1;i<=row;i++)
    {
              for(j=1;j<=row-i;j++)
              printf(" ");
              for(j=1;j<=i;j++)
                printf("%d ",i);
           Ushtrime                               MSc. Olta Petritaj
               printf("\n");
    }
    getch();
}
9.         Display pyramid of *s using for loop
Code:
/* Program display following Pattern */
/* *
   **
   ***
  * * * * */
#include<stdio.h>
#include<conio.h>
int main()
{
  int i,j,row;
    printf("Enter How many Rows : ");
    scanf("%d",&row);
    for(i=1;i<=row;i++)
    {
              for(j=1;j<=row-i;j++)
              printf(" ");
              for(j=1;j<=i;j++)
                printf("* ");
              printf("\n");
    }
    getch();
}
10.        Display a pyramid of numbers
Code:
/* Program display following Pattern */
/* 1
   23
  456
 7 8 9 10 */
#include<stdio.h>
#include<conio.h>
int main()
{
  int i,j,row,t=1;
          Ushtrime                        MSc. Olta Petritaj
    printf("Enter How many Rows : ");
    scanf("%d",&row);
    for(i=1;i<=row;i++)
    {
              for(j=1;j<=row-i;j++)
              printf(" ");
              for(j=1;j<=i;j++)
                printf("%2d",t++);
              printf("\n");
    }
    getch();
}
11.        Display pattern of numbers
Code:
/* Program display following Pattern */
/* 1
   23
   456
   7 8 9 10 */
#include<stdio.h>
#include<conio.h>
int main()
{
  int i,j,row,t=1;
    printf("Enter How many Rows : ");
    scanf("%d",&row);
    for(i=1;i<=row;i++)
    {
              for(j=1;j<=i;j++)
                printf("%3d",t++);
              printf("\n");
    }
    getch();
}
12.     Display a pattern of numbers
Code:
/* Program display following Pattern */
/* 1
   22
   333
          Ushtrime                                   MSc. Olta Petritaj
   4444 */
#include<stdio.h>
#include<conio.h>
Int main()
{
  int i,j,row;
    printf("Enter How many Rows : ");
    scanf("%d",&row);
    for(i=1;i<=row;i++)
    {
              for(j=1;j<=i;j++)
                printf("%2d",i);
              printf("\n");
    }
    getch();
}
13.        Display a particular pattern of numbers
Code:
/* Program display following Pattern */
/* 1
    12
    123
    1234 */
#include<stdio.h>
#include<conio.h>
int main()
{
  int i,j,row;
  printf("Enter How many Rows : ");
  scanf("%d",&row);
  for(i=1;i<=row;i++)
  {
             for(j=1;j<=i;j++)
               printf("%2d",j);
             printf("\n");
  }
  getch();
}
14.   Display a particular pattern of *s
Code:
/* Program display following Pattern */
        Ushtrime                      MSc. Olta Petritaj
/* *
    **
    ***
    **** */
#include<stdio.h>
#include<conio.h>
int main()
{
  int i,j,row;
  printf("Enter How many Rows : ");
  scanf("%d",&row);
  for(i=1;i<=row;i++)
  {
            for(j=1;j<=i;j++)
               printf("*");
            printf("\n");
  }
  getch();
}