#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fpd,*fpe,*fpo;
int i;
clrscr();
// Entering the numbers
printf("\n\n Enter the number: \n");
// Opening the main file containing the numbers
fpd=fopen("Data.txt","w");
scanf("%d",&i);
while(i!=-1)
{
putw(i,fpd);
scanf("%d",&i);
}
fclose(fpd);
// Printing the numbers
fpd=fopen("Data.txt","r");
printf("\n\n");
while((i=getw(fpd))!=EOF)
{
printf("%d\t",i);
}
// Closing the main file
fclose(fpd);
// Opening data,even and odd files
fpd=fopen("Data.txt","r");
fpe=fopen("even.txt","w");
fpo=fopen("odd.txt","w");
// Separating even and odd numbers in odd and even files.
while((i=getw(fpd))!=EOF)
{
if(i%2==0)
putw(i,fpe);
else
putw(i,fpo);
}
fclose(fpd);
fclose(fpe);
fclose(fpo);
// Printing the even file.
fpe=fopen("even.txt","r");
printf("\n\n\n\n EVEN NUMBERS \n\n");
while((i=getw(fpe))!=EOF)
{
printf("%d\t",i);
}
// Printing the odd file.
fpo=fopen("odd.txt","r");
printf("\n\n\n\n ODD NUMBERS \n\n");
while((i=getw(fpo))!=EOF)
{
printf("%d\t",i);
}
getch();
}
#include<conio.h>
void main()
{
FILE *fpd,*fpe,*fpo;
int i;
clrscr();
// Entering the numbers
printf("\n\n Enter the number: \n");
// Opening the main file containing the numbers
fpd=fopen("Data.txt","w");
scanf("%d",&i);
while(i!=-1)
{
putw(i,fpd);
scanf("%d",&i);
}
fclose(fpd);
// Printing the numbers
fpd=fopen("Data.txt","r");
printf("\n\n");
while((i=getw(fpd))!=EOF)
{
printf("%d\t",i);
}
// Closing the main file
fclose(fpd);
// Opening data,even and odd files
fpd=fopen("Data.txt","r");
fpe=fopen("even.txt","w");
fpo=fopen("odd.txt","w");
// Separating even and odd numbers in odd and even files.
while((i=getw(fpd))!=EOF)
{
if(i%2==0)
putw(i,fpe);
else
putw(i,fpo);
}
fclose(fpd);
fclose(fpe);
fclose(fpo);
// Printing the even file.
fpe=fopen("even.txt","r");
printf("\n\n\n\n EVEN NUMBERS \n\n");
while((i=getw(fpe))!=EOF)
{
printf("%d\t",i);
}
// Printing the odd file.
fpo=fopen("odd.txt","r");
printf("\n\n\n\n ODD NUMBERS \n\n");
while((i=getw(fpo))!=EOF)
{
printf("%d\t",i);
}
getch();
}
No comments:
Post a Comment