fork(1) download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int x;
  5. float y;
  6.  
  7. while( x > 0)
  8. {
  9. printf("Enter any integer:\n");
  10. scanf("%d", &x);
  11. // x is an even number if is perfectly divisible by 2
  12. if (x%2 == 0)
  13. {
  14. y= (float)x*(float)x;
  15. printf("y= %f\n");
  16.  
  17. //x is an odd number if it is not perfectly divisible by 2
  18. else if (x%2 != 0)
  19. {
  20. y=(float)x+2;
  21. printf("y= %f\n");
  22. }
  23. else
  24. printf("Invalid entry, only positive integers accepted\n");
  25. }
  26. }
  27. return 0;
  28. }
  29.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
2
compilation info
prog.c: In function ‘main’:
prog.c:15:16: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat=]
    printf("y= %f\n");
                ^
prog.c:18:4: error: expected ‘}’ before ‘else’
    else if (x%2 != 0)
    ^~~~
prog.c:21:16: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat=]
    printf("y= %f\n");
                ^
prog.c:5:7: warning: variable ‘y’ set but not used [-Wunused-but-set-variable]
 float y;
       ^
prog.c: At top level:
prog.c:27:1: error: expected identifier or ‘(’ before ‘return’
 return 0;
 ^~~~~~
prog.c:28:1: error: expected identifier or ‘(’ before ‘}’ token
 }
 ^
stdout
Standard output is empty