From ac5aa74d26dcd5b69c30f14254261f1c80712086 Mon Sep 17 00:00:00 2001 From: UTKARSH AGRAWAL <71021450+Scientist69@users.noreply.github.com> Date: Sun, 24 Oct 2021 23:07:58 +0530 Subject: [PATCH] number_pyramid.c --- C/number_pyramid.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 C/number_pyramid.c diff --git a/C/number_pyramid.c b/C/number_pyramid.c new file mode 100644 index 0000000..0337891 --- /dev/null +++ b/C/number_pyramid.c @@ -0,0 +1,52 @@ +/* + This is number pyramid program. Here the input data is the number of rows as shown below in the following examples. + Enter number of rows: 4 + 1 + 2 3 2 + 3 4 5 4 3 +4 5 6 7 6 5 4 + Enter number of rows: 8 + 1 + 2 3 2 + 3 4 5 4 3 + 4 5 6 7 6 5 4 + 5 6 7 8 9 8 7 6 5 + 6 7 8 9 10 11 10 9 8 7 6 + 7 8 9 10 11 12 13 12 11 10 9 8 7 +8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 +*/ +#include +int main() +{ + int i, s, r, k=0, c = 0, count = 0; + + printf("Enter number of rows: "); + scanf("%d",&r); + + for(i=1; i<=r; ++i) + { + for(s=1; s <= r-i; ++s) + { + printf(" "); + ++c; + } + + while(k != 2*i-1) + { + if (c<= r-1) + { + printf("%d ", i+k); + ++c; + } + else + { + ++count; + printf("%d ", (i+k-2*count)); + } + ++k; + } + count = c = k = 0; + + printf("\n"); + } +}