0% found this document useful (0 votes)
7 views10 pages

OODP Week 1 Programs

The document contains a series of C++ programs demonstrating various programming concepts, including the use of mathematical constants, input/output formatting, area calculation of a triangle, multiplication tables, distance calculation between geographical points, and fraction addition. Each program is followed by its expected output. The programs serve as practice exercises for students learning C++ programming.

Uploaded by

poke.cool1000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views10 pages

OODP Week 1 Programs

The document contains a series of C++ programs demonstrating various programming concepts, including the use of mathematical constants, input/output formatting, area calculation of a triangle, multiplication tables, distance calculation between geographical points, and fraction addition. Each program is followed by its expected output. The programs serve as practice exercises for students learning C++ programming.

Uploaded by

poke.cool1000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

21CSC101T Practice Program

Week – 1
-Pranshu Bharti
RA2311033010104
CINTEL AK – 1
PROGRAM 1:
#include <iostream>

#include <iomanip>

using namespace std;

int main ()

const float pi = 3.1416;

cout << setprecision(5) << "The value of pi : " << pi << endl;

cout << "The value of pi 4 decimal place of total width 8 :|" << setw(8) << pi << "|" << endl;

cout << "The value of pi 4 decimal place of total width 10 :|" << setw(10) << pi << "|" << endl;

cout << "The value of pi 4 decimal place of total width 8 :|" << setfill('-') << setw(8) << pi << "|" << endl;

cout << "The value of pi 4 decimal place of total width 10 :|" << setfill('-') << setw(10)<< pi << "|" << endl;

cout << "The value of pi in scientific format is : " << scientific << pi << endl;

cout << "Status in number : " << isdigit(pi) << endl;

cout << "Status in alphabet : " << (isalpha(pi) ? "true" : "false") << endl;

return 0;

OUTPUT:
Program 2:
#include <iostream>

#include <cmath>

using namespace std;

int main()

float s1, s2, s3, s, area;

cout << "Input the length of 1st side of the triangle : ";

cin >> s1;

cout << "Input the length of 2nd side of the triangle : ";

cin >> s2;

cout << "Input the length of 3rd side of the triangle : ";

cin >> s3;

s = (s1+s2+s3)/2;

area = pow((s*(s-s1)*(s-s2)*(s-s3)), 0.5);

cout << "The area of the triangle is : " << area << endl;

return 0;

OUTPUT:
PROGRAM 3:

#include <iostream>
using namespace std;
int main() {
int n, i = 6, j = 4;
cin >> n;
while (i--) {
while (j--) {
if (i == 5 || i == 0 || j == 3 || j == 0) cout << n;
else cout << " ";
}
cout << endl;
j = 4;
}
return 0;
}

OUTPUT:
PROGRAM 4:
#include <iostream>

using namespace std;

int main()

int x;

cout<<"Input a Number: ";

cin>>x;

for (int i=0 ; i<=10 ; i++)

cout<<x<<" x "<<i<<" = "<<x*i<<endl;

return 0;

OUTPUT:
PROGRAM 5:

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double dis, la1, la2, lo1, lo2, e, r;
cout << "Print the distance between two points on the
surface of earth:";
cout << "----------------------------------------------------------"<<endl;
cout << " Input the latitude of coordinate 1: ";
cin >> la1;
cout << " Input the longitude of coordinate 1: ";
cin >> lo1;
cout << " Input the latitude of coordinate 2: ";
cin >> la2;
cout << " Input the longitude of coordinate 2: ";
cin >> lo2;
r = 0.01745327;
la1 = la1 * r;
la2 = la2 * r;
lo1 = lo1 * r;
lo2 = lo2 * r;
e = 6371.01;
dis= e*acos((sin(la1)*sin(la2))+(cos(la1)*cos(la2)*cos(lo1-
lo2)));
cout <<"The distance between those points is:
"<<dis<<endl;
return 0;
}

OUTPUT:

PROGRAM 6:

#include <iostream>
using namespace std;
int main() {
long int n1, n2, sum, p = 0;
cin >> n1 >> n2;
sum = n1 + n2;
while(sum) {
sum /= 10;
p++;
}
cout << p << endl;
return 0;
}

OUTPUT:

PROGRAM 7:
#include <iostream>

#include <iomanip>

using namespace std;

int main() {

int n1;

long n2;

char n3;

float n4;

double n5;

cin >> n1 >> n2 >> n3 >> n4 >> n5;

cout << n1 << " ";

cout << n2 << " ";

cout << n3 << " ";

cout << fixed << setprecision(3) << n4 << " ";

cout << setprecision(9) << n5 << endl;

return 0;
}

OUTPUT:

PROGRAM 8:
#include <iostream>
using namespace std;
int main() {
float deg_c, deg_f;
cin >> deg_c;
deg_f = deg_c * 9 / 5 + 32;
cout << deg_f << endl;
return 0;
}
OUTPUT:

PROGRAM 9:
#include <iostream>

using namespace std;

int main() {

int n1, n2, d1, d2;


char divide;

cout << "Enter first fraction: ";

cin >> n1 >> divide >> d1;

cout << "Enter second fraction: ";

cin >> n2 >> divide >> d2;

cout << "Sum = " << (n1*d2+n2*d1) << "/" << (d1*d2) << endl;

return 0;

OUTPUT:

PROGRAM 10:
#include <iostream>

#include <iomanip>

using namespace std;

int main() {

cout << setw(15) << left << 0.123456 << endl;

cout << setw(12) << right << fixed << setprecision(2) << 23.987 << endl;

cout << setw(10) << scientific << setprecision(4) << -123.456 << endl;

return 0;

OUTPUT:

You might also like