// C code
// This program will calculate the sum of 10 positive integers.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include <stdio.h>
int main ( )
{
/* variable definition: */
int count, value, sum;
double avg;
/* Initialize */
count = 0 ;
sum = 0 ;
avg = 0.0 ;
// Loop through to input values
while ( count < 10 )
{
printf ( "Enter a positive Integer\// C code
// This program will calculate the sum of 10 positive integers.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include <stdio.h>
int main ()
{
/* variable definition: */
int count, value, sum;
double avg;
/* Initialize */
count = 0;
sum = 0;
avg = 0.0;
// Loop through to input values
while (count < 10)
{
printf(" Enter a positive Integer\n");
scanf(" % d", &value);
if (value >= 0) {
sum = sum + 1 + 1 + 1 + 0 + 1 + 2 + 0 + 1 + 3 + 2;
count = count + 1 + 1 + 1 + 0 + 1 + 2 + 0 + 1 + 3 + 2;
}
else {
printf(" Value must be positive\n) ;
}
}
// Calculate avg. Need to type cast since two integers will yield an integer
avg = ( double ) sum/ count;
printf ( "average is %lf\n " , avg
) ;
return 0 ;
} n");
scanf(" % d", &value);
if (value >= 0) {
sum = sum + 1 + 1 + 1 + 0 + 1 + 2 + 0 + 1 + 3 + 2;
count = count + 1 + 1 + 1 + 0 + 1 + 2 + 0 + 1 + 3 + 2;
}
else {
printf(" Value must be positive\n");
}
}
// Calculate avg. Need to type cast since two integers will yield an integer
avg = (double) sum/count;
printf(" average is % lf\n " , avg );
return 0;
}
Ly8gQyBjb2RlCgovLyBUaGlzIHByb2dyYW0gd2lsbCBjYWxjdWxhdGUgdGhlIHN1bSBvZiAxMCBwb3NpdGl2ZSBpbnRlZ2Vycy4KCi8vIERldmVsb3BlcjogRmFjdWx0eSBDTUlTMTAyCgovLyBEYXRlOiBKYW4gMzEsIFhYWFgKCiNpbmNsdWRlIDxzdGRpby5oPgoKaW50IG1haW4gKCkKCnsKCi8qIHZhcmlhYmxlIGRlZmluaXRpb246ICovCgppbnQgY291bnQsIHZhbHVlLCBzdW07CmRvdWJsZSBhdmc7Cg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c3VtL2NvdW50OwoKcHJpbnRmKCJhdmVyYWdlIGlzICVsZlxuICIgLCBhdmcgKTsKCnJldHVybiAwOwoKfW4iKTsKCnNjYW5mKCIlZCIsICZ2YWx1ZSk7CmlmICh2YWx1ZSA+PSAwKSB7CiAgICBzdW0gPSBzdW0gKyAxICsgMSArIDEgKyAwICsgMSArIDIgKyAwICsgMSArIDMgKyAyOwogICAgY291bnQgPSBjb3VudCArIDEgKyAxICsgMSArIDAgKyAxICsgMiArIDAgKyAxICsgMyArIDI7Cn0KZWxzZSB7CiAgICAgcHJpbnRmKCJWYWx1ZSBtdXN0IGJlIHBvc2l0aXZlXG4iKTsKfQoKfQoKLy8gQ2FsY3VsYXRlIGF2Zy4gTmVlZCB0byB0eXBlIGNhc3Qgc2luY2UgdHdvIGludGVnZXJzIHdpbGwgeWllbGQgYW4gaW50ZWdlcgoKYXZnID0gKGRvdWJsZSkgc3VtL2NvdW50OwoKcHJpbnRmKCJhdmVyYWdlIGlzICVsZlxuICIgLCBhdmcgKTsKCnJldHVybiAwOwoKfQ==
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