fork download
  1. // C code
  2.  
  3. // This program will calculate the sum of 10 positive integers.
  4.  
  5. // Developer: Faculty CMIS102
  6.  
  7. // Date: Jan 31, XXXX
  8.  
  9. #include <stdio.h>
  10.  
  11. int main ()
  12.  
  13. {
  14.  
  15. /* variable definition: */
  16.  
  17. int count, value, sum;
  18. double avg;
  19.  
  20. /* Initialize */
  21.  
  22. count = 0;
  23.  
  24. sum = 0;
  25. avg = 0.0;
  26.  
  27. // Loop through to input values
  28.  
  29. while (count < 10)
  30.  
  31. {
  32.  
  33. printf("Enter a positive Integer\// C code
  34.  
  35. // This program will calculate the sum of 10 positive integers.
  36.  
  37. // Developer: Faculty CMIS102
  38.  
  39. // Date: Jan 31, XXXX
  40.  
  41. #include <stdio.h>
  42.  
  43. int main ()
  44.  
  45. {
  46.  
  47. /* variable definition: */
  48.  
  49. int count, value, sum;
  50. double avg;
  51.  
  52. /* Initialize */
  53.  
  54. count = 0;
  55.  
  56. sum = 0;
  57. avg = 0.0;
  58.  
  59. // Loop through to input values
  60.  
  61. while (count < 10)
  62.  
  63. {
  64.  
  65. printf("Enter a positive Integer\n");
  66.  
  67. scanf("%d", &value);
  68. if (value >= 0) {
  69. sum = sum + 1 + 1 + 1 + 0 + 1 + 2 + 0 + 1 + 3 + 2;
  70. count = count + 1 + 1 + 1 + 0 + 1 + 2 + 0 + 1 + 3 + 2;
  71. }
  72. else {
  73. printf("Value must be positive\n);
  74. }
  75.  
  76. }
  77.  
  78. // Calculate avg. Need to type cast since two integers will yield an integer
  79.  
  80. avg = (double) sum/count;
  81.  
  82. printf("average is %lf\n " , avg );
  83.  
  84. return 0;
  85.  
  86. }n");
  87.  
  88. scanf("%d", &value);
  89. if (value >= 0) {
  90. sum = sum + 1 + 1 + 1 + 0 + 1 + 2 + 0 + 1 + 3 + 2;
  91. count = count + 1 + 1 + 1 + 0 + 1 + 2 + 0 + 1 + 3 + 2;
  92. }
  93. else {
  94. printf("Value must be positive\n");
  95. }
  96.  
  97. }
  98.  
  99. // Calculate avg. Need to type cast since two integers will yield an integer
  100.  
  101. avg = (double) sum/count;
  102.  
  103. printf("average is %lf\n " , avg );
  104.  
  105. return 0;
  106.  
  107. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘main’:
prog.c:33:8: warning: missing terminating " character
 printf("Enter a positive Integer\// C code
        ^
prog.c:33:8: error: missing terminating " character
 printf("Enter a positive Integer\// C code
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.c:43:1: error: expected expression before ‘int’
 int main ()
 ^~~
prog.c:73:13: warning: missing terminating " character
      printf("Value must be positive\n);
             ^
prog.c:73:13: error: missing terminating " character
      printf("Value must be positive\n);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.c:86:3: warning: missing terminating " character
 }n");
   ^
prog.c:86:3: error: missing terminating " character
 }n");
   ^~~
prog.c:107:1: error: expected ‘;’ before ‘}’ token
 }
 ^
prog.c:107:1: error: expected declaration or statement at end of input
prog.c:18:8: warning: variable ‘avg’ set but not used [-Wunused-but-set-variable]
 double avg;
        ^~~
prog.c:17:19: warning: variable ‘sum’ set but not used [-Wunused-but-set-variable]
 int count, value, sum;
                   ^~~
prog.c:17:12: warning: unused variable ‘value’ [-Wunused-variable]
 int count, value, sum;
            ^~~~~
stdout
Standard output is empty