A file name DATA contains a series of integer numbers. Code a program to read these numbers and then write all ‘odd’ numbers to a file to be called ODD and all ‘even’ numbers to a file called EVEN.
#include<stdio.h>
#include<STDLIB.H>
main()
{
FILE *f1,*f2,*f3;
char c[1];
int x;
f1=fopen("data.txt","r");
f2=fopen("odd.txt","w");
f3=fopen("even.txt","w");
while((c[0]=getc(f1)) != EOF)
{
x = atoi(c);
if(x%2==0)
putc(c[0],f3);
else
putc(c[0],f2);
}
fclose(f1);
fclose(f2);
fclose(f3);
}
#include<STDLIB.H>
main()
{
FILE *f1,*f2,*f3;
char c[1];
int x;
f1=fopen("data.txt","r");
f2=fopen("odd.txt","w");
f3=fopen("even.txt","w");
while((c[0]=getc(f1)) != EOF)
{
x = atoi(c);
if(x%2==0)
putc(c[0],f3);
else
putc(c[0],f2);
}
fclose(f1);
fclose(f2);
fclose(f3);
}