Hi im really confused with c language programming.Im a middle school student and our instructor wanted us to make a program that will display the following:
54321
4321
321
21
1
displaying that should be relatively easy but our instructor asked us to use a do-while or a do-for statement.this is what i came up with
#include<stdio.h>
int main()
{
int x,y;
for (x=5;x>=1;x--)
{
for(y=1;y<=5;y++)
{
printf("%i",x);
x--;
}
printf("\n");
}
getch();
}
All this program displayed was 54321 please help ! any advice would do.
Hahaha I got the same question on my C++ exam only instead of numbers it was
*****
****
***
**
*
I didn't get it write then, but I got home and with my brother's help. I did it. I won't give you the answer directly, I'll give you hints. If you didn't know then I'll give you the answer.
You started it kind of correctly, when you did the 2 for loops inside each other. But you gotta change something in the second for loop to make it print 5 digits, then 4, then 3, then 2, then 1.
Your program gives
54321
54321
54321
54321
54321
If you change the 2nd for loop. HINT: Include x somewhere in the 2nd for loop.
Hello my friend,
I see that you have corrected it, but instead of letting z into the program. Use x instead
I Edited Your Last Code Into This
1 2 3 4 5 6 7 8 9 10 11 12 13
#include<stdio.h>
int main()
{
int x,y;
for(x=5;x>=1;x--)
{
for(y=x;y>=1;y--)
printf("%i",y);
printf("\n");
}
getch();
}
//Now it should work totally fine without the z variable.
Yours is totally right, but when dealing with bigger programs, the lesser variables you put, the better!
This is the first year my high school has offered a computer programming class. We're studying c++. First semester were just doing text based applications. Second semester were switching to Win32 programming.
A great place to challenge yourself is projecteuler.net, I had done up to question 15, then I showed my teacher. He loves the website and has begun to use it in school.
Personally, I use a mac and have began to learn how to use cocoa. If you have any beginner questions I would love to help.