there is a problm in this programmebut i dont know what is itquestionWrite a C-Program that does the following• Read integer numbers from a file inp.dat• Calculate the sum, average, and multiplicand of even numbers and store the result and the even numbers in output file out1.dat• Calculate the sum, average, and multiplicand of odd numbers and stored the result and the odd numbers in output file out2.dat

#include #include #includemain (){   FILE *inp,*outp1,*outp2;   int  num, even_sum, odd_sum, even_product, odd_product, count_even=0, count_odd=0;   double even_average, odd_average;               inp=fopen("C:\\inp.dat","r");               outp1=fopen("C:\\out1.txt","w");               outp2=fopen("C:\\out2.txt","w");if(inp==NULL)   {       printf("cannot open file");       exit(1);   }even_sum=0;even_product=1;odd_sum=0;odd_product=1;for(fscanf(inp,"%d",num); num!=EOF; fscanf(inp, "%d", num));   {       if(num%2 ==0)       {       fprintf(outp1, "even=%d\n", num);       even_sum +=num;       even_product *=num;       count_even++;       }       else      {           fprintf(outp2, "odd=%d\n", num);           odd_sum +=num;           odd_product *=num ;           count_odd++;       }}       even_average=(even_sum)/(count_even);       odd_average=(odd_sum)/(count_odd);       fprintf(outp1,"the sum=%d\n the product=%d\nand the average=lf",even_sum,even_product,even_average);       fprintf(outp2,"the sum=%d\n the product=%d\n and the average=%lf",odd_sum,odd_product,odd_average);}
#include <stdio.h>
#include <math.h>
#include<stdlib.h>
main ()
{
   FILE *inp,*outp1,*outp2;
   int  num, even_sum, odd_sum, even_product, odd_product, count_even=0, count_odd=0;
   double even_average, odd_average;

               inp=fopen("C:\\inp.dat","r");
               outp1=fopen("C:\\out1.txt","w");
               outp2=fopen("C:\\out2.txt","w");
if(inp==NULL)
   {
       printf("cannot open file");
       exit(1);
   }

even_sum=0;
even_product=1;
odd_sum=0;
odd_product=1;


for(fscanf(inp,"%d",num); num!=EOF; fscanf(inp, "%d", num));
   {
       if(num%2 ==0)
       {
       fprintf(outp1, "even=%d\n", num);
       even_sum +=num;
       even_product *=num;
       count_even++;
       }


       else
      {
           fprintf(outp2, "odd=%d\n", num);
           odd_sum +=num;
           odd_product *=num ;
           count_odd++;
       }

}

       even_average=(even_sum)/(count_even);
       odd_average=(odd_sum)/(count_odd);

       fprintf(outp1,"the sum=%d\n the product=%d\nand the average=lf",even_sum,even_product,even_average);
       fprintf(outp2,"the sum=%d\n the product=%d\n and the average=%lf",odd_sum,odd_product,odd_average);


}

Ugh! There's no way on earth anyone is going to even try to look at that code - try to format it properly. the very least you can do is not have it all on one continuous line.

Cross references: here and here (for those who weren't aware that other replies to this question exist already).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.