programming like c, c++, java,python learn in free

Tuesday, June 2, 2020

C programming Question and Answer Day-7

31. Pattern 11

1                   1
1 2             2 1
1 2 3       3 2 1
1 2 3 4 4 3 2 1

#include<stdio.h>
#include<conio.h>
void main()
{
    int i, j, k;
    clrscr();

    for (i = 1; i <= 5; i++)
    {
        for (j = 1; j <= 5; j++)
        {
            if (j <= i)
            {
                printf("%d ", j);
            }
            else
            {
                printf(" ");
            }
        }
        for (j = 5; j >= 1; j--)
        {
            if (j <= i)
            {
                printf("%d ", j);
            }
            else
            {
                printf(" ");
            }
        }
        printf("\n");
    }
    getch();
}

32. Floyd's triangle

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

#include<stdio.h>
#include<conio.h>
void main()
{
    int n, i, c, a = 1;
    clrscr();

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

    for (i = 1; i <= n; i++) {

        for (c = 1; c <= i; c++) {

            printf("%d ", a);
            a++;

        }

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

33. Pyramid

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

#include<stdio.h>
#include<conio.h>
void main()
{
    int row, c, n, temp;
    clrscr();

    printf("Enter the number of rows : ");
    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();
}

34. Pyramid 2

       *
      A
    A*A
  A*A*A
A*A*A*A

#include<stdio.h>
#include<conio.h>
void main()
{
    int n, c, k, space, count = 1;
    clrscr();

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

    space = n;

    for (c = 1; c <= n; c++)
    {

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

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

            if (c > 1 && count < c)
            {
                printf("A");
                count++;
            }
        }

        printf("\n");
        space--;
        count = 1;
    }
    getch();
}

35. Number Pyramid

        1
      232
    34543
  4567654
567898765

#include<stdio.h>
#include<conio.h>
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();
}
Share:

0 comments:

Post a Comment

Unordered List

recentposts1
Powered by Blogger.

Text Widget

Featured Post

C programming Question and Answer Day-15

71. Program to check Niven number (Harshad number). #include<stdio.h> #include<conio.h> void main() {     int n, d, a, su...

Search This Blog

recent comments

recentcomments

Labels

[slideshow][technology]

vertical posts

[verticalposts][technology]

business

[business][grids]

ad space

ads 600

vehicles

[cars][stack]
[verticalposts][food]

our facebook page

about us

logo

Jupiter is a magazine responsive Blogger template. It has everything you need to make your blog stand out. This template is fully customizable and very flexible and we believe you will love it as much as we do.

Slide show

[people][slideshow]

health

[health][btop]

recent posts

recentposts1

Subscribe Us

random posts

randomposts2

Blog Archive

Recent Posts

top ads

Unordered List

recent

Pages

Theme Support

[socialcounter] [facebook][#][215K] [twitter][#][115K] [youtube][#][215,635] [rss][#][23M] [linkedin][#][21.5K] [instagram][#][600,300]