Showing posts with label Pattern using C. Show all posts
Showing posts with label Pattern using C. Show all posts

Tuesday, December 4, 2012

C Language Program On Pattern




12341
21432
34123
43214



#include< stdio.h>
void main()
{
 int i,j,x;
 clrscr();
   for(i=0;i< 4;i++)
  {
   x=i+1;
  for(j=0;j< 5;j++)
 {
printf("%d",x);
if(i%2==0)
x++;
else
x--;
if(i%2==0 && x>4)
x=1;
else if(i%2!=0 && x<1 span="span">
x=4;
}
printf("\n");
}
getch();
}

Pattern Program Using C Language




The following pattern is displayed using C programming language. 



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

Pattern On Characters Using C Language





Here is a pattern given below and the pattern will be displayed using C Language.



ABCDE
BCDE
CDE
DE
E
f
fg
fgh
fghi
fghij




#include<stdio.h>
void main()
{
 int i,j,n=5;
 char ch;
 clrscr();
     for(i=0;i< 10;i++)
      {
            if(i< 5)
            {
                ch='A';
            ch=ch+i;
    }
    else
    ch='f';

               for(j=0;j< n;j++)
               {
                   printf("%c",ch);
            ch=ch+1;
                        }
                  if(i>=5)
                  n++;
                  else if(i< 4)
                  n--;
               printf("\n");

    }
getch();
}




Thursday, May 31, 2012

Print the pattern using C programs


Few programs on pattern using C language are posted here.
Pattern number 1:
1
1 2 3
1 2 3 4 5
#include < stdio.h>
void main()
{
 int i,j,x;
 clrscr();
 for(i=0;i<3;i++)
 {
 x=1;
  for(j=0;j< i*2+1;j++)
  {
  printf("%d",x++);
  }
  printf("\n");
  }
  getch();
  }


Pattern number 2:
1234
123
12
1

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

Pattern number 3:

Another pattern as follows, here ‘*’ indicates blank space.
****1
***12
**123
*1234
12345

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

Pattern number 4:

Next pattern is like:
5
54
543
5432
54321

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

Pattern number 5:

Pattern printing the numbers 1 2 2 3 3 4 4 5 5 as inverted ‘V’, like:
#include < stdio.h>
void main()
{
 int i,j,k,x=1,y=1;
 clrscr();
 for(i=0;i<5;i++)
 {
   for(k=i;k<5;k++)
   printf(" ");
   for(j=0;j< y;j++)
  {
  if(j==0||j==y-1)
  printf("%d",x);
  else
  printf(" ");
  }
  y=y+2;
  x++;
  printf("\n");
  }
  getch();
  }

Subscribe via email

Enter your email address:

Delivered by FeedBurner