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

C Program To Print Patterns Of Numbers And Stars

How to write a C Program To Print Patterns Of Numbers And Stars in C Programming Language ?

Solution:

C Program To Print Patterns Of Numbers And Stars

#include<stdio.h>

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");
   }

   return 0;
}


Out PUT:-

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

C Program To Print Diamond Pattern

How to write a C Program To Print Diamond Pattern in C Programming Language ?


Solution:

#include<stdio.h>

main()
{
    int n, c, k, space = 1;

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

    space = n - 1;

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

        space--;

        for ( c = 1 ; c <= 2*k-1 ; c++)
            printf("*");

        printf("\n");

    }

    space = 1;

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

        space++;

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

        printf("\n");
    }      

    return 0;
}


output

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

Program to display the following pattern in C

How to write a c Program to display the following pattern in C programming language ?



Solution:
/* Program to display the following pattern:
1
12
123
1234
12345
*/
#include<stdio.h>
#include<conio.h>

void main()
{
int i, j;

clrscr();

for(i = 0; i<4; i++) {
for(j = 0; j <= i; j++)
printf("%d", j + 1);
printf("\n");
}

getch();
}

Display the Following Pattern * ** *** **** ***** C Program

How to write a C Program to Display the Following Pattern 

** 

*** 

**** 

***** 

in C Programming Language ?



Solution:
/* Program to display the following pattern:
*
**
***
****
*****
*/
#include<stdio.h>
#include<conio.h>

void main()
{
int i, j;

clrscr();

for(i = 0; i<4; i++) {
for(j = 0; j <= i; j++)
printf("*");
printf("\n");
}

getch();
}