Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C Lanugage Programme Coding for Creating Pyramid

Posted on 2007-11-25
9
Medium Priority
?
7,082 Views
Last Modified: 2008-02-01
Hi friends !

Long before 5 years, I used to make some basic and intermediate programmes using C language. But after that, I switched to Computer Networks, so I never used 'C' again.

Now, I am doing my M.Sc. and I want to be proficient in 'C' at least for my examination purpose. I want to make a programme to create a star pyramid. What will be the coding ?

As, I told you, I have previous knowledge, so I can understand the commands.

If you can also give me a website address from where, I can get some programme codings, then it will be nice of you.

Regards,

Hemant
0
Comment
Question by:JatinHemant
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 11

Expert Comment

by:Deepu Abraham
ID: 20348578
0
 
LVL 4

Accepted Solution

by:
yuy2002 earned 375 total points
ID: 20348646
core code:
void printpyramid(int line, char a)
{
    if(line>1024)
    {
        return;
    }
    int i=0,j=0;
    for(i=1;i<=line;i++)
    {
        for(j=line-i;j>=0;j--)
        {
            printf(" ");
        }
        for(j=0;j<2*i-1;j++)
        {
            printf("%c",a);
        }
        printf("\n");
    }
}
0
 
LVL 5

Expert Comment

by:abith
ID: 20348956
yuy2002: Unless author posts his code, we should not. this is followd strictly by EE.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Infinity08
ID: 20349246
>> I want to make a programme to create a star pyramid. What will be the coding ?

You want to figure out what the structure of a pyramid is (it's pretty basic), and find the logic in it. Then all you have to do is have a nested loop that prints *'s and spaces depending on where in the pyramid you are.

It's not very complicated, so just give it a try, and post what you have here.

You'll need printf for output ;)
0
 
LVL 4

Expert Comment

by:yuy2002
ID: 20362644
>>yuy2002: Unless author posts his code, we should not. this is followd strictly by EE.
got it.
0
 

Author Comment

by:JatinHemant
ID: 20438235
Hi friends !

I used this code with some exercise and now it is OK. Please see what code, I used and if any suggestions to make it short or better, please give your kind suggestions.

The code is here:
******************************************************************************************************************************
#include<stdio.h>
#include<conio.h>

void main()

{

int i=0;
int j=0;
int n;
int cpos, rpos;


cpos=39;
rpos=5;

clrscr();

printf("Enter the number: ");
scanf("%d", &n);

for (i=0; i<=n; i++)
 {
   gotoxy(cpos, rpos);

   for (j=1; j<=i*2-1; j++)

   {

    printf("*");

   }

   rpos=rpos+1;
   cpos=cpos-1;


 }

getch();


}

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

Regards,

Hemant
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 20438252
Are you sure you were allowed to use gotoxy for this ?
0
 

Author Comment

by:JatinHemant
ID: 20471591
Yes, I used gotoxy and it worked. There is no problem in program execution.

Regards,

Hemant
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 20471610
"allowed" as in "allowed for the assignment".
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question