Solved

C Lanugage Programme Coding for Creating Pyramid

Posted on 2007-11-25
9
7,057 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: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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now