Programming Using C++ MANUAL
Programming Using C++ MANUAL
Part A
1) Program to find the area of Circle and Triangle
#include <iostream>
using namespace std;
int main() {
double r, area;
#include <iostream>
using namespace std;
int main() {
double b, h, area;
// Prompt the user to enter the base and height of the triangle
cout << "Enter the base of the triangle: ";
cin >> b;
PARTA-1
PROGRAMMING USING C++ LAB MANUAL
2) Program to find the largest and second largest among 3 numbers
#include <iostream>
using namespace std;
int main() {
int n1, n2, n3;
int largest, secondLargest;
return 0;
}
PARTA-2
PROGRAMMING USING C++ LAB MANUAL
3) Program to classify triangles based on the length of sides
#include <iostream>
using namespace std;
int main() {
int a, b, c;
// Prompt the user to enter the lengths of the sides of the triangle
cout << "Enter the length of the first side (a): ";
cin >> a;
cout << "Enter the length of the second side (b): ";
cin >> b;
cout << "Enter the length of the third side (c): ";
cin >> c;
return 0;
}
Enter the length of the first side (a): 5
Enter the length of the second side (b): 5
Enter the length of the third side (c): 5
The triangle is equilateral.
PARTA-3
PROGRAMMING USING C++ LAB MANUAL
4) Program to generate all prime numbers between M and N using function
#include <iostream>
using namespace std;
int main() {
int M, N;
return 0;
}
Enter the starting number M: 10
Enter the ending number N: 20
Prime numbers between 10 and 30 are: 11 13 17 19
PARTA-4
PROGRAMMING USING C++ LAB MANUAL
5) Program to find the sum of digits of a numbers and check whether it is
palindrome or not
#include <iostream>
using namespace std;
int main() {
int num, originalNum, sumOfDigits = 0, reversedNum = 0, remainder;
originalNum = num;
return 0;
}
PARTA-5
PROGRAMMING USING C++ LAB MANUAL
6) Program to generate the following pattern
a)
1
1 2
1 2 3
b)
#include <iostream>
using namespace std;
int main() {
int rows = 3; // Number of rows in the pattern
return 0;
}
1
12
123
PARTA-6
PROGRAMMING USING C++ LAB MANUAL
#include <iostream>
using namespace std;
int main() {
int n = 6; // Number of rows for the pattern
return 0;
}
*
**
***
****
** ***
******
PARTA-7
PROGRAMMING USING C++ LAB MANUAL
7) Program to solve a given quadratic equation using switch statement
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double a, b, c;
double disc, x1, x2, rp, ip;
PARTA-8
PROGRAMMING USING C++ LAB MANUAL
PARTA-9
PROGRAMMING USING C++ LAB MANUAL
8) Program to sum of all elements in an array
#include <iostream>
using namespace std;
int main() {
int n;
int sum = 0;
return 0;
}
PARTA-10
PROGRAMMING USING C++ LAB MANUAL
9) Program to search an element in an array
#include <iostream>
using namespace std;
int main() {
int a[10];
int n, key, found = -1;
return 0;
}
PARTA-11
PROGRAMMING USING C++ LAB MANUAL
Element is present in the array at index 2
PARTA-12
PROGRAMMING USING C++ LAB MANUAL
10) Program to find the sum of 2 matrices
#include <iostream>
using namespace std;
int main() {
int r, c;
PARTA-13
PROGRAMMING USING C++ LAB MANUAL
Enter the number of rows: 2
Enter the number of columns: 2
Enter elements of the first matrix:
12
34
Enter elements of the second matrix:
56
78
Sum of the two matrices is:
68
10 12
PARTA-14
PROGRAMMING USING C++ LAB MANUAL
11) Program to find the simple interest with default argument
#include <iostream>
using namespace std;
int main() {
float p, r;
int t;
double interest;
return 0;
}
PARTA-15
PROGRAMMING USING C++ LAB MANUAL
12) Program to check whether a given number is prime or not using friend
function
#include <iostream>
using namespace std;
class Number {
private:
int num;
public:
// Constructor to initialize the number
Number(int n) : num(n) {}
int main() {
int num;
cout << "Enter a number to check if it's prime: ";
cin >> num;
Number number(num);
if (isPrime(number)) {
cout << num << " is a prime number." << endl;
} else {
cout << num << " is not a prime number." << endl;
}
return 0;
}
PARTA-16
PROGRAMMING USING C++ LAB MANUAL
Enter a number to check if it's prime: 29
29 is a prime number.
PARTA-17
PROGRAMMING USING C++ LAB MANUAL
13) Program to check whether a given number is even or odd using inline
function
#include <iostream>
using namespace std;
int main() {
int num;
return 0;
}
Enter a number: 8
8 is an even number.
Enter a number: 15
15 is an odd number.
PARTA-18