المستند (8)
المستند (8)
المستند (8)
int main() {
int a, b;
cout << "Enter two numbers: ";
cin >> a >> b;
int sum = a + b;
cout << "Sum: " << sum << endl;
return 0;
}
Out put
Enter two numbers: 5 3
Sum: 8
#include <iostream>
using namespace std;
int main() {
int number;
cout << "Enter a number: ";
cin >> number;
if (number > 0) {
cout << "Positive number" << endl;
} else {
cout << "Non-positive number" << endl;
}
return 0;
}
Out put
Enter a number: 10
Positive number
Q3// programming to Counter to any number
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter a number: ";
cin >> n;
for (int i = 0; i <= n; i++) {
cout << i << " ";
}
cout << endl;
return 0;
}
Out put
Enter a number: 5
012345
Q4//calculator can user input any number
#include <iostream>
using namespace std;
int main() {
char op;
double num1, num2, result;
return 0;
}
Out put
Enter an operation (+, -, *, /): *
Enter first number: 5
Enter second number: 4
Product: 20
Q5//programing to Addition and Subtraction
#include <iostream>
using namespace std;
int main() {
char op;
double num1, num2, result;
cout << "Enter an operation (+ or -): ";
cin >> op;
cout << "Enter two numbers: ";
cin >> num1 >> num2;
if (op == '+') {
result = num1 + num2;
cout << "Sum: " << result << endl;
} else if (op == '-') {
result = num1 - num2;
cout << "Difference: " << result << endl;
} else {
cout << "Invalid operation. Please use only + or -." << endl;
}
return 0;
Out put
Enter an operation (+ or -): +
Enter two numbers: 10 5
Sum: 15
Q6//Pointer
#include <iostream>
using namespace std;
int main() {
int number;
cout << "Enter a number: ";
cin >> number;
int *ptr = &number;
cout << "Value at pointer: " << *ptr << endl;
return 0;
}
Out put
Enter a number: 10
Value at pointer: 10
Q7//password
#include <iostream>
#include <string>
using namespace std;
int main() {
string password = "12345”;
string inputPassword;
cout << "Enter password: ";
cin >> inputPassword;
if (inputPassword == password) {
cout << "Access granted! Welcome." << endl;
} else {
cout << "Access denied! Incorrect password." << endl;
}
return 0;
}
Out put
Enter password: 12345
Access granted! Welcome.
Q8// positive and negative
#include <iostream>
using namespace std;
int main() {
int number;
if (number > 0) {
cout << "The number is positive." << endl;
} else if (number < 0) {
cout << "The number is negative." << endl;
} else {
cout << "The number is zero." << endl;
}
return 0;}
Out put
Enter a number: 10
The number is positive.
Or
Enter a number: -5
The number is negative.
Q9//even and odd
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> evenNumbers;
vector<int> oddNumbers;
int number;
cout << "Enter numbers (-1 to exit):" << endl;
while (true) {
cin >> number;
if (number == -1) {
break;
}
if (number % 2 == 0) {
evenNumbers.push_back(number);
} else {
oddNumbers.push_back(number);
}
}
return 0;
}
Out put
Enter numbers (-1 to exit):
4
7
2
9
6
-1
Even numbers: 4 2 6
Odd numbers: 7
Q10// حساب مساحة االشكال الهندسية
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int choice;
double area, length, width, base, height, radius;
return 0;
}
Choose a shape to calculate its area:
1. Rectangle
2. Triangle
3. Circle
Enter your choice (1, 2, or 3): 2
Enter base of triangle: 5
Enter height of triangle: 3
Area of triangle: 7.5
Q11//program to find number )(العدد المتكرر
#include <iostream>
using namespace std;
int main() {
int numbers[] = {2, 5, 2, 8, 2, 4, 2};
int size = sizeof(numbers) / sizeof(numbers[0]);
int targetNumber = 2;
int occurrences = countOccurrences(numbers, size,
targetNumber);
cout << "Occurrences of " << targetNumber << ": " <<
occurrences << endl;
return 0;
}
Out put
Occurrences of 2: 4
Q12// برنامج تبديل القيم
#include <iostream>
using namespace std;
int main() {
int x = 5, y = 10;
cout << "Before swapping: x = " << x << ", y = " << y << endl;
swapValues(x, y);
cout << "After swapping: x = " << x << ", y = " << y << endl;
return 0;
}
Out put
Before swapping: x = 5, y = 10
After swapping: x = 10, y = 5
Q13//Square any number
#include <iostream>
using namespace std;
int main() {
int number;
cout << "Enter a number: ";
cin >> number;
int result = square(number);
cout << "Square: " << result << endl;
return 0;
}
Out put
Enter a number: 5
Square: 25
Q14//program to calaulate average arr
#include <iostream>
using namespace std;
int main() {
int numbers[] = {10, 20, 30, 40, 50};
int size = sizeof(numbers) / sizeof(numbers[0]);
double avg = calculateAverage(numbers, size);
cout << "Average: " << avg << endl;
return 0;
}
Out put
Average: 30
Q15//add two numbers
#include <iostream>
using namespace std;
int sum(int a, int b) {
return a + b;
}
int main() {
int x = 5, y = 3;
int result = sum(x, y);
cout << "Sum: " << result << endl;
return 0;}
Out put
Sum: 8
Q16//factorial
#include <iostream>
using namespace std;
int calculateFactorial(int n) {
int factorial = 1;
for (int i = 1; i <= n; ++i) {
factorial *= i;
}
return factorial;
}
int main() {
int number;
cout << "Factorial of " << number << " is " << result << endl;
return 0;
}
Enter a number to calculate its factorial: 5
Factorial of 5 is 120
Q17//تحويل من سليزي الى فرهن هايت
#include <iostream>
using namespace std;
fahrenheit = celsiusToFahrenheit(celsius);
return 0;
}
Out put
Enter temperature in Celsius: 25
Temperature in Fahrenheit: 77
Q18//برنامج الدخال ارقام عشوائيه الكن المستخدم هوا الذي يحدد فترة هذه االرقام
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int count, lower, upper;
cout << "Enter number of random numbers to generate: ";
cin >> count;
cout << "Enter lower bound: ";
cin >> lower;
cout << "Enter upper bound: ";
cin >> upper;
return 0;
}
Out put
Enter number of random numbers to generate: 5
Enter lower bound: 1
Enter upper bound: 100
Random numbers: 17 45 89 3 62
Q19//حساب مساحة المثلث
#include <iostream>
#include <cmath>
using namespace std;
double calculateTriangleArea(double base, double height) {
return 0.5 * base * height;{
int main() {
double base, height;
cout << "Enter base length of triangle: ";
cin >> base;
cout << "Enter height of triangle: ";
cin >> height;
double area = calculateTriangleArea(base, height);
cout << "Area of triangle: " << area << endl;
return 0;{
Out put
Enter base length of triangle: 5
Enter height of triangle: 8
Area of triangle: 20
int main() {
int numbers[] = {10, 20, 30, 40, 50};
int size = sizeof(numbers) / sizeof(numbers[0]);
cout << "Sum of array elements: " << totalSum << endl;
return 0;
}
Out put
Sum of array elements: 150
Q21//طباعة عناصر المصفوفه بالعكس
#include <iostream>
using namespace std;
int main() {
int size;
cout << "Enter the size of the array: ";
cin >> size;
int arr[size];
cout << "Enter " << size << " integers:\n";
for (int i = 0; i < size; ++i) {
cin >> arr[i];
}
return 0;
}
Out put
Enter the size of the array: 4
Enter 4 integers:
1234
Array elements in reverse order:
4321
Q22// إيجاد عنصر داخل المصفوفة
#include <iostream>
using namespace std;
int main() {
int size, target;
cout << "Enter the size of the array: ";
cin >> size;
int arr[size];
cout << "Enter " << size << " integers:\n";
for (int i = 0; i < size; ++i) {
cin >> arr[i];
}
if (found) {
cout << "Number " << target << " is found in the array.\n";
} else {
cout << "Number " << target << " is not found in the array.\n";
}
return 0;
}
Out put
Enter the size of the array: 5
Enter 5 integers:
10 20 30 40 50
Enter the number to search for: 30
Number 30 is found in the array.
Q23//إيجاد اكبر عنصر في المصفوفه
#include <iostream>
using namespace std;
int main() {
int size;
cout << "Enter the size of the array: ";
cin >> size;
int arr[size];
cout << "Enter " << size << " integers:\n";
for (int i = 0; i < size; ++i) {
cin >> arr[i];
}
int maxElement = arr[0];
cout << "Largest element in the array: " << maxElement << endl;
return 0;
}
Out put
Enter the size of the array: 4
Enter 4 integers:
15 7 22 10
Largest element in the array: 22
Q24//جمع عناصر الصفوف في المصفوفه
#include <iostream>
using namespace std;
int main() {
const int rows = 3;
const int cols = 3;
int matrix[rows][cols];
cout << "Enter elements of a " << rows << "x" << cols << "
matrix:\n";
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
cin >> matrix[i][j];
}
}
cout << "Sum of elements in each row:\n";
for (int i = 0; i < rows; ++i) {
int rowSum = 0;
for (int j = 0; j < cols; ++j) {
rowSum += matrix[i][j];
}
cout << "Row " << i + 1 << ": " << rowSum << endl;
}
return 0;
}
Out put
Enter elements of a 3x3 matrix:
123
456
789
Sum of elements in each row:
Row 1: 6
Row 2: 15
Row 3: 24
Q25//إيجاد القطر الرئيسي واستخراج االعداد الزوجيه والفرديه منه
#include <iostream>
using namespace std;
int main() {
int size;
cout << "Enter the size of the matrix (should be square): ";
cin >> size;
int matrix[size][size];
cout << "Enter " << size * size << " integers for the matrix:\n";
for (int i = 0; i < size; ++i) {
for (int j = 0; j < size; ++j) {
cin >> matrix[i][j];
}
}
return 0;
}
Out put
Enter the size of the matrix (should be square): 3
Enter 9 integers for the matrix:
123
456
789
Main diagonal elements: 1 5 9
Number of even elements in main diagonal: 2
Number of odd elements in main diagonal: 1
Q26// جمع عناصر كل صف
#include <iostream>
using namespace std;
int main() {
int rows, cols;
int matrix[rows][cols];
cout << "Enter " << (rows * cols) << " integers for the matrix:\n";
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
cin >> matrix[i][j];
}
}
return 0;
}
Out put
Enter the number of rows: 3
Enter the number of columns: 3
Enter 9 integers for the matrix:
123
456
789
Sum of elements in each row:
Row 1: 6
Row 2: 15
Row 3: 24
Q27// قلب المصفوفة
#include <iostream>
using namespace std;
int main() {
const int size = 3;
int matrix[size][size] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int invertedMatrix[size][size];
for (int i = 0; i < size; ++i) {
for (int j = 0; j < size; ++j) {
invertedMatrix[j][i] = matrix[i][j];
}
}
return 0;
}
Out put
Original Matrix:
123
456
789
Inverted Matrix:
147
258
369
Q28//جمع مصفوفتين
#include <iostream>
using namespace std;
int main() {
int rows1, cols1, rows2, cols2;
sumMatrix
for (int i = 0; i < rows1; ++i) {
for (int j = 0; j < cols1; ++j) {
sumMatrix[i][j] = matrix1[i][j] + matrix2[i][j];
}
}
return 0;
}
Out put
Enter dimensions of Matrix 1 (rows cols): 2 2
Enter dimensions of Matrix 2 (rows cols): 2 2
Enter elements of Matrix 1:
12
34
Enter elements of Matrix 2:
56
78
Resultant Matrix (Matrix1 + Matrix2):
68
10 12
Q29//ضرب مصفوفتين
#include <iostream>
using namespace std;
const int MAX_SIZE = 10; // تعريف أقصى حجم للمصفوفات
ضرب المصفوفتين//
for (int i = 0; i < rows1; ++i) {
for (int j = 0; j < cols2; ++j) {
result[i][j] = 0;
for (int k = 0; k < cols1; ++k) {
result[i][j] += mat1[i][k] * mat2[k][j];
}
}
}
}
int main() {
int rows1, cols1, rows2, cols2;
return 0;
}
Out put
Enter dimensions of Matrix 1 (rows cols): 2 3
Enter dimensions of Matrix 2 (rows cols): 3 2
Enter elements of Matrix 1:
123
456
Enter elements of Matrix 2:
78
9 10
11 12
Resultant Matrix (Matrix1 * Matrix2):
58 64
139 154
Q30// حل معادلةa=3d+c/2
#include <iostream>
using namespace std;
int main() {
int rows_a, cols_a, rows_d, cols_d, rows_c, cols_c;
return 0;
}
Out put
Enter dimensions of Matrix a (rows cols): 2 2
Enter dimensions of Matrix d (rows cols): 2 2
Enter dimensions of Matrix c (rows cols): 2 2
Enter elements of Matrix a:
12
34
Enter elements of Matrix d:
56
78
Enter elements of Matrix c:
9 10
11 12
Result Matrix a = 3d + c/2:
17 23
29 35
Q31//حساب اعداد
#include <iostream>
using namespace std;
int sumUpTo(int n) {
if (n == 0)
return 0;
else
return n + sumUpTo(n - 1);
}
int main() {
int number;
cout << "Enter a positive integer: ";
cin >> number;
cout << "Sum of numbers from 1 to " << number << " is: " <<
sumUpTo(number) << endl;
return 0;
}
Out put
Enter a positive integer: 5
Sum of numbers from 1 to 5 is: 15
Q31// قلب الكلمه
#include <iostream>
using namespace std;
int main() {
const char* message = "Hello, World!";
cout << "Original message: " << message << endl;
cout << "Reversed message: ";
reversePrint(message);
cout << endl;
return 0;
}
Out put
Original message: Hello, World!
Reversed message: !dlroW ,olleH
Q32//حساب تنازلي
#include <iostream>
using namespace std;
void countDown(int n) {
if (n < 0)
return;
cout << n << " ";
countDown(n - 1);
}
int main() {
int number;
cout << "Enter a positive integer: ";
cin >> number;
cout << "Counting down from " << number << ": ";
countDown(number);
cout << endl;
return 0;
}
Out put
Enter a positive integer: 5
Counting down from 5: 5 4 3 2 1 0
Q33//تحويل من ثنائي الى العشري
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
return decimal;
}
int main() {
string binaryNumber;
return 0;
}
Out put
Enter a binary number: 10101
Decimal equivalent: 21
Q34// //#write a program in c++ for calculating the time spent
#include <iostream>
using namespace std;
void time(double time, double distance)
{
double th, tm, AvrageSpeed = 60;
// the Avrage Speed of car is 60km/h
int t;
time = distance / AvrageSpeed;
// time in minute
t = time * 60;
//the hours
th = t / 60;
//the minute
tm = t % 60;
cout << "the time is: " << th << " hour and " << tm << " minute";
}
int main()
{
double t, d;
cout << "enter the distance(km): ";
cin >> d;
time(t, d);
}
Out put
Enter the distance (km): 120
Time taken to cover 120 km at an average speed of 60.0 km/h is: 2
hours and 0 minutes
Q34//عكس الرقم
#include <iostream>
#include <stdio.h>
int main(){
int x,i=0;
while(i<3){
cout<<"Enter your number: ";
cin>>x;
if(x>0 && x<=99999)
{
int a1= x % 10
,a2 = (x / 10)%10
,a3=(x / 100)%10
,a4=(x / 1000)%10
,a5=x / 10000;
cout<<a1<<a2<<a3<<a4<<a5<<endl;
}
else
cout<<"Error Try again\n";
}
return 0;
}
Out put
Enter your number: 12345
54321
Enter your number: 9876
6789
Enter your number: 456
654
Q35//
/Write a program in C++ to find the square of any //number using
the function.
#include <iostream>
#include <stdio.h>
cout<<"------------------------------------------------\n";
return 0;
}
Out put
Function: Find square of any number
------------------------------------
Input any number to find its square: 5
The square of 5 is: 25
Q36//
#include <iostream>
#include <string>
using namespace std;
int main() {
string text;
char target;
int count = 0;
int main() {
double number;
#include <iostream>
using namespace std;
int main() {
double num1, num2;
int main() {
int birthYear, currentYear;
cout << "Your age is: " << age << " years old." << endl;
return 0;
}
Out put
Enter your birth year: 1990
Your age is: 34 years old.
Q40//حساب االحرف في كلمه
#include <iostream>
#include <string>
using namespace std;
int main() {
string inputString;
cout << "Enter a string: ";
getline(cin, inputString);
return 0;
}
Out put
Enter a string: Hello World!
Number of characters: 12
Q41//تحويل الحروف الصغيره الى كبيره
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main() {
string inputString;
return 0;
}
Out put
Enter a string: Hello World
Convert to (U)pper or (L)ower case? U
Converted string: HELLO WORLD
Q41//جدول الضرب
#include <iostream>
using namespace std;
int main() {
int number;
cout << "Enter a number to display its multiplication table: ";
cin >> number;
return 0;
}
Out put
Enter a number to display its multiplication table: 7
Multiplication Table of 7:
7*1=7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35
7 * 6 = 42
7 * 7 = 49
7 * 8 = 56
7 * 9 = 63
7 * 10 = 70
Q42//برنامج لحساب فاتوره ناقص منها الخصم
#include <iostream>
using namespace std;
int main() {
double totalAmount, discountRate, finalAmount;
cout << "Final amount after discount: " << finalAmount << endl;
return 0;
}
Out put
Enter total amount: 100
Enter discount rate (%): 10
Final amount after discount: 90
Q43//حساب درجات والمعدل
#include <iostream>
using namespace std;
int main() {
int numSubjects;
cout << "Enter the number of subjects: ";
cin >> numSubjects;
double totalMarks = 0;
for (int i = 1; i <= numSubjects; ++i) {
double marks;
cout << "Enter marks for subject " << i << ": ";
cin >> marks;
totalMarks += marks;
}
return 0;
}
Out put
Enter the number of subjects: 4
Enter marks for subject 1: 85
Enter marks for subject 2: 78
Enter marks for subject 3: 92
Enter marks for subject 4: 80
Your average marks are: 83.75
Q44//تحقق اذا كان عدد اولي
#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter a number: ";
cin >> num;
if (isPrime(num)) {
cout << num << " is a prime number." << endl;
} else {
cout << num << " is not a prime number." << endl;
}
return 0;
}
Out put
Enter a number: 17
17 is a prime number.
Q45// تحقق اذا كانت سنه كبيسه أوال
#include <iostream>
using namespace std;
int main() {
int year;
cout << ";" :أدخل سنة
cin >> year;
if (isLeapYear(year)) {
cout << year << " << ".هي سنة كبيسةendl;
} else {
cout << year << " << ".ليست سنة كبيسةendl;
}
return 0;
}
Out put
2024 :أدخل سنة
. هي سنة كبيسة2024
Q45//برنامج لحساب اعداد اوليه ضمن نطاق محدد
#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int num) {
if (num <= 1) return false;
if (num <= 3) return true;
if (num % 2 == 0 || num % 3 == 0) return false;
for (int i = 5; i * i <= num; i += 6) {
if (num % i == 0 || num % (i + 2) == 0) return false;
}
return true;
}
int main() {
int start, end;
cout << " << "[ األعداد األولية في النطاقstart << ", " << end << "]
<< ":هيendl;
for (int i = start; i <= end; ++i) {
if (isPrime(i)) {
cout << i << " ";
}
}
cout << endl;
return 0;
}
Out put
10 :أدخل الحد األدنى للنطاق
30 :أدخل الحد األعلى للنطاق
:] هي30 ,10[ األعداد األولية في النطاق
11 13 17 19 23 29
Q46// تحويل العدد الثنائي الى ثماني
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
base = 1;
تحويل العدد العشري إلى عدد ثماني//
while (decimal != 0) {
octal += (decimal % 8) * base;
decimal /= 8;
base *= 10;
}
return octal;
}
int main() {
string binary;
return hexadecimal;
}
int main() {
string binary;
return 0;
}
Out put
110110 :أدخل عددًا ثنائيًا
36 :العدد السداسي عشر المعادل هو
Q48// تحويل العدد العشري الى أي نظام يريده المستخدم
#include <iostream>
#include <string>
#include <stack>
using namespace std;
;return result
}
{ )(int main
;int decimalNumber, base
{ )(int main
;int height
;endlهيheight << " << ":السلسلة النجمية بارتفاع " << " << cout
;)printStars(height
;return 0
}
Out put
أدخل ارتفاع السلسلة النجمية4 :
السلسلة النجمية بارتفاع 4هي:
*
**
***
****
Q50//متسلسلة بنا ًء على التسلسل الفيبوناتشي
#include <iostream>
using namespace std;
int fibonacciSum(int n) {
if (n <= 0) return 0;
if (n == 1) return 1;
int a = 0, b = 1, sum = 1;
for (int i = 2; i <= n; ++i) {
int next = a + b;
sum += next;
a = b;
b = next;
}
return sum;
}
int main() {
int number;
return 0;
}
Out put
5 :أدخل عدد لحساب مجموع سلسلة فيبوناتشي
12 : هو5 مجموع أعداد سلسلة فيبوناتشي حتى العدد