Jump to content

Need help with a turbo c program....urgent plz help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
hassan_shohag

hassan_shohag

    Newbie

  • Members
  • Pip
  • 3 posts
dear friends,
i have this assignment for class which is getting on my nerves every time i try to write the program.
the program is as follows...

there will be a variable 'n' which must be entered by the user. For example if a value of 7 is entered for 'n', then in the display it will print a sand-clock consisting of 7 stars on the first line. 5 stars in the second line. 3 stars in the third line. and 1 star in the fourth line. after that it will increase again like before. like 3 stars on the fifth line. 5 stars in the sixth line. and again seven stars in the seventh line.


*******
*****
***
*
***
*****
*******


THIS.
Please help me with this assignment.

#2
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
What do you have done so far?

#3
hassan_shohag

hassan_shohag

    Newbie

  • Members
  • Pip
  • 3 posts
int i,n;
clrscr();
printf("n:"); /*n must be an odd number*/
scanf("%d",&n);
for(i=n;i>=1;i--)
{
printf("*",i);
}
getch();

#4
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
One way would be use two Loops
for(i=n;i>1;i--)
for Max to 1 Star
then
for(i=1;i<n;i++)
for 1 to Max Stars

#5
hassan_shohag

hassan_shohag

    Newbie

  • Members
  • Pip
  • 3 posts
i cant go to end..

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,j;
clrscr();
printf("n:");
scanf("%d",&n);
for(i=n;i>=1;i--)
{


printf("*",i);
printf(" \n*",i-2);

}
for(i=1;i<=n;i++)
{
printf("*",i);
// break;
}
getch();
}

#6
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
Try using string stars (i,"*"); this will create a string of i "*" in the string stars.
       string stars (5,'*');
        cout << stars << endl;
 
For example would print
*****

#7
Davide

Davide

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 506 posts
This should be in the C category
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

#8
pengling

pengling

    Newbie

  • Members
  • Pip
  • 2 posts
after that it will increase again like before. like 3 stars on the fifth line. 5 stars in the sixth line. and again seven stars in the seventh line.
:crying: