Skip to content

Instantly share code, notes, and snippets.

@SwadhInz
Created August 20, 2015 17:59
Show Gist options
  • Select an option

  • Save SwadhInz/2cc540210fd2e4dc3310 to your computer and use it in GitHub Desktop.

Select an option

Save SwadhInz/2cc540210fd2e4dc3310 to your computer and use it in GitHub Desktop.

Revisions

  1. SwadhInz created this gist Aug 20, 2015.
    26 changes: 26 additions & 0 deletions pyramid.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #include <stdio.h>

    int main()
    {
    int line, t, n, k, sum, i, j;

    scanf("%d", &n);

    for(line = 1; line <= n; line++) {
    for(i = 0; i < (n - line); i++)
    printf(" ");
    t = line - 1;
    printf("%d", line);
    for(k = 1; k <= t; k++) {
    sum = line + k;
    printf("%d", sum);
    j = sum;
    }
    for(k =1; k <= t; k++) {
    sum = j - k;
    printf("%d", sum);
    }
    printf("\n");
    }
    return 0;
    }