C program to Inverted pyramid number pattern - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Monday, December 16, 2019

C program to Inverted pyramid number pattern - My CS Tutorial

C program to print or create a inverted pyramid number pattern by 0 and 1.

In this tutorial we will learn how to write a c program code that print or create a inverted pyramid pattern using numbers 0 and 1.





C program code


#include<stdio.h>
#include<conio.h>
void main()
{
    int x,y,z,rows,count,temp,a=1,totalNumbers=0;
    printf("\n Enter number of rows:\n ");
    scanf("%d",&rows);
    printf(" \n");
    count=1;
    // using formula a+(n-1)*d
    temp=1+(rows-1)*2;
    for(x=0;x<rows;x++)
    {
     if(x!=0)
        {
      a+=2;
     }
   totalNumbers+=a;
    }

    for(x=1;x<=rows;x++)
    {
        for(y=1;y<=count;y++)
        {
            printf(" ");
        }
        for(z=temp;z>=1;z--)
        {
            printf("%d",totalNumbers%2);
            totalNumbers--;
        }
        count++;
        temp-=2;

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


OUTPUT:





In this output we can see that it is a inverted pyramid pattern that create by numbers as 0 and 1.
In the first we will enter the range of this inverted pyramid then will be print.This is a c programing code for inverted pyramid pattern by using numbers 0 and 1.
We can see that the range of inverted pyramid is 25 in input and 25 lines are available in this inverted pyramid pattern.


Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com

Created by-- HARSH CHAUHAN

No comments:

Post a Comment