Program 1
Program 1
#include <iostream>
using namespace std;
int main() {
int x = 25;
int y = 13;
cout << "Total of x + y = " << (x + y) << endl;
}
Output
Program2
Q2 Write a program to find if a number is even or add
Program3
Q4 Write a program to find greatest among 3 number
#include <iostream>
using namespace std;
int main() {
else
cout << "Largest number: " << n3;
return 0;
Program4
if (n == 0 || n == 1) {
is_prime = false;
} else {
for (i = 2; i <= sqrt(n); ++i) {
if (n % i == 0) {
is_prime = false;
break;
}
}
}
if (is_prime)
cout << n << " is a prime number";
else
cout << n << " is not a prime number";
return 0;
}
Program5
Q5 Write a program to find the smallest among three number
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a = 5, b = 7, c = 10;
else
cout << c << " is the smallest";
return 0;
}
Program6
Q6 program to calculate the division of a student occording to mark obtained in
4 subject
#include <iostream>
using namespace std;
int main() {
float subject1, subject2, subject3, subject4, average
cout << "Enter the marks obtained in subject 1: ";
cin >> subject1;
cout << "Enter the marks obtained in subject 2: ";
cin >> subject2;
cout << "Enter the marks obtained in subject 3: ";
cin >> subject3;
cout << "Enter the marks obtained in subject 4: ";
cin >> subject4;
average = (subject1 + subject2 + subject3 + subject4) / 4;
cout << "The average marks are: " << average << endl;
if (average >= 60) {
cout << "First Division" << endl;
} else if (average >= 50) {
cout << "Second Division" << endl;
} else if (average >= 35) {
cout << "Third Division" << endl;
} else {
cout << "Fail" << endl;
}
return 0;
input
Program7
Write a program to display even number between 1 and 15 (while loop )
#include <iostream>
int main() {
int num = 2;
return 0;
}
program 8
Q8 writ a program to multiplication table of a given number
#include <iostream>
int main() {
int number;
Input
Program 9
Q9 Write a program to calculate the average of n number
#include <iostream>
using namespace std;
int main() {
int n;
double sum = 0.0;
cout << "The average of the entered numbers is: " << average << endl;
return 0;
}
Program 10
Q10 write a program to display fibonaci series of n number
using for loop
#include <iostream>
using namespace std;
int main() {
int n, t1 = 0, t2 = 1, nextTerm;
return 0;
}
Q11. Write a program to show pass by address work?
#include <iostream>
void increment(int *ptr);
int main() {
int num = 5;
increment(&num);
return 0;
}
int main() {
int originalNum = 10;
std::cout << "Before calling passByValue, originalNum: " << originalNum << std::endl;
return 0;
}
int main()
{
float radius = 3.5;
float length = 4.2, breadth = 2.8;
int base = 5, height = 8;
std::cout << "Area of circle with radius " << radius << " is: " << area(radius) <<
std::endl;
std::cout << "Area of rectangle with length " << length << " and breadth " <<
breadth << " is: "
<< area(length, breadth) << std::endl;
std::cout << "Area of triangle with base " << base << " and height " << height
<< " is: "
<< area(base, height) << std::endl;
return 0;
}
int main() {
int rows, cols;
int array[rows][cols];
std::cout << "Enter the elements of the array:" << std::endl;
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
std::cout << "Element [" << i << "][" << j << "]: ";
std::cin >> array[i][j];
}
}
std::cout << "The elements of the array are:" << std::endl;
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
std::cout << array[i][j] << " ";
}
std::cout << std::endl;
}
return 0;
}
int main() {
int rows1, cols1, rows2, cols2;
void input() {
std::cout << "Enter student name: ";
std::cin.ignore();
std::getline(std::cin, name);
std::cout << "Enter student age: ";
std::cin >> age;
std::cout << "Enter student ID: ";
std::cin >> id;
}
void display() const {
std::cout << "Student Name: " << name << std::endl;
std::cout << "Student Age: " << age << std::endl;
std::cout << "Student ID: " << id << std::endl;
}
};
int main() {
Student student;
student.input();
student.display();
return 0;
}
Q 18. write a program to display the address and the content of a pointer ?
#include <iostream>
int main() {
int num = 42;
int* ptr = #
std::cout << "The address stored in the pointer: " << ptr << std::endl;
std::cout << "The content of the pointer (value pointed to): " << *ptr <<
std::endl;
std::cout << "The address of the pointer itself: " << &ptr << std::endl;
return 0;
}
int main() {
int x, y;
std::cout << "Enter the first integer: ";
std::cin >> x;
std::cout << "Enter the second integer: ";
std::cin >> y;
swap(x, y);
return 0;
}
Q.20 write a program to find the number is palindrome ?
#include <iostream>
int main() {
int x, y;
swap(x, y);
return 0;
}