fork(4) download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. // i;q(char*n){double m=0;while(*n)m+=*n++-48;m=sqrt(m)-(int)sqrt(m);return !m;}
  5. // s(char**n,int s){i=-1;while(++i<s)if(q(n[i]))printf("%s\n",n[i]);}
  6.  
  7. int q(char*n)
  8. {
  9. double m=0;
  10.  
  11. while(*n) // sum digits
  12. m+=*n++-48;
  13.  
  14. // get the decimal part
  15. m=sqrt(m)-(int)sqrt(m);
  16.  
  17. // true if decimal part is zero
  18. return !m;
  19. }
  20.  
  21. // input is text, can be a file
  22. void s(char**n, int s)
  23. {
  24. int i=-1;
  25.  
  26. while(++i<s) // for each number in input
  27. if(q(n[i])) // if is square
  28. printf("%s\n",n[i]); // output is terminal
  29. }
  30.  
  31. int main(void)
  32. {
  33. char* test[] = {"1","2","4", "9","16","25","1111"};
  34. s(test, sizeof(test)/sizeof(test[0]));
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
1
4
9
1111