0% found this document useful (0 votes)
19 views9 pages

PF Lab1

The document contains multiple programming examples in C++ demonstrating the use of arithmetic, assignment, relational, and logical operators. Each program illustrates basic operations such as addition, subtraction, multiplication, division, and conditional checks. The examples are structured to guide the reader through fundamental programming concepts and their applications.
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)
19 views9 pages

PF Lab1

The document contains multiple programming examples in C++ demonstrating the use of arithmetic, assignment, relational, and logical operators. Each program illustrates basic operations such as addition, subtraction, multiplication, division, and conditional checks. The examples are structured to guide the reader through fundamental programming concepts and their applications.
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

NAME: Ghulam Mohi ud din

ROLL NUM: F2024105031


SECTION: Y7

PROGRAMMING
FUNDAMENTALS LAB

 ARITHEMATIC OPERATOR

PROGRAM#1

#include <iostream>
using namespace std;

int main() {
int num1, num2;

cout << "Enter first number: ";


cin >> num1;
cout << "Enter second number: ";
cin >> num2;

int sum = num1 + num2;


int difference = num1 - num2;
int product = num1 * num2;
double quotient = (double)num1 / num2;

cout << "Addition: " << num1 << " + " << num2 << " = "
<< sum << endl;
cout << "Subtraction: " << num1 << " - " << num2 << " = "
<< difference << endl;
cout << "Multiplication: " << num1 << " * " << num2 << "
= " << product << endl;
cout << "Division: " << num1 << " /" << num2 << " = " <<
quotient << endl;

return 0;
}
PROGRAM#2

#include <iostream>
using namespace std;

int main()
{
int num;
cout << "Enter a number: ";
cin >> num;

int square = num * num;


int cube = num*num*num;

cout << "Square: " << num << " * " << num << " = " << square
<< endl;
cout << "Cube: " << num << " * " << num << " * " << num << "
= " << cube << endl;

return 0;
}
PROGRAM#3

#include <iostream>
using namespace std;

int main()
{

double num1, num2, num3;


double average;

cout << "Enter first number: ";


cin >> num1;
cout << "Enter second number: ";
cin >> num2;
cout << "Enter third number: ";
cin >> num3;

average = (num1 + num2 + num3) / 3.0;

cout << "The average is "<< average << endl;

return 0;
}
 Assignment Operator
PROGRAM#1

#include <iostream>
using namespace std;

int main() {
int num = 10;
cout << "Value: " << num << endl;

num += 6;
cout << "After adding 6: " << num << endl;

num -= 4;
cout << "After subtracting 4: " << num << endl;

num *= 12;
cout << "After multiplying by 12: " << num << endl;

num /= 3;
cout << "After dividing by 3: " << num << endl;

return 0;
}
 Relational Operator
PROGRAM#1

#include <iostream>
using namespace std;

int main()
{
int num;

cout << "Enter a number: ";


cin >> num;

if (num > 0) {
cout << num << " is a positive number" << endl;
} else {
cout << num << " is not a negqtive number" << endl;
}

return 0;
}

PROGRAM#2

#include <iostream>
using namespace std;

int main()
{
int x, y;

cout << "Enter first num: ";


cin >> x;
cout << "Enter second num: ";
cin >> y;

if (x == y) {
cout << "Both numbers are equal" << endl;
} else {
cout << "Both numbers are not equal" << endl;
}

return 0;
}

 Logical operator
PROGRAM#1

#include <iostream>
using namespace std;

int main()
{
int num;

cout << "Enter a number: ";


cin >> num;

if (num % 3 == 0 && num % 5 == 0) {


cout << num << " is divisible " << endl;
} else {
cout << num << " is not divisible " << endl;
}

return 0;
}

PROGRAM#2

#include <iostream>
using namespace std;
int main() {
int num;

cout << "Enter a number: ";


cin >> num;

if (num > 0 || num > 17) {


cout << num << " is either positive or greater than 17"
<< endl;
} else {
cout << num << " is neither positive nor greater than
17" << endl;
}

return 0;
}

You might also like