Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C Lanugage Programme Coding for Creating Pyramid

Posted on 2007-11-25
9
Medium Priority
?
7,081 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

705 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