Programming Exam Preparation Guide
Question 1: Sum of Prime Numbers in a Range
This program calculates the sum of all prime numbers between 1 and 100 using a loop and if statements.
Steps:
1. Iterate through numbers from 2 to 100.
2. For each number, check if it's a prime using a nested loop.
3. If prime, add to the sum.
Code:
```c
#include <stdio.h>
int main() {
int i, j, isPrime, sum = 0;
for(i = 2; i <= 100; i++) {
isPrime = 1;
for(j = 2; j <= i/2; j++) {
if(i % j == 0) {
isPrime = 0;
break;
if(isPrime)
Programming Exam Preparation Guide
sum += i;
printf("Sum of prime numbers between 1 and 100 is: %d", sum);
return 0;
```
Question 2: Array and Functions
This program accepts 10 numbers into an array, finds the maximum number, and displays all even numbers.
Steps:
1. Accept input into a 1D array.
2. Use a function to find the maximum element.
3. Use another function to print even numbers.
Code:
```c
#include <stdio.h>
int findMax(int arr[], int size);
void printEven(int arr[], int size);
int main() {
Programming Exam Preparation Guide
int arr[10], i;
for(i = 0; i < 10; i++) {
printf("Enter number %d: ", i+1);
scanf("%d", &arr[i]);
printf("Maximum element: %d\n", findMax(arr, 10));
printf("Even numbers: ");
printEven(arr, 10);
return 0;
int findMax(int arr[], int size) {
int max = arr[0];
for(int i = 1; i < size; i++) {
if(arr[i] > max)
max = arr[i];
return max;
void printEven(int arr[], int size) {
for(int i = 0; i < size; i++) {
if(arr[i] % 2 == 0)
Programming Exam Preparation Guide
printf("%d ", arr[i]);
```
Question 3: Menu-Driven Banking Application
This program simulates a simple banking system using switch and nested if-else.
Steps:
1. Display menu using switch.
2. Use nested if-else to validate balance during withdrawal.
Code:
```c
#include <stdio.h>
int main() {
int choice;
float balance = 1000.0, amount;
while(1) {
printf("\n1. Deposit\n2. Withdraw\n3. Check Balance\n4. Exit\nEnter your choice: ");
scanf("%d", &choice);
Programming Exam Preparation Guide
switch(choice) {
case 1:
printf("Enter amount to deposit: ");
scanf("%f", &amount);
balance += amount;
break;
case 2:
printf("Enter amount to withdraw: ");
scanf("%f", &amount);
if(amount > balance)
printf("Insufficient balance!\n");
else
balance -= amount;
break;
case 3:
printf("Current Balance: %.2f\n", balance);
break;
case 4:
return 0;
default:
printf("Invalid choice!\n");
```
Programming Exam Preparation Guide
Question 4: Pattern Printing Using Nested Loops
This program prints a triangle pattern and its inverted form using nested loops.
Code:
```c
#include <stdio.h>
int main() {
int i, j;
printf("Normal Pattern:\n");
for(i = 1; i <= 5; i++) {
for(j = 1; j <= i; j++) {
printf("*");
printf("\n");
printf("Inverted Pattern:\n");
for(i = 5; i >= 1; i--) {
for(j = 1; j <= i; j++) {
printf("*");
printf("\n");
Programming Exam Preparation Guide
return 0;
```