File Handling Example In C++
Write a C++ Program that computes the equation (y) to the power of (x) and print the result on file.
//Before creating this program. Create a txt file on note pad with "powerX.txt" name.
#include<fstream.h>
void main ()
{
int number,power,result=1;
ofstream powers;
powers.open("powerX.txt");
cout<<"Enter Numbers:";
cin>>number;
cout<<"Enter Power:";
cin>>power;
for(int i=1; i<=power; i++)
{
result=number*result;
}
powers<<"Number:"<<number<<"\nPower:"<<power<<endl;
powers<<"Result:"<<result;
}
OUT PUT On FILE
0 comments: