0% found this document useful (0 votes)
15 views4 pages

Day 1

Uploaded by

Vab
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)
15 views4 pages

Day 1

Uploaded by

Vab
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
You are on page 1/ 4

Que: Program to Find Largest Number Among Three Numbers

#include <iostream>

using namespace std;

int main() {

int num1, num2, num3;

// Input three numbers from the user

cout << "Enter three numbers: ";

cin >> num1 >> num2 >> num3;

// Compare the numbers

if (num1 >= num2 && num1 >= num3) {

cout << "The largest number is: " << num1 << endl;

else if (num2 >= num1 && num2 >= num3) {

cout << "The largest number is: " << num2 << endl;

else {

cout << "The largest number is: " << num3 << endl;

return 0;

Que: Program to Calculate Sum of Natural Numbers

#include <iostream>

using namespace std;


int main() {

int n, sum = 0;

// Input the number from the user

cout << "Enter a positive integer: ";

cin >> n;

// Calculate the sum of natural numbers

for (int i = 1; i <= n; ++i) {

sum += i;

// Display the result

cout << "The sum of natural numbers up to " << n << " is: " << sum << endl;

return 0;

Que 3: Program to Check Whether a Number is Prime or Not

#include <iostream>

using namespace std;

int main() {

int n, i;

// Input a number from the user

cout << "Enter a positive integer: ";

cin >> n;
// Assume n is prime unless we find a divisor

for (i = 2; i < n; ++i) {

if (n % i == 0) {

break;

// If loop completes without finding a divisor, n is prime

if (i == n && n > 1)

cout << n << " is a prime number." << endl;

else

cout << n << " is not a prime number." << endl;

return 0;

Que 4: Program to Display Fibonacci Series

#include <iostream>

using namespace std;

int main() {

int n, t1 = 0, t2 = 1, nextTerm;

// Input the number of terms from the user

cout << "Enter the number of terms: ";

cin >> n;

cout << "Fibonacci Series: ";


for (int i = 1; i <= n; ++i) {

cout << t1 << " "; // Print the current term

nextTerm = t1 + t2; // Calculate the next term

t1 = t2; // Update t1

t2 = nextTerm; // Update t2

return 0;

You might also like