Write a
program to create num.txt file which stores number. Find max value from a file nums.txt and print it on standard output device.
|
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
void
main()
{
int no,no1;
ofstream of1("num.txt");
for(int i=0;i<10;i++)
{
cout<<"\n Enter number";
cin>>no;
of1<<no<<endl;
}
of1.close();
cout<<"\n Read data
from file\n";
ifstream if1("num.txt");
int max=0;
for(int i=0;i<10;i++)
{
if1>>no1;
cout<<"\n
Data"<<i<<" "<<no1;
if(max<no1)
{
max=no1;
}
}
cout<<"\n Maximum no
is: "<<max;
if1.close();
}
|
File Program 6
Subscribe to:
Posts (Atom)