Thread: Help me with reverse pyramid program?

  1. #1
    Registered User
    Join Date
    Jun 2017
    Posts
    11

    Talking Help me with reverse pyramid program?

    I managed to make the right one with help of a teacher(but he had changed the 1st main for loop and changed the codes quite a lot). I am more into solving this only using the inside 2 for loops and not affecting 1st one(Unless it is purely wrong). Maybe one of you guys can help me. Code is as below.:-
    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int i,j,k,n;
    clrscr();
    printf("Enter the number of rows.\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
      {
       printf(" ");
      }
      for(k=n;k>0;k--)
      {
       printf("*");
      }
      printf("\n");
    }
    getch();
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    main returns int, not void.
    FAQ > main() / void main() / int main() / int main(void) / int main(int argc, char *argv[]) - Cprogramming.com

    Try naming your variables better, say
    int numberOfRows;
    int numberOfLeadingSpaces;
    int numberOfStars;

    Then you have your main loop
    for ( i = 0 ; i < numberOfRows ; i++ )
    numberOfLeadingSpaces = some calculation based on i
    numberOfStars = some other calculation based on i

    Then
    for ( j = 0 ; j < numberOfLeadingSpaces ; j++ ) printf(" ");

    Get the idea?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C program to draw a pyramid
    By nyck66 in forum C Programming
    Replies: 3
    Last Post: 05-20-2017, 04:23 AM
  2. Printing a reverse pyramid using C
    By djadil in forum C Programming
    Replies: 9
    Last Post: 04-19-2015, 02:57 AM
  3. Replies: 1
    Last Post: 05-30-2010, 10:22 PM

Tags for this Thread