Skip to content

Instantly share code, notes, and snippets.

@starhopp3r
Created February 12, 2019 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starhopp3r/a129e770dd89e589b8e2900bd79f91f9 to your computer and use it in GitHub Desktop.
Save starhopp3r/a129e770dd89e589b8e2900bd79f91f9 to your computer and use it in GitHub Desktop.
// C++ Program to compute the area of a circle
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
// Variables to hold the radius and area
float radius, area;
// Open file
ofstream file;
file.open("result.txt", ofstream::out | ofstream::app);
// Get the radius of the circle from the user
cout << "Enter the radius of the circle: ";
cin >> radius;
// Calculate the area of the cirlce
area = 3.14 * radius * radius;
// Output
cout << "Area of circle with radius " << radius << " is " << area << endl;
file << "Area of circle with radius " << radius << " is " << area << endl;
// Close the file
file.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment