KEMBAR78
Simple Programs Set2 | PDF | Namespace | C++
0% found this document useful (0 votes)
3 views2 pages

Simple Programs Set2

The document contains a series of C++ programs demonstrating basic mathematical calculations and concepts, including simple interest, area calculations for circles and rectangles, temperature conversion, leap year checking, number classification, multiplication tables, summation of natural numbers, digit counting, and exponentiation. Each program is accompanied by its expected output. The examples illustrate fundamental programming techniques and mathematical principles.

Uploaded by

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

Simple Programs Set2

The document contains a series of C++ programs demonstrating basic mathematical calculations and concepts, including simple interest, area calculations for circles and rectangles, temperature conversion, leap year checking, number classification, multiplication tables, summation of natural numbers, digit counting, and exponentiation. Each program is accompanied by its expected output. The examples illustrate fundamental programming techniques and mathematical principles.

Uploaded by

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

11) Simple Interest

#include <iostream>
using namespace std;
int main() {
float p = 1000, r = 5, t = 2;
float si = (p * r * t) / 100;
cout << "Simple Interest = " << si;
return 0;
}
Output: Simple Interest = 100

12) Area of Circle


#include <iostream>
using namespace std;
int main() {
float r = 7;
float area = 3.14 * r * r;
cout << "Area = " << area;
return 0;
}
Output: Area = 153.86

13) Area of Rectangle


#include <iostream>
using namespace std;
int main() {
int l = 10, b = 5;
cout << "Area = " << (l * b);
return 0;
}
Output: Area = 50

14) Celsius to Fahrenheit


#include <iostream>
using namespace std;
int main() {
float c = 25;
float f = (c * 9/5) + 32;
cout << "Fahrenheit = " << f;
return 0;
}
Output: Fahrenheit = 77

15) Check Leap Year


#include <iostream>
using namespace std;
int main() {
int year = 2024;
if((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
cout << "Leap Year";
else
cout << "Not Leap Year";
return 0;
}
Output: Leap Year

16) Positive or Negative


#include <iostream>
using namespace std;
int main() {
int n = -10;
if(n > 0)
cout << "Positive";
else if(n < 0)
cout << "Negative";
else
cout << "Zero";
return 0;
}
Output: Negative

17) Multiplication Table


#include <iostream>
using namespace std;
int main() {
int n = 5;
for(int i = 1; i <= 10; i++)
cout << n << " * " << i << " = " << n*i << "\n";
return 0;
}
Output: 5 * 1 = 5 ... 5 * 10 = 50

18) Sum of Natural Numbers


#include <iostream>
using namespace std;
int main() {
int n = 10, sum = 0;
for(int i = 1; i <= n; i++)
sum += i;
cout << "Sum = " << sum;
return 0;
}
Output: Sum = 55

19) Count Digits


#include <iostream>
using namespace std;
int main() {
int n = 12345, count = 0;
while(n != 0) {
count++;
n /= 10;
}
cout << "Digits = " << count;
return 0;
}
Output: Digits = 5

20) Power of a Number


#include <iostream>
#include <cmath>
using namespace std;
int main() {
int base = 2, exp = 3;
cout << "Power = " << pow(base, exp);
return 0;
}
Output: Power = 8

You might also like