Complete the program that can compute the sum and product of the input values. T
ID: 3642079 • Letter: C
Question
Complete the program that can compute the sum and product of the input values. The program exists when the input is '0'.
#include <studio.h>
int main(){
int sum = , product = , a; //initialization sum and product
FILE *fp = fopen( "data.txt", "r+" );
fscanf( ); //read input
while( ){ //if input is zero, stop computing
//otherwise, computing sum and product
//read input
}
fprintf( ); //write sum and product
fclose(fp);
return 0;
}
Explanation / Answer
#include int main(){ int sum =0,product =1,a; //initialization sum and product FILE *fp = fopen( "data.txt", "r+" ); fscanf(fp, "%d",&a ); //read input while(a !=0){ //if input is zero, stop computing sum += a; //otherwise, computing sum and product product *= a; fscanf(fp,"%d",&a ); //read input } fprintf(fp, "The sum is : %d and product is : %d ", sum, product); //write sum and product fclose(fp); return 0; }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.