Link to home
Start Free TrialLog in
Avatar of JatinHemant
JatinHemantFlag for Rwanda

asked on

C Lanugage Programme Coding for Creating Pyramid

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
Avatar of Deepu Abraham
Deepu Abraham
Flag of United States of America image

ASKER CERTIFIED SOLUTION
Avatar of yuy2002
yuy2002

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yuy2002: Unless author posts his code, we should not. this is followd strictly by EE.
>> 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 ;)
Avatar of yuy2002
yuy2002

>>yuy2002: Unless author posts his code, we should not. this is followd strictly by EE.
got it.
Avatar of JatinHemant

ASKER

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
Are you sure you were allowed to use gotoxy for this ?
Yes, I used gotoxy and it worked. There is no problem in program execution.

Regards,

Hemant
"allowed" as in "allowed for the assignment".