Solved

C Lanugage Programme Coding for Creating Pyramid

Posted on 2007-11-25
9
7,063 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maze travler 6 51
Move constructor only called if marked noexcept? 6 98
IdTCPClient1->Disconnect(); not working 3 60
What is atomic operation? 6 45
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

911 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

19 Experts available now in Live!

Get 1:1 Help Now