There are no syntax errors in the code. The C code is legitimate, compiles, and executes. The code executes and writes an integer on the screen to the number 7. The problem may be in some peripheral details. You can try to display some blank lines before and after the number so it stays clear on the screen:
#include <stdio.h>
int main()
{
int x, y, z;
int a = 0;
for(x = 0; x <= 1; x = x + 1)
for(y = x; y <= 1; y = y + 1)
for(z = y; z <= 2; z = z + 1)
a = a + 1;
printf("\n\n %d \n\n", a);
}
In some environments it may be worthwhile to add system("pause");
before closing the keys of main
, so that the prompt
window does not close itself:
#include <stdio.h>
int main()
{
int x, y, z;
int a = 0;
for(x = 0; x <= 1; x = x + 1)
for(y = x; y <= 1; y = y + 1)
for(z = y; z <= 2; z = z + 1)
a = a + 1;
printf("\n\n %d \n\n", a);
system("pause");
}
It's important to make sure that at the time you compile the code there is no running window already open. If so, close it before compiling your code.