Well, I was doing some basic programming exercises and I came across a bug that I did not understand very well:
#include <stdio.h>
#include <stdlib.h>
//Program prints the odd numbers until a determined limit.
int main()
{
int numeric_limits;
int count = 1;
printf("Enter the limit number.\n");
scanf(" %d", &numeric_limits);
while(count <= numeric_limits)
{
printf(" %d\n", count);
count+2;
}
return 0;
}
This code above is in an infinite loop "Uns". While this one below works perfectly:
#include <stdio.h>
#include <stdlib.h>
//Program prints the odd numbers until a determined limit.
int main()
{
int numeric_limits;
int count = 1;
printf("Enter the limit number.\n");
scanf(" %d", &numeric_limits);
while(count <= numeric_limits)
{
printf(" %d\n", count);
count++;
count++;
}
return 0;
}
I'm programming in codeblocks ... I was testing in any online compiler to see if it was compiler problem, but in the online compiler it gave infinite loop too ... Does anyone know why this happens?