Sunday, January 1, 2012

Print following pattern. 1 2 3 4 8 7 6 5 9 10 11 12 in 'C'


 1 2 3 4
 8 7 6 5
 9 10 11 12

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,k=1;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=4;j++)
{
if(i%2==0)
{
printf("%4d",k--);
}
else
{
printf("%4d",k++);
}
}
if(i%2==0)
{
k++;
}
else
k--;
k+=4;
printf("\n");
}
getch();
}
/*================================================================
OUTPUT
Enter the number:3
1 2 3 4
8 7 6 5
9 10 11 12
*/

Print following pattern. A BB CCC DDDD in 'C'


A
BB
CCC
DDDD

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
char c;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
c=65;
for(i=0;i<=n;i++)
{
for(j=0;j<=i;j++)
{
printf("%c",c);


}
     c++;
printf("\n\n");
}
getch();
}
/*=====================================================================
OUTPUT
Enter the value of n:4
A
BB
CCC
DDDD



Print following pattern in 'C'


A
   A
     A
       A
     A
   A
 A

Example

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,k;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
if(i==j)
{
printf(" A ");
}
else
{
printf(" ");
}
}
printf("\n");
       }
       for(i=2;i<=n;i++)
       {
for(j=n;j>=i;j--)
{
if(i==j)
{
printf(" A ");
}
else
{
printf(" ");
}
}
printf("\n");
       }

getch();
}
/*===============================================================
OUTPUT
A
  A
    A
      A
    A
  A
A
*/

Print following pattern. * * * * * * * * * * in 'C'


   *
  * *
 * * *
* * * *
Example



#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,k;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
for(i=1;i<=n;++i)
{
for(k=1;k<=n-i;++k)
{
printf(" ");
}
for(j=1;j<=i;++j)
{
printf("* ");


}
printf("\n");
}
getch();
}
/*=====================================================================
OUTPUT
Enter the value of n:4
       *
      * *
     * * *
    * * * *
*/



Print following pattern. **** *** ** * in 'C'


****
***
**
*

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(j=i;j<n;j++)
{
printf("*");
}
printf("\n\n");
}
getch();
}
/*=====================================================================
OUTPUT
Enter the value of n:4
****
***
**
*
*/


Print following pattern. 1 01 101 0101 in 'C'


1
01
101
0101

Example

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(j=1;j<i;j++)
{
      if((i+j)%2==0)
      {
printf("0");
      }
else
{
printf("1");
}
}
printf("\n");
}
getch();
}
/*=====================================================================
OUTPUT
Enter the value of n:5

1
01
101
01010
*/

Print following pattern. 1 22 333 4444 in 'C'


1
22
333
4444

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
getch();
}
/*=====================================================================
OUTPUT
Enter the value of n:4


1
22
333
4444