About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Saturday, December 10, 2011

Pattern Printing 7



#include

void main()
{
      int n, c, d, num = 1, space;
      clrscr();
      printf("Enter the number of rows::");
      scanf("%d",&n);

      space = n - 1;

      for ( d = 1 ; d <= n ; d++ )
      {
          num = d;

          for ( c = 1 ; c <= space ; c++ )
              printf(" ");

          space--;

          for ( c = 1 ; c <= d ; c++ )
          {
              printf("%d", num);
              num++;
          }
          num--;
          num--;
          for ( c = 1 ; c < d ; c++)
          {
              printf("%d", num);
              num--;
          }
          printf("\n");

      }
      getch();

}


-----------------------------------
output:-
Enter the number of rows::6
     1
    232
   34543
  4567654
 567898765
67891011109876

















Pattern Printing 6



#include

main()
{
      int n, c, k, x = 1;
      clrscr();
      printf("Enter number of rows::");

      scanf("%d", &n);

      for ( c = 1 ; c <= n ; c++ )
      {
          for ( k = 1 ; k <= c ; k++ )
          {
              printf("%d", x);
              x++;
          }

          x--;

          for ( k = 1 ; k <= c - 1 ; k++ )
          {
              x--;
              printf("%d", x);
          }

          printf("\n");
          x = 1;
      }
      getch();
      return 0;
}

--------------------------------
output:-
Enter number of rows::6
1
121
12321
1234321
123454321
12345654321

















Pattern Printing 5



#include
#include

main()
{
      char string[100];
      int c, k, length;
      clrscr();

      printf("Enter a string\n");
      gets(string);

      length = strlen(string);

      for ( c = 0 ; c < length ; c++ )
      {
          for( k = 0 ; k <= c ; k++ )
          {
               printf("%c", string[k]);
          }
          printf("\n");
      }
      getch();
      return 0;
}


-----------------------------
output:-

Enter a string
amit singh
a
am
ami
amit
amit
amit s
amit si
amit sin
amit sing
amit singh












Pattern Printing 4



#include

main()
{
      int n, c, k, num = 1;
      clrscr();
      printf("Enter the number of rows:");
      scanf("%d", &n);

      for ( c = 1 ; c <= n ; c++ )
      {
          for ( k = 1 ; k <= c ; k++ )
          {
              printf("%d", num);

              if ( num == 0 )
                 num = 1;
              else
                 num = 0;
          }
          printf("\n");
      }
      getch();
      return 0;
}

-------------------------------
output:-
Enter the number of rows:5
1
01
010
1010
10101


















Pattern Printing 3



#include

main()
{
      char ch = 'A';
      int n, c, k, space = 0;
      clrscr();
      printf("Enter Number of Rows..");

      scanf("%d", &n);

      for ( k = n ; k >= 1 ; k-- )
      {
          for ( c = 1 ; c <= space ; c++)
              printf(" ");

          space++;

          for ( c = 1 ; c <= k ; c++ )
          {
             printf("%c ", ch);
             ch++;
          }

          printf("\n");
          ch = 'A';
      }
      getch();

      return 0;
}

--------------------------------
Output:-
Enter Number of Rows..6
A B C D E F
 A B C D E
  A B C D
   A B C
    A B
     A

















Pattern Printing 2


#include
#include

main()
{
    int n, c, k;

    printf("Enter number of rows\n");
    scanf("%d",&n);

    for ( c = 1 ; c <= n ; c++ )
    {
        for( k = 1 ; k <= c ; k++ )
            printf("*");

        printf("\n");
    }
    getch();
    return 0;
}

----------------------

output:-

Enter number of rows
7
*
**
***
****
*****
******
*******


Pattern Printing 1


#include
#include

void main()
{
int row, c, n, temp;

printf("Enter the number of rows in pyramid of stars you wish to see ");
scanf("%d",&n);

temp = n;

for ( row = 1 ; row <= n ; row++ )
{
for ( c = 1 ; c < temp ; c++ )
{
printf(" ");
}

temp--;

for ( c = 1 ; c <= 2*row - 1 ; c++ )
{
printf("*");
}
printf("\n");
}

getch();
}
-------------

Output:-

Enter the number of rows in pyramid of stars you wish to see 6
     *
    ***
   *****
  *******
 *********
***********