Search
 
SCRIPT & CODE EXAMPLE
 

C

pyramid pattern in c

"EASIEST EXPLANATION EVER"
/*
n=4
                *
               ***
              *****
             *******
*/

#include <iostream>
using namespace std;
int main() {
	int n=4; //indicates the number of rows.
    int max_breadth=(n-1)*2+1, mid=breadth/2; //max_breadth indicates the maximum no. of '*' in the last row.
    for(int i=0;i<n;i++)
    {
        int range_start=mid-i,range_end=mid+i;
        for(int j=0;j<max_breadth;j++)
        {
            if(j>=range_start && j<=range_end){
                cout<<"*";
            }
            else{
                cout<<" ";
            }
        }
        cout<<endl;
    }
    return 0;
}
Comment

pyramid using c

#include <stdio.h>

int main(){
    int i,j,n,;//declaring variables

    /*
    At first half pyramid
    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    */
    printf("Enter rows: 
");
    scanf("%d",&n);

    printf("half pyramid

");
    for(i=0;i<n;i++){ //loop for making rows
        for(j=0;j<i;j++){ //loop for making stars. Here "i" is row number and n is total row number. so for making 1 star after 1 star you've to put variable "i"
            printf("* ");
        }
        //printing new line
        printf("
");
    }

    printf("

");





    /*
    making full pyramids

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

    */
    printf("full pyramid

");
    //the first loop is for printing rows
    for(i=1;i<=n;i++){
        //loop for calculating spaces
        for(j=1;j<=(n-i);j++){ //to calculate spaces I use totalRows-rowNo formula
            printf(" ");
        }

        //loop for calculating stars
        for(j=1;j<=((2*i)-1);j++){ //using the formula "2n-1"
            printf("*");
        }
        //printing a new line
        printf("
");
    }





    return 0;


}
Comment

Pyramid pattern in c

#include <stdio.h>
int main() {
   int i, space, rows, k = 0;
   printf("Enter the number of rows: ");
   scanf("%d", &rows);
   for (i = 1; i <= rows; ++i, k = 0) {
      for (space = 1; space <= rows - i; ++space) {
         printf("  ");
      }
      while (k != 2 * i - 1) {
         printf("* ");
         ++k;
      }
      printf("
");
   }
   return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: Firebase Connecting with ESP8266 
C :: what is syntax in programming 
C :: what is string::npos 
C :: arduino wifi client 
C :: c programming how to force stop the programme 
C :: binary to decimal in c 
C :: plt legend top right outside 
C :: warning: function returns address of local variable [-Wreturn-local-addr] 
C :: c/c++ windows api download file 
C :: functions in c 
C :: why there is return 0 used in c 
C :: flip exis in dataframe 
C :: int to double c 
C :: how to read 2d array from a file in c 
C :: print to console in c 
C :: C - program to create 1D array 
C :: pid of a process in c 
C :: C program to input the month number and output the month name using switch statement 
C :: why do you jerk while falling aslee 
C :: how to arrange a 2d array based on string length in c 
C :: time include c 
C :: what is the use of malloc in c 
C :: pointer c 
C :: what is O(N^2) in bubble sort method 
C :: gcc compiler for windows 10 
C :: C static libraries (Indexing an archive) 
C :: remove language from jupyter notebook 
C :: C static libraries (creating object files) 
C :: clipboard lib 
C :: djb2 algorithm for C 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =