any other way you'd write this?
Hi everyone,
I'm learning c right now and doing the exercises from the book. The exercise prompts to write
a counting program that prompts the user for three inputs:
- beginning number to start counting from
- ending number
- increment number
I wrote this:
Code:
#include <stdio.h>
main()
{
int ifrom = 0;
int ito = 0;
int iby = 0;
scanf("%d%d%d", &ifrom, &ito, &iby);
do {
printf("\n%d\n", ifrom);
ifrom = ifrom + iby;
} while ( ifrom - iby < ito ); // end do while loop
} // end main function
ok it seems to work but there is one thing that bothers me: in the while statement I have "ifrom - iby < ito" because (ifom < ito) counted numbers from ifrom to ito minus the increment (iby) which was wrong. Here's the question, how this can be written to work using only conditional operators without the "minus thing"
And another question is, whether you know a better way to write this little program and could you please share with me your wisdom.
Thanks for all the help guys,