Showing posts with label Pattern. Show all posts
Showing posts with label Pattern. Show all posts
This a pattern... Print this using C language.
*
**
***
****
*****
****
***
**
*

Source Code: 

  1. #include<stdio.h>
  2. int main(){
  3. int row,col,n;
  4. printf("~~~~~Thanks for visit browncodeit.blogspot.com~~~~~~~~~\n");
  5. printf("Enter the numebr: ");
  6. scanf("%d",&n);
  7. for(row=1;row<=n;row++){
  8. for(col=1;col<=row;col++){
  9. printf("*");
  10. }
  11. printf("\n");
  12. }
  13. for(row=n;row>=1;row--){
  14. for(col=1;col<row;col++){
  15. printf("*");
  16. }
  17. printf("\n");
  18. }
  19. return 0;
  20. }



Output:


C program to print pattern like this in a different way just check out with Alphabet. First with row and second with column.
A
BB
CCC
DDDD
EEEEE
ABCD
ABC
AB
A

Source Code:

  1. #include<stdio.h>

  2. int main(){
  3. int row,col,n;
  4. printf("~~~~~Thanks for visit browncodeit.blogspot.com~~~~~~~~~\n");
  5. printf("Enter the numebr: ");
  6. scanf("%d",&n);
  7. for(row=1;row<=n;row++){
  8. for(col=1;col<=row;col++){
  9. printf("%c",row+64);
  10. }
  11. printf("\n");
  12. }
  13. for(row=n;row>=1;row--){
  14. for(col=1;col<row;col++){
  15. printf("%c",col+64);
  16. }
  17. printf("\n");
  18. }
  19. return 0;
  20. }

Output:


This a pattern... 
1
12
123
1234
12345
1234
123
12
1



Source Code:

  1. #include<stdio.h>

  2. int main(){
  3. int row,col,n;
  4. printf("~~~~~Thanks for visit browncodeit.blogspot.com~~~~~~~~~\n");
  5. printf("Enter the numebr: ");
  6. scanf("%d",&n);
  7. for(row=1;row<=n;row++){
  8. for(col=1;col<=row;col++){
  9. printf("%d",col);
  10. }
  11. printf("\n");
  12. }
  13. for(row=n;row>=1;row--){
  14. for(col=1;col<row;col++){
  15. printf("%d",col);
  16. }
  17. printf("\n");
  18. }
  19. return 0;
  20. }


Output:



This is a C program to print love pattern or  Heart pattern  or Leave pattern.

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

Source Code: 

  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int i, j, n;
  5.                  //take input from user.
  6.     printf("Enter Row number : ");
  7.     scanf("%d", &n);
  8.                    //  up two side print
  9.     for(i=n/2;i<=n;i+=2)
  10.     {
  11.         for(j=1; j<n-i; j+=2)
  12.         {
  13.             printf(" ");
  14.         }

  15.         for(j=1; j<=i; j++)
  16.         {
  17.             printf("*");
  18.         }

  19.         for(j=1; j<=n-i; j++)
  20.         {
  21.             printf(" ");
  22.         }

  23.         for(j=1; j<=i; j++)
  24.         {
  25.             printf("*");
  26.         }

  27.         printf("\n");
  28.     }
  29.            // down portion print
  30.     for(i=n; i>=1; i--)
  31.     {
  32.         for(j=i; j<n; j++)
  33.         {
  34.             printf(" ");
  35.         }

  36.         for(j=1; j<=(i*2)-1; j++)
  37.         {
  38.             printf("*");
  39.         }

  40.         printf("\n");
  41.     }

  42.     return 0;
  43. }


Output: 



Problem:  Write a c program to print Pyramid Patterns.
 
        *
        * * *
        * * * * *
        * * * * * * *
         * * * * * * * * *
Source Code:
  1.  /*
  2. * C Program to print full pyramid pattern using *
  3. */
  4. #include<stdio.h>
  5. #include<conio.h>
  6. int main()
  7.  {
  8.     int row, space, rows, star=0;
  9.     printf("Enter the number of rows in pyramid\n");
  10.     scanf("%d",&rows);
  11.  
  12.     for(row = 1;row <= rows; row++)
  13. {
  14.      /* Printing spaces */
  15.         for(space = 1; space <= rows-row; space++) 
  16. {
  17.            printf("  ");
  18.         }
  19.         /* Printing stars */
  20.         while(star != (2*row - 1)) 
  21. {
  22.             printf("* ");
  23.             star++;;
  24.         }
  25.         star=0;
  26.         printf("\n");
  27.     }
  28.     getch();
  29.     return 0;
  30. }
Outputs:
         
Problems:   Write a C program to print Patterns Inverted Pyramid
        *****
      ****
    ***
   **
 *
Source Code:
  1. #include <stdio.h>

  2. int main()
  3. {
  4.     int i, j, n;

  5.     printf("Enter N: ");
  6.     scanf("%d", &n);
  7.     for (i=n;i>=1;i--)
  8.      {
  9.      
  10.         for(j=1;j<=i;j++)
  11.           {
  12.           printf("*");
  13.           }
  14.            printf("\n");
  15.      }
  16.     
  17.     
  18.      return 0;
  19.  }


Output:


This is half pyramid different design.

Source Code:


#include <stdio.h>

int main()
{
    int i, j, n;

    printf("Enter N: ");
    scanf("%d", &n);
    for (i=1;i<=n;i++)
     {
      for(j=1;j<=(n-i);j++)
      {
      printf(" ");
        }
       for(j=1;j<=i;j++)
         {
        printf("*");
         }
     printf("\n");
 }
 }


Outputs:




Write a C program  to print number pattern.   | Number increasing order  | Half Pyramid with Number.
                                                                   

Source Code :

  1. /**
  2.  * C program to print number pattern
  3.  */

  4. #include <stdio.h>

  5. int main()
  6. {
  7.     int i, j, N;

  8.     printf("Enter N: ");
  9.     scanf("%d", &N);

  10.     for(i=1; i<=N; i++)
  11.     {
  12.         // Logic to print numbers
  13.         for(j=1; j<=i; j++)
  14.         {
  15.             printf("%d", j);
  16.         }

  17.         printf("\n");
  18.     }

  19.     return 0;
  20. }

Outputs:


Enter N: 10
1
12
123
1234
12345
123456
1234567
12345678
123456789
12345678910

Output 2:



C Program  to print inverted half pyramid. 

Problem:  C program to print pattern.

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

Source Code:

  1. #include<stdio.h> 
  2. int main()
  3. int i,j,n;
  4. printf("length of ball:"); 
  5. scanf("%d",&n);
  6. /*printf("Breadth of ball");
  7. scanf("%d",&j);*/

  8. // This is upper half of pattern 
  9. for (i=1; i<=n; i++) 
  10. for (j=1; j<=(2*n); j++) 
  11. // Left part of pattern 
  12. if (i>(n-j+1)) 
  13. printf(" "); 
  14. else
  15. printf("*"); 
  16. // Right part of pattern 
  17. if ((i+n)>j) 
  18. printf(" "); 
  19. else
  20. printf("*"); 
  21. printf("\n"); 
  22. // This is lower half of pattern 
  23. for (i=1; i<=n; i++) 
  24. for (j=1; j<=(2*n); j++) 
  25. // Right Part of pattern 
  26. if (i<j) 
  27. printf(" "); 
  28. else
  29. printf("*"); 
  30. // Left Part of pattern 
  31. if (i<=((2*n)-j)) 
  32. printf(" "); 
  33. else
  34. printf("*"); 
  35. printf("\n"); 
  36. }
  37. return 0; 
Output:


length of ball:5