Thread: Question On Shape

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    2

    Question On Shape

    #include <stdio.h>

    main ()
    {
    int height;
    int star = 0;

    printf("How high would you like the pyramid?\n");
    scanf("%d",&height);
    if (height > 30) {
    printf("Pick another height (must be between 1 and 30):\n");
    scanf("%d",&height);
    }
    while (star!=height) {
    printf("*");
    printf("*\n");
    star=star+1;
    }



    return 0 ;

    }

    this is what i did ...
    but i want it to be a pyramid in shape printed with "*"

    thx for reading

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Search this board. This question has been asked (and solved)several times.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    2
    sorry for my newbieness in C language
    i have found the sample of my question from some old thread, it is like this :

    #include <stdio.h>
    #include <ctype.h>
    int main(void)
    {
    int p,q,x,y;
    char ch,in;
    printf("\nEnter a lower case letter:\n\n");
    fflush(stdout);
    printf("\nGet a Capital character: \n\n");
    scanf("%c",&in);
    p=in-'a'+1; /* position in alphabet of in i.e. a=1,b=2,c=3... */
    for(x='a',q=p;x<=in;x++)
    {
    for(y=1;y<q;y++) printf(" "); /* inserts the relevant amount of spaces*/
    for(ch='a';ch<=x;ch++) printf("%c",toupper(ch));
    for(ch=x-1;ch>='a';ch--) printf("%c",toupper(ch));
    printf("\n");
    q--;
    }
    return 0;
    }

    but i cant figure out on how to convert it to my question .,.*straching head*

  4. #4
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    Here's a good one that handles any size without a lot of complicated looping. :-)
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main(void)
    {
      int i;
      int spaces;
      int height;
      char *stars;
    
      printf("Enter the height: ");
      if (scanf("%d", &height) != 1)
      {
        return 1;
      }
    
      if ((stars = malloc(height*2 + 1)) == 0)
      {
        return 1;
      }
    
      memset(stars, '*', height*2);
      stars[height*2] = '\0';
    
      for (spaces = height, i = 1; spaces > 0; i += 2)
      {
        printf("%*c%.*s\n", spaces--, ' ', i, stars);
      }
    
      free(stars);
    
      return 0;
    }
    *Cela*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Filling a shape
    By SlayerBlade in forum C Programming
    Replies: 5
    Last Post: 10-07-2005, 08:26 PM
  2. Newbie- having trouble with functions
    By bnmwad in forum C Programming
    Replies: 7
    Last Post: 02-22-2005, 04:41 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM