Code compilation [closed]

2

Please help me, I can not compile this code: Until the command prompt does not start anymore

#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("%d",a);
}
    
asked by anonymous 06.09.2015 / 02:54

2 answers

1

System pause is a DOS command of the c.E language and is used to use DOS commands. The "pause" command is used to pause the program and not let it close quickly. And you can not forget to add include stdlib.h to use it.

    
07.09.2015 / 07:49
0

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.

    
06.09.2015 / 16:23