/*NAME:- KHAN SADEEM NAVED
ROLL NO:- 2416125
BRANCH:- EXTC
Year:- S.E
BATCH:- A*/
Program 1:- Check if a number is positive, negative, or zero
Input:
#include <iostream> using namespace std;
int main() {
int a;
cout << "Enter an integer: "; cin >> a;
if (a > 0) {
cout << "The number is positive." << endl;
} else if (a < 0) {
cout << "The number is negative." << endl;
} else {
cout << "The number is zero." << endl;
}
Return 0; }
Output:
Program 2 :
Generate Multiplication Table of a Number:
Input:
#include <iostream> using namespace std;
int main() { int a, result; cout << "Enter a Number to
Generate Multiplication Table: "; cin >> a; cout <<
"Multiplication Table of " << a << " is:" << endl;
for (int i = 1; i <= 10; i++) { result = a * i; cout << a << " x "
<< i << " = " << result << endl;
}
return 0;
}
Output:
Program 3:
Simple Calculator Using Switch Case Input:
#include <iostream> using namespace std;
int main() { int a, b, choice;
cout << "Calculator Program" << endl;
cout << "Enter first number: "; cin >> a;
cout << "Enter second number: "; cin >> b;
cout << "Choose an operation:\n"; cout << "1.
Addition\n"; cout << "2. Subtraction\n"; cout << "3.
Multiplication\n"; cout << "4. Division\n";
cout << "Enter your choice (1-4): "; cin >> choice;
switch (choice) { case 1:
cout << "Result: " << a + b << endl; break;
case 2: cout << "Result: " << a - b << endl;
break; case 3: cout << "Result: " << a * b <<
endl; break; case 4:
if (b != 0) { cout << "Result: " <<
static_cast<double>(a) / b << endl;
} else { cout << "Error: Division by zero is not allowed." << endl; }
break; default:
cout << "Invalid choice. Please select a valid operation." << endl;
}
return 0;
}
Output:
Program 4 :
Print Numbers from 1 to 10 using while loop Input:
#include <iostream> using namespace std;
int main() { int i = 1;
cout << "Numbers from 1 to 10:" << endl;
while (i <= 10) { cout << i << endl; i++;
}
return 0;
}
Output:
Program 5:
Find sum of first n natural numbers using do while loop:
Input:
#include <iostream> using namespace std;
int main() { int n,
sum = 0, i = 1;
cout << "Enter a positive integer: "; cin >> n;
do { sum += i; i++;
} while (i <= n);
cout << "The sum of the first " << n << " natural numbers
is: " << sum << endl;
return 0;
}
Output:
Program 6:
Demonstrate the use of break and continue statements Input:
#include <iostream>
using namespace std; int
main() {
// Demonstrating 'continue' cout << "Using
continue to skip even numbers:\n"; for (int i
=1; i <= 10; ++i)
{ if (i % 2 == 0)
{ continue;
} cout << i << " ";
}
cout << "\n\nUsing break to stop loop when
number is 5:\n"; // Demonstrating 'break'
for (int i = 1; i <= 10; ++i)
{ if (i == 5) {
break; } cout <<
i << " "; } return 0;
}
Output: