Trying to write a simple program, that if the user entered '5' the output would be:
0
01
012
0123
01234
012345
01234
0123
012
01
0
I'm having trouble coming up with the proper loops to do this. Any help would be appreciated.
Thanks!
7 replies to this topic
#1
Posted 11 October 2010 - 02:59 PM
|
|
|
#2
Posted 11 October 2010 - 03:24 PM
You'll need a nested for loop, followed by a second nested for loop.
#3
Posted 11 October 2010 - 04:07 PM
I am trying to print out a wheel/or circle to the screen. How would I go about this?
#4
Posted 12 October 2010 - 08:58 AM
by wheel, do your meen a wheel made out of ascii characters ?
#5
Posted 12 October 2010 - 09:16 AM
Yes, dollar signs and or stars, using for loops.
#6
Posted 12 October 2010 - 09:16 AM
agnl666 said:
by wheel, do your meen a wheel made out of ascii characters ?
yes, dollar signs and or stars, using for loops.
#7
Posted 12 October 2010 - 12:40 PM
TitanClone said:
Trying to write a simple program, that if the user entered '5' the output would be:
0
01
012
0123
01234
012345
01234
0123
012
01
0
I'm having trouble coming up with the proper loops to do this. Any help would be appreciated.
Thanks!
0
01
012
0123
01234
012345
01234
0123
012
01
0
I'm having trouble coming up with the proper loops to do this. Any help would be appreciated.
Thanks!
int main(int argc, char ** argv) {
int num, i, n;
scanf("%d", &num);
for (i = 0; i <= num; i++) {
for (n = 0; n <= i; n++)
printf("%d", n);
printf("\n");
}
for (i = num - 1; i >= 0; i--) {
for (n = 0; n <= i; n++)
printf("%d", n);
printf("\n");
}
}
#8
Posted 14 October 2010 - 10:58 AM
Hi!
I am trying to get this code to print a wheel on the screen. it is kind of printing sideways. could you please look at it and tell me whats wrong?
int main()
{
int distance, x, y;
for (y=-20; y<=20; y++)
for (x=-20; x <= 20; x++)
{
if (x*x + y*y >= 20*20)
printf(" ");
else if (x*x + y*y < 2)
printf("+");
else if (x*x + y*y <= 6*6)
printf("$");
else
printf("*");
}
system("pause");
return 0;
}
I am trying to get this code to print a wheel on the screen. it is kind of printing sideways. could you please look at it and tell me whats wrong?
int main()
{
int distance, x, y;
for (y=-20; y<=20; y++)
for (x=-20; x <= 20; x++)
{
if (x*x + y*y >= 20*20)
printf(" ");
else if (x*x + y*y < 2)
printf("+");
else if (x*x + y*y <= 6*6)
printf("$");
else
printf("*");
}
system("pause");
return 0;
}
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









