Monday, August 6, 2012

C Programming Question Part 3

Pattern Print with Unique and Extreme Logic
 Pattern  1. ***
**
*
**
***
 Code: #include <stdio.h>
main()
{


int i,x,j;
for (i=2; i>=-2;i--)
{

x = 1 + 2*abs(i);
for (j=1;j<=x;j++) printf("*");
printf("\n");

}
}
 Pattern 2. RAJVEER
A        E     
J        E
V        V
E        J
E        A
REEVJAR
 Code:  #include<conio.h>
#include<string.h>
void main()
{
     char str[20];
      int i,j,k,len;
      printf("Enter the String: ");
      gets(str);
      len=strlen(str);
      puts(str);
      printf("");
      for(i=1;i<len-1;i++)
      {
            printf("%c",str[i]);
            for(j=0;j<len-2;j++)
                  printf(" ");
            printf("%c\n",str[len-i-1]);
      }
      strrev(str);
      puts(str);
}
Pattern 3. *
 **
   ***
 **
*
Code: #include <stdio.h>
main()
{


int i,x,j;
for (i=2; i>=-2;i--)
{

x = 1 + abs(i);
for (j=1;j<=x;j++) printf(" ");
for (j=1;j<=x;j++) printf("*");
printf("\n");

}
}
Pattern 4. 1
01
101
0101
Code: #include<stdio.h>
#include<conio.h>

void main()
{
  int i,j;
  int count = 1;
  clrscr();
  for(i=1;i<=4;i++)
  {
        for(j=1;j<=i;j++)
        {
            printf("%d",(i+j+1)%2);               
        }
    printf("\n");   
  }
  getch();
}