There are no syntax errors in the code. C code is legitimate, compiles, and executes. The code executes and writes an integer on the screen the number 7. Perhaps the problem lies in some peripheral details. You can try to display some blank lines before and after the number so that it becomes more 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 interesting you add system("pause");
before closing the keys to main
, so that the window of the prompt
don’t close yourself:
#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 is important to check that at the time you compile the code there is no execution window already open. If it exists it will close before compiling your code.
compiled here, the result was 7, which error is giving?
– Leonardo
How did you manage to compile? in my note was not. (Windows)
– user32333
I just copied and pasted in Dev C++ and compiled with F11. It’s on Windows?
– Leonardo
Which IDE you are using?
– Pena Pintada
Can you explain what IDE is?
– user32333
For example, I can’t even compile #include <stdio. h> int main() { int x; int soma=0; int k =1; while (k<=15) { scanf("%d", &x); soma = sum + x; k = k + 1; } } ;}
– user32333
See working and more organized to facilitate reading: http://ideone.com/NrJirM. I’ll repeat so you don’t insist on material that teaches you to make bad codes. If you are making a mistake to compile, post it. Give details so we can help.
– Maniero
@user32333 About IDE I use Codeblocks, the above friend used Dev C++ , This name comes from the English IDE(Integrated Development Environment). In a rough translation it would be: Integrated Development Environment. The IDE has many features that help with program development, but, roughly speaking, they basically have a compiler and a graphical interface!!
– Pena Pintada
What compiler you are using?
– DaviAragao
@user32333 Syntactically the code is correct. To know why it is not compiling, the information that the above friends requested is necessary. Which is your operating system? Which is your IDE? Which is your compiler? What is the error noted?
– lys