C program for pattern star,pyramid,numbers, C/C++ Programming

Assignment Help:

 

1 PETTERN1 (Pettern1.c)

 

main()

{

          int i,j,k=1,a;

          clrscr();

          for(i=1;i<=5;i++)

          {

                   if(i>=3)

                             printf("* ");

                   for(j=1;j<=k;j++)

                   {

                             if(i<=2)

                                      printf("* ");

                             else

                                      printf("%d ",j);

                   }

                   k++;

                             if(i==2)

                                      k=1;

                             if(i>=3)

                                      printf("* ");

                   printf("\n");

          }

          getch();

}

 

OUTPUT :

* *

*  *

* 1 *

* 1 2 *

* 1 2 3 *

 

2 PETTERN2 (Pettern2.c)

 

main()

{

          int i,j,a,k=1,r=1,c=1,p=3;

          clrscr();

          for(i=5;i>=1;i--)

          {

                   for(j=1;j<=i;j++)

                   {

                             gotoxy(c,r);

                             printf("%d   ",k++);

                             c=c+4;

                   }

                             c=p;

                             p+=2;

                             r++;

                             printf("\n");

          }

          getch();

}

OUTPUT :

 

1   2   3   4   5

6   7   8   9

10 11 12

13 14

15

 

3 PETTERN3 (Pettern3.c)

void main()

{

          int i,j,k=0,max;

          clrscr();

          printf("ENTER THE VALUE: ");

          scanf("%d",&max);

          for(i=max;i>=1;i--)

          {

                   for(j=1;j<=i;j++)

                     {

                             k++;

                             printf(" *");

                     }

                   printf("\n");

          }

          getch();

}

OUTPUT :

 

ENTER THE VALUE : 5

 

* * * * *

* * * *

* * *

* *

*

 

 

4 PETTERN4 (Pettern4.c)

 

void main()

{

          int i,j,n;

          clrscr();

          printf("ENTER THE NO. ");

          scanf("%d",&n);

          for(i=1;i

          {

                   for(j=1;j

                   {

                             if(i==n/2 || j==(n-1))

                                      printf("* ");

                             else

                                      printf(" ");

                   }

          printf("\n");

}

          getch();

}

 

OUTPUT :

 

ENTER THE NO : 8

 

          *

          *

          *

*  *  *  *  *  *  *

          *

          *

          *

 

 

5 PETTERN5 (Pettern5.c)

 

void main()

{

          int i,j;

          char k;

          clrscr();

          printf("ENTER ANY SYMBOL AS U LIKE: ");

 

          scanf("%c",&k);

          for(i=1;i<=5;i++)

          {

                   if(i==3)

                   {

                             for(j=1;j<=5;j++)

                                      printf("  %c",k);

                   }

                    else

                             printf("\t%c",k);

                   printf("\n");

          }

          getch();

}

OUTPUT :

 

ENTER ANY SYMBOL AS U LIKE : 8

 

8

8

8

8  8  8  8  8  8  8

8

8

8

 

6 PETTERN6 (Pettern6.c)

 

void main()

{

          int i,j,max,a=1;

          clrscr();

          printf("ENTER THE NO: ");

 

          scanf("%d",&max);

          for(i=max;i>=1;i--)

          {

                   for(j=i;j>=1;j--)

                   {

                             if(a<10)

                             {

                                      printf(" 0%d ",a);

                                      a++;

                             }

                             else

                                      printf(" %d ",a++);

                   }

                   printf("\n");

          }

          getch();

}

 

OUTPUT :

 

ENTER THE NO: 5

 

01

02 03

04 05 06

07 08 09 10

11 12 13 14 15

 

7 PETTERN7 (Pettern7.c)

 

void main()

{

          int i,j,max,a=1;

          clrscr();

          printf("ENTER THE NO: ");

          flushall();

          scanf("%d",&max);

          for(i=max;i>=1;i--)

          {

                   for(j=i;j>=1;j--)

                   {

                             if(a<10)

                             {

                                      printf(" 0%d ",a);

                                      a++;

                             }

                             else

                                      printf(" %d ",a++);

                   }

                   printf("\n");

          }

          getch();

}

OUTPUT :

 

ENTER THE NO: 5

 

01 02  03  04  05

06 07  08  09 

10 11 12

13 14

15

 

8 PETTERN8 (Pettern8.c)

 

void main()

{

          int i,j,max,a=1;

          clrscr();

          printf("ENTER THE NO: ");

          scanf("%d",&max);

          for(i=1;i<=max;i++)

          {

                   for(j=1;j<=i;j++)

                   {

                             if(a==0)

                             {

                                      printf(" 0 ");

                                      a++;

                             }

                             else if(a==1)

                             {

                                      printf(" 1 ");

                                      a--;

                             }

                   }

                   a=1;

                   printf("\n");

          }

          getch();

}

OUTPUT :

 

ENTER THE NO: 5

 

1  0

1  0  1

1  0  1  0

1  0  1  0  1

 

 

9 PETTERN9 (Pettern9.c)

 

void main()

{

          int i,j,max,a=1,b;

          clrscr();

          printf("ENTER THE NO: ");

          flushall();

          scanf("%d",&max);

          for(i=1;i<=max;i++)

          {

                   b=max-1;

                   for(j=1;j<=i;j++)

                   {

                             for(;b>=i-1;b--)

                                      printf("  ");

                             if(a<10)

                                      printf(" 0%d ",a++);

                             else

                                      printf(" %d ",a++);

                   }

                   printf("\n");

          }

          getch();

}

 

OUTPUT :

 

ENTER THE NO: 5

 

01

02 03

04 05 06

07 08 09 10

11 12 13 14 15

 

10 PETTERN10 (Pettern10.c)

 

void main()

{

          int i,j,max;

          clrscr();

          printf("ENTER THE NO: ");

          scanf("%d",&max);

          for(i=1;i<=max;i++)

          {

                   for(j=1;j<=max;j++)

                   {

                             if(i==1)

                                      printf("* ");

                             else if(i==max)

                                      printf("* ");

                             else if(j==1)

 

                                      printf("* ");

                             else if(j==max)

                                      printf("* ");

                             else

                                      printf("  ");

                   }

                   printf("\n");

          }

          getch();

}

OUTPUT :

 

ENTER THE NO: 5

 

*  *  *  *  *

*            *

*            *

*            *

*  *  *  *  *

 


11 PETTERN11 (Pettern11.c)

 

void main()

{

          int i,j,k,s,s1;

          clrscr();

          s=1;

          s1=4;

          for(i=1;i<=3;i++)

          {

                   for(j=1;j<=s;j++)

                             printf(" ");

                   printf("*");

                   if(i!=3)

                   {

                             for(k=1;k<=s1;k++)

                                      printf(" ");

                             printf("*");

                   }

                   printf("\n");

                   s=s++;

                   s1=s1-2;

          }

          s=2;

          s1=2;

          for(i=1;i<=2;i++)

          {

                   for(j=1;j<=s;j++)

                             printf(" ");

                   printf("*");

                             for(k=1;k<=s1;k++)

                                      printf(" ");

                   printf("*");

                   printf("\n");

                   s--;

                   s1=s1+2;

          }

          getch();

}

 

OUTPUT :

 

Enter The No: 5

 

*          *

*    *

*

*     *

*           *

 

 


12 PETTERN12 (Pettern12.c)

 

void main()

{

          int i,j,k,d,a;

          clrscr();

          k=1;

          for(i=1;i<=5;i++)

          {

                   printf("0%d ",k++);

          }

                   printf("\n");

                   for(j=1;j<=3;j++)

                   {

                             for(d=1;d<=2;d++)

                             {

                                      if(k<10)

                                      {

                                                printf("0%d          ",k++);

                                      }

                                      else

                                      {

                                                printf("%d          ",k++);

                                      }

                             }

                             printf("\n");

                   }

                             for(a=12;a<=16;a++)

                             {

                                      printf("%d ",k++);

                             }

 

          getch();

}

 

OUTPUT :

 

01 02 03 04 05

06                07  

08                09 

10                11 

12 13 14 15 16

 

13 PETTERN13 (Pettern13.c)

 

void main()

{

          int min,mino,a,max,t,p,r,k;

          char option;

          clrscr();

          printf("ENTER THE LIMIT OF TRAINGLE= ");

          scanf("%d",&max);

          printf("SERIES IN FORWARD OR IN REVERSE 'f' or 'r'= ");

          scanf("%c",&option);

          while(option!='f' && option!='r')

          {

printf("YOU HAVE ENTERED WRONG DATA ENTERED RIGHT DATA       'f' or 'r'= ");

          scanf("%c",&option);

          }

          /* for forward loop*/

          if(option=='f')

          {

                   a=1;

          }

          /* for reverse loop*/

          else

          {

                   p=1;

                   r=max;

                   k=0;

                   while(p<=max)

                   {

                             k=k+r;

                             r=r-1;

                             p=p+1;

                   }

                   a=k;

          }

          /* for triangle */

          t=max;

          for (min=1;min<=max;min=min+1)

          {

                   for(mino=1;mino<=t;)

                   {

                             if(option=='f')

                             {

                                      if(a<=9)

                                                printf("0%d  ",a);

                                      else

                                                printf("%d  ",a);

                                      a=a+1;

                             }

                             else

                             {

                                      if(a<=9)

                                                printf("0%d  ",a);

                                      else

                                                printf("%d  ",a);

                                      a=a-1;

                             }

                             mino=mino+1;

                   }

                   t=t-1;

                   printf("\n");

          }

          getch();

}

 

OUTPUT :

 

ENTER THE LIMIT OF TRAINGLE: 5

SERIES IN FORWARD OR REVERSE 'f' or 'r' : f

 

01 02 03 04 05

06 07 08 09

10 11 12

13 14

15

 

 

14 PETTERN14 (Pettern14.c)

 

void main()

{

          int min,mino,t,a,max,p;

          char option;

          clrscr();

          t=1;

          a=1;

          printf("ENTER THE LIMIT OF TRIANGLE= ");

          flushall();

          scanf("%d",&max);

printf("SERIES TO BE PRINTER IN FORWARD OR REVERSE 'f' or

     'r'= ");

          scanf("%c",&option);

 

          printf("*\n");

          printf("*  *\n");

 

          for(min=2;min

          {

                   if(option=='r')

                   {

                             p=max-2;

                             a=p;

                   }

                   else

                             a=t;

                   printf("*");

                   for(mino=2;mino<=min;mino++)

                   {

                             if(option=='f')

                             {

                                      if(a<=9)

                                      {

                                                printf(" 0%d ",a);

                                                a=a+1;

                                      }

                                      else

                                      {

                                                printf(" %d ",a);

                                                a=a+1;

                                      }

                             }

 

                             else

                             {

                                       if(a<=9)

                                       {

                                                 printf(" 0%d ",a);

                                                a=a-1;

                                      }

                                      else

                                      {

                                                printf(" %d ",a);

                                                a=a-1;

                                       }

                             }

                             if(mino==min)

                             {

                                      printf("  *");

                                       mino=mino+1;

                             }

                   }

                   printf("\n");

          }

          getch();

}

OUTPUT :

 

ENTER THE MAX LIMIT OF TRIANGLE : 8

SERIES TO BE PRINT IN FORWARD OR REVERSE "f" OR "r"= r

 

*

* *

* 06 *

* 06 05 *

* 06 05 04 *

* 06 05 04 03 *

* 06 05 04 03 02 *

* 06 05 04 03 02 01 *

 


15 PETTERN15 (Pettern15.c)

 

 

void main()

{

          int min,mino,max,a,t,p,q,r,z,s;

          char option;

          clrscr();

          printf("ENTER THE MAX LINE OF PYRAMID= ");

          flushall();

          scanf("%d",&max);

printf("SERIED TO BE PRINTED IN FORWARD OR REVERSE 'f'   or 'r'= ");

          flushall();

          scanf("%c",&option);

          if(option=='f')

          {

                   a=1;

          }

          else

          {

                   s=1;

                   r=max;

                   z=1;

                   while(s

                   {

                             r=r+(max-z);

                             z=z+1;

                             s=s+1;

                   }

                   a=r;

          }

          p=max;

          q=max;

          for(min=1;min<=max;min++)

          {

                   for(t=min;t

                   {

                             printf("  ");

                   }

                   for(mino=1;mino<=p;mino++)

                   {

                             if(option=='f')

                             {

                                       if(a<=9)

                                      {

                                                printf("0%d  ",a);

                                                a=a+1;

                                      }

 

                                      else

                                      {

                                                printf("%d  ",a);

                                                a=a+1;

                                      }

                             }

                             else

                             {

                                      if(a<=9)

                                      {

                                                printf("0%d  ",a);

                                                a=a-1;

                                      }

                                      else

                                      {

                                                printf("%d  ",a);

                                                a=a-1;

                                      }

                             }

                   }

                   p=p-1;

                   q=q+2;

                   printf("\n");

          }

          getch();

}

OUTPUT :

 

ENTER THE MAX LIMIT OF PYRAMID : 8

SERIES TO BE PRINTED IN FORWARD OR REVERSE ‘f’ OR ‘r’= r

 

35 35 34 33 32 31 30 29

28 27 26 25 24 23 22

21 20 19 18 17 16

15 14 13 12 11

10 09 08 07

06 05 04

03 02

01

 


16 PETTERN16 (Pettern16.c)

 

  void main()

{

          int min,mino,max,t,p,r;

          clrscr();

          printf("ENTER THE LIMIT IN ODD NO=");

          flushall();

          scanf("%d",&max);

          r=max%2;

          while(r==0)

          {

printf("YOU HAVE ENTERED WRONG DATA PLEASE ENTER RIGHT DATA: ");

                   flushall();

                   scanf("%d",&max);

                   r=max%2;

          }

          for (min=1;min<=max;min=min+1)

          {

                   if(min==(max/2)+1)

                   {

                             t=1;

                             while(t<=max)

                             {

                                      printf("* ");

                                      t=t+1;

                             }

                    }

                   else

                   {       for(p=1;p<=(max/2);p++)

                             {

                                      printf("  ");

                             }

                             printf("*");

                   }

 

                   printf("\n");

          }

 

          getch();

}

 

OUTPUT :

 

ENTER THE LIMIT IN ODD NO: 5

 

*

*

*  *  *  *  *

*

*

 

17 PETTERN17 (Pettern17.c)

 

void main()

{

          int t,p,r,min,min1,min2,max;

          clrscr();

          printf("ENTER THE LIMIT OF CROSS IN ODD= ");

          scanf("%d",&max);

          t=max%2;

          while(t==0)

          {

printf("YOU HAVE ENTERED WRONG NO PLEASE ENTER RIGHT ODD NO= ");

                   scanf("%d",&max);

                   t=max%2;

          }

          t=0;

          t=(max/2)+1;

          p=1;

          r=max-1;

          for(min=1;min<=t;min++)

          {

                   for(min1=1;min1<=p;min1++)

                             printf("  ");

                   p=p+1;

                   printf("*");

                   for(min2=1;min2<=r;min2++)

 

                             printf("  ");

                   r=r-2;

                   if(min!=(max/2)+1)

                             printf("*");

                   printf("\n");

          }

          t=0;

          t=max/2;

          p=max/2;

          r=2;

          for(min=1;min<=t;min++)

          {

                   for(min1=1;min1<=p;min1++)

                                      printf("  ");

                   p=p-1;

                   printf("*");

                   for(min2=1;min2<=r;min2++)

                             printf("  ");

                   r=r+2;

                   printf("*");

                   printf("\n");

          }

          getch();

}

OUTPUT :

 

ENTER THE LIMIT OF CROSS IN ODD NO: 5

 

*        *

*    *

*

*    *

*        *


18 PETTERN18 (Pettern18.c)

 

void main()

{

          int min,mino,row,col,c,t;

          char a;

          clrscr();

          printf("ENTER THE MAX LIMIT OF THE ROW= ");

          scanf("%d",&row);

          printf("ENTER THE MAX LIMIT OF THE COL= ");

          scanf("%d",&col);

          printf("ENTER THE DATA TO BE PRINTED: ");

scanf("%c",&a);

          for(min=1;min<=row;min++)

          {

                   if(min==1)

                   {

                             c=1;

                             while(c<=col)

                             {

                                      printf("%c ",a);

 

                                      c=c+1;

                             }

                             printf("\n");

                   }

                   else

                   {

                             if(min==row)

                             {

                                      t=1;

                                      while(t<=col)

                                      {

                                                printf("%c ",a);

                                                t=t+1;

                                      }

                                      printf("\n");

                             }

                             else

                             {

                                      printf("%c",a);

                                      for(mino=1;mino<=((col*2)-3);mino++)

                                      {

                                                printf(" ");

                                                if(mino==((col*2)-3))

                                                {

                                                          printf("%c\n",a);

                                                }

                                      }

                             }

                   }

          }

          getch();

}

OUTPUT :

 

ENTER THE LIMIT OF ROW: 5

ENTER THE LIMIT OF COL:  5

ENTER THE DATA TO BE PRINTED: 1

1 1 1 1 1

1          1

1          1

1          1

1 1 1 1 1

 


Related Discussions:- C program for pattern star,pyramid,numbers

Program is to define a class as teacher, Program is to define a class as te...

Program is to define a class as teacher: Program is to define a class as teacher and collect information about them by using classes and object class teacher   {   pr

Is there any difficulty with the following : char*a=null; , Is there any di...

Is there any difficulty with the following : char*a=NULL; char& p = *a;? A: The result is indeterminate. You must never do this. A reference has to always refer to some object.

How to write program, how to write a program for all the types of beam reac...

how to write a program for all the types of beam reactions

Calculate the area of circle using c program, Calculate the area of circle ...

Calculate the area of circle using c program: const float Pi = 3.1415926;   inline float area(const float r) {return Pi * r * r;}   main() {    float radius;

Write function that take array as argument, Write a function that takes an ...

Write a function that takes an array as the argument and returns the second largest element. Bonus (+5): Write a function that takes an array and a number n as arguments and return

I want to convert atmel c code into arduino mppt, Normal 0 fals...

Normal 0 false false false EN-US X-NONE X-NONE

Basics, conceptual difference between big o,big thete and big omega

conceptual difference between big o,big thete and big omega

Program to create a class and store student information, Develop a Student ...

Develop a Student class that has the following header file: #ifndef STUDENT_H #define STUDENT_H #include #include #include using namespace std; class Stu

Text Editor, Add a function for saving the text stored in an array to a fil...

Add a function for saving the text stored in an array to a file. Your program must check whether or not the output file already exists, and if it does, your program must ask the us

String, A string is said to be "Beautiful"€, if it contains only non repet...

A string is said to be "Beautiful"€, if it contains only non repetitive alphabets

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd