Ads

LightBlog

Latest

Saturday, April 17, 2021

printing pattern in c

 

                        PRINTING PATTERN IN C 



1) using a decrement operator(--)


#include<stdio.h>

#include<conio.h>

void main()

{

int i,j;
clrscr();
for(i=5;i>=1;i--)
 {
   for(j=5;j>=i;j--)
     {
      printf("*");
     }
     printf("\n");
 }
getch();
}

output:

*
**
***
****
*****



2) using a decrement operator(--)

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
 for(i=5;i>=1;i--)
 {
  for(j=5;j>=i;j--)
    {
     printf("%d",i);
    }
    printf("\n");
 }
 getch();
}



output:



5

44

333
2222
11111


3) using a decrement operator(--)

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
 for(i=5;i>=1;i--)
 {
  for(j=5;j>=i;j--)
    {
     printf("%d",j);
    }
    printf("\n");
 }
 getch();
}



output:



5

54

543
5432
54321

4) using a increment operator(++) and decrement operator(--)




#include<stdio.h>
#include<conio.h>
void main()
{
  int i,j;
  clrscr();
  for(i=1;i<=5;i++)
   {
    for(j=i;j>=1;j--)
     {
      printf("*");
     }
    printf("\n");
   }
     getch();
}



output:

*
**
***
****
*****

5) using a increment operator(++) and decrement operator(--)



#include<stdio.h>
#include<conio.h>
void main()
{
  int i,j;
  clrscr();
  for(i=1;i<=5;i++)
   {
    for(j=i;j>=1;j--)
     {
      printf("%d",i);
     }
    printf("\n");
   }
     getch();
}



output:

1
22
333
4444
55555


6) using a increment operator(++) and decrement operator(--)



#include<stdio.h>
#include<conio.h>
void main()
{
  int i,j;
  clrscr();
  for(i=1;i<=5;i++)
   {
    for(j=i;j>=1;j--)
     {
      printf("%d",j);
     }
    printf("\n");
   }
     getch();
}



output:

1
21
321
4321
54321


7) using a increment operator(++)


#include<stdio.h>
#include<conio.h>
void main()
 {
  int i,j;
  clrscr();
  for(i=1;i<=5;i++)
  {
  for(j=i;j<=5;j++)
  {
  printf("*");
  }
  printf("\n");

  }
  getch();
 }

output:

*****
****
***
**
*
------>>>>>>>/////////////////////////////////<<<<<----------


#include<stdio.h>
#include<conio.h>
void main()
 {
  int i,j;
  clrscr();
  for(i=1;i<=5;i++)
  {
  for(j=i;j<=5;j++)
  {
  printf("%d",i);
  }
  printf("\n");

  }
  getch();
 }

output:

11111
2222
333
44
5

------>>>>>>>/////////////////////////////////<<<<<----------


#include<stdio.h>
#include<conio.h>
void main()
 {
  int i,j;
  clrscr();
  for(i=1;i<=5;i++)
  {
  for(j=i;j<=5;j++)
  {
  printf("%d",j);
  }
  printf("\n");

  }
  getch();
 }

output:
12345
2345
345
45
5


------>>>>>>>/////////////////////////////////<<<<<----------


#include<stdio.h>
#include<conio.h>
void main()
 {
  int i,j;
  clrscr();
  for(i=5;i>=1;--)
  {
  for(j=i;j<=5;j++)
  {
  printf("%d",j);
  }
  printf("\n");

  }
  getch();
 }

output:

5
45
345
2345
12345


8) using a decrement operator(--)




#include<stdio.h>
#include<conio.h>
void main()
 {
  int i,j;
  
  for(i=5;i>=1;i--)
  {
  for(j=i;j>=1;j--)
  {
  printf("*");
  }
  printf("\n");

  }
  getch();
 }

output:

*****
****
***
**
*



using a decrement operator(--)




#include<stdio.h>
#include<conio.h>
void main()
 {
  int i,j;
  
  for(i=5;i>=1;i--)
  {
  for(j=i;j>=1;j--)
  {
  printf("%d",i);
  }
  printf("\n");

  }
  getch();
 }

output:


55555
4444
333
22
1




using a decrement operator(--)




#include<stdio.h>
#include<conio.h>
void main()
 {
  int i,j;
  
  for(i=5;i>=1;i--)
  {
  for(j=i;j>=1;j--)
  {
  printf("%d",j);
  }
  printf("\n");

  }
  getch();
 }

output:


54321
4321
321
21
1





SWITCH CASE In C

     #include<stdio.h>
     #include<conio.h>
     void main ()
     {
      int week;
      clrscr();
       printf("enter the value 1-7 ");
      scanf("%d",&week);
      switch(week)
       {
case 1: printf("monday");break;
case 2: printf("tudesday");break;
case 3: printf("wednesday");break;
case 4: printf("thursday");break;
case 5: printf("friday");break;
case 6: printf("saturday");break;
case 7: printf("sunday");break;
default: printf("invalid enter");
       }
       getch();
     }

No comments:

Post a Comment