Solved

C Lanugage Programme Coding for Creating Pyramid

Posted on 2007-11-25
9
7,073 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:DeepuAbrahamK
ID: 20348578
0
 
LVL 4

Accepted Solution

by:
yuy2002 earned 125 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
Independent Software Vendors: 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Dialogbox API leak? 18 109
Least Squares Curve Fitting 4 116
Add values of each row in an array 3 70
Test the speeds on my PC Drives 12 71
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

749 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