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.
Need help with a turbo c program....urgent plz help
Started by hassan_shohag, Jun 27 2010 07:31 AM
7 replies to this topic
#1
Posted 27 June 2010 - 07:31 AM
|
|
|
#2
Posted 27 June 2010 - 09:30 AM
What do you have done so far?
#3
Posted 27 June 2010 - 09:38 AM
int i,n;
clrscr();
printf("n:"); /*n must be an odd number*/
scanf("%d",&n);
for(i=n;i>=1;i--)
{
printf("*",i);
}
getch();
clrscr();
printf("n:"); /*n must be an odd number*/
scanf("%d",&n);
for(i=n;i>=1;i--)
{
printf("*",i);
}
getch();
#4
Posted 27 June 2010 - 09:56 AM
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
for(i=n;i>1;i--)
for Max to 1 Star
then
for(i=1;i<n;i++)
for 1 to Max Stars
#5
Posted 27 June 2010 - 10:11 AM
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();
}
#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
Posted 27 June 2010 - 10:44 AM
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
Posted 28 June 2010 - 03:56 AM
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
Posted 30 June 2010 - 12:00 AM
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:
:crying:


Sign In
Create Account

Back to top









