0% found this document useful (0 votes)
36 views

Simple C++ Programs

The document contains C++ code snippets for calculating geometric properties like area and circumference of basic shapes such as circles, rectangles, spheres, cubes, and triangles. Each code snippet accepts user input for dimensions, performs the relevant calculation formula and outputs the result. Formulas included are for area of circle, circumference of circle, area of rectangle, surface area and volume of sphere, surface area and volume of cube, average of numbers, Celsius to Fahrenheit conversion, distance between two points, and area of triangle.

Uploaded by

malvadearyan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Simple C++ Programs

The document contains C++ code snippets for calculating geometric properties like area and circumference of basic shapes such as circles, rectangles, spheres, cubes, and triangles. Each code snippet accepts user input for dimensions, performs the relevant calculation formula and outputs the result. Formulas included are for area of circle, circumference of circle, area of rectangle, surface area and volume of sphere, surface area and volume of cube, average of numbers, Celsius to Fahrenheit conversion, distance between two points, and area of triangle.

Uploaded by

malvadearyan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

//Area of a circle

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float r;
cout<<"Enter radius of a circle: ";
cin>>r;

float a = 3.14 * r * r;

cout<<"Area of circle = "<<a;


getch();

#include<iostream.h>
#include<conio.h>
//circumference of a circle
void main()
{
clrscr();

float r;

cout<<"Enter radius of a circle: ";


cin>>r;

float c = 2 * 3.14 * r;

cout<<"Circumference of circle = "<<c;

getch();
}
#include<iostream.h>
#include<conio.h>

//Area of rectangle

void main()
{
clrscr();

float l, b;

cout<<"Enter length and breadth of rectangle: ";


cin>>l>>b;

float area = l * b;

cout<<"Area of rectangle : "<<area;

getch();
}

#include<iostream.h>
#include<conio.h>

// surface area of sphere

void main()
{
clrscr();

float r;

cout<<"Enter radius of a sphere: ";


cin>>r;

float s = 4 * 3.14 * r * r;
cout<<"Surface area of sphere = "<<s;

getch();
}

#include<iostream.h>
#include<conio.h>

//volume of sphere

void main()
{
clrscr();

float r;

cout<<"Enter radius of sphere: ";


cin>>r;

float v = 4/3.0 * 3.14 * r * r * r;

cout<<"Volume of sphere : "<<v;

getch();
}

#include<iostream.h>
#include<conio.h>

//surface area of cube


void main()
{
clrscr();

float s;

cout<<"Enter value of side of cube : ";


cin>>s;

float sa = 6 * s * s;

cout<<"Surface area of cube : "<<sa;

getch();
}

#include<iostream.h>
#include<conio.h>

//volume of cube

void main()
{
clrscr();

float s;

cout<<"Enter side of cube: ";


cin>>s;

float v = s * s * s;

cout<<"Volume of cube = "<<v;


getch();
}

#include<iostream.h>
#include<conio.h>

//Average of three int numbers

void main()
{
clrscr();

int a, b, c;

cout<<"Enter any three int numbers: ";


cin>>a>>b>>c;

float avg = (a+b+c)/3.0; // float avg = (float)(a+b+c)/3;

cout<<"Average = "<<avg;

getch();
}

#include<iostream.h>
#include<conio.h>

//conversion Celsius to Fahrenheit

void main()
{
clrscr();

float c;

cout<<"Enter temperature in Celsius : ";


cin>>c;

float f = 1.8 * c + 32;

cout<<"Equivalent temperature in Fahrenheit = "<<f;

getch();
}

#include<iostream.h>
#include<conio.h>
#include<math.h>

//distance between two point

void main()
{
clrscr();

float x1, y1, x2, y2;

cout<<"Enter x-y co-ordinates of a first point : ";


cin>>x1>>y1;

cout<<"Enter x-y co-ordinates of a second point : ";


cin>>x2>>y2;
float d = sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) );
//float d = sqrt(pow(x2-x1,2) + pow(y2-y1,2));

cout<<"Distance between two point : "<<d;


getch();
}

#include<iostream.h>
#include<conio.h>
#include<math.h>

// Area of triangle when three sides are given

void main()
{
clrscr();

float a, b, c;

cout<<"Enter values three sides of triangle : ";


cin>>a>>b>>c;

float s = (a+b+c)/2;
float area = sqrt(s*(s-a)*(s-b)*(s-c));

cout<<"Area of triangle = "<<area;

getch();
}

You might also like