Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote