0% found this document useful (0 votes)
1 views

LAB Copy

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

LAB Copy

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 38

Experiment 1: Conditional Statement and Switch Case

1. Write a program that takes three integers as input and determines the largest among them using nested if-
else statements.
2. Write a program to check whether a given year is a leap year. A year is a leap year if it is divisible by 4 but
not divisible by 100, except when it is also divisible by 400.
3. Write a program that acts as a basic calculator. The program should take two numbers and an operator (+,
-, *, /) as input and use a switch case to perform the appropriate operation. Handle cases for invalid
operator.
4. Write a program that takes an integer (1-7) as input and prints the corresponding day of the week using a
switch statement. For example, 1 for Monday, 2 for Tuesday, and so on. Handle invalid inputs
appropriately.
Experiment 2: Loop Questions
1. Print Numbers from 1 to 100: Write a program to print numbers from 1 to 100 using a `for` loop.

2. Sum of First N Natural Numbers: Write a program to calculate the sum of the first `N` natural numbers.
3. Factorial of a Number: Write a program to calculate the factorial of a given number `N` using a `for` loop.

4. Odd Numbers Between 1 and 50: Write a program to print all odd numbers between 1 and 50.
5. Reverse a Number: Write a program to reverse a given integer number using a `for` loop.
6. Check Prime Number: Write a program to check if a given number `N` is prime.
7. Count Digits in a Number: Write a program to count the number of digits in a given number.
Experiment 3: Pattern Questions
1. Generate a Pattern: Write a program using a `for` loop to print a pyramid pattern with `N` rows. Example for
`N=3`:

*
**
***
2. Square Pattern of Stars: Write a program to print a square pattern with `N` rows and columns. Example for
`N=4`:

****
****
****
****
3. Right-Angled Triangle Pattern of Numbers: Write a program to print a right-angled triangle with `N` rows
where each row has the same number as its row number. Example for `N=4`:

1
22
333
4444
4. Inverted Right-Angled Triangle of Numbers: Write a program to print an inverted right-angled triangle with
numbers in decreasing order from `N` down to 1. Example for `N=5`:

55555
4444
333
22
1
5. Diamond Pattern of Stars: Write a program to print a diamond pattern with `N` rows (assuming `N` is odd).
Example for `N=5`:

*
**
***
**

*
6. Pascal's Triangle Pattern: Write a program to print the first `N` rows of Pascal’s Triangle. Example for `N=5`:

1
11
121
Experiment 4: 1D Array Questions
1. Find Maximum Element: Write a program to find the maximum element in a 1D array of integers.
2. Sum of Array Elements: Write a program to calculate the sum of all elements in a 1D array.
3. Reverse an Array: Write a program to reverse the elements of a 1D array.
4. Search for an Element: Write a program to search for an element in a 1D array and return its index if found.
5. Find Minimum and Maximum Element: Write a program to find both the minimum and maximum elements in a 1D
array.
6. Sort Array in Ascending Order: Write a program to sort a 1D array in ascending order.
7. Remove Duplicates from an Array: Write a program to remove duplicate elements from a 1D array.
Experiment 5: 2D Array Questions
1. Transpose of a Matrix: Write a program to find the transpose of a 2D matrix.
2. Matrix Addition: Write a program to add two 2D matrices of the same dimensions.
3. Matrix Multiplication: Write a program to multiply two 2D matrices.
4. Sum of Diagonal Elements: Write a program to calculate the sum of the diagonal elements of a square matrix.
Experiment 6: Functions
1. Write a program that uses a function to calculate the factorial of a given number. The function should take an
integer as input and return the factorial value.
2. Write a program that includes a function to check whether a given number is a prime number. The function should
return 1 if the number is prime and 0 otherwise. Test the function with user input.
3. Write a program that includes a function to find the greatest common divisor (GCD) of two numbers using the
Euclidean algorithm. The function should take two integers as parameters and return their GCD.
4. Write a program that swaps two numbers using a function. The function should take two integers by reference
(using pointers) and swap their values. Display the swapped values in the main function.

You might also like