The next thing that happens once you write more complicated programs, is that you make mistakes ("bugs"). You therefore need strategies to "debug" your program.
If you program compiles and runs but doesn’t do what you had intended for it to do then one great strategy is to sprinkle your code with printf() statements that leave a trail of how the program executes and allow you to track the values of important variables along the way. This strategy makes it easier to pinpoint where in your code things are starting to go wrong.
#include <stdio.h>
int main(void)
{
int N, i, sum;
printf("Good Morning!\n"); /* printf() statement #1 */
i=1;
N=10;
sum=0;
while (i <= N) {
printf("i = %d, sum = %d.") /* printf() statement #2 */
sum += N;
i--;
}
printf("The sum from 1 to %d equals %d.\n", N, sum); /* printf() statement #3 */
return(0);
}