1.
SUM OF INDIVIDUAL DIGIT
Aim:
To write a C program that calculates the sum of the individual digits of a 10-digit number
repeatedly until a single-digit result is obtained.
Algorithm:
1. Start
2. Input a 10-digit number.
3. Repeat the following steps until the number becomes a single digit:
a. Initialize sum = 0.
b. While the number is greater than 0:
i. Extract the last digit using digit = number % 10.
ii. Add the digit to sum.
iii. Remove the last digit using number = number / 10.
c. Assign number = sum.
4. Output the single-digit result.
5. End
2. PASS OR FAIL
Aim:
To write a C program that accepts a student's name and marks in five subjects, and declares
the result as PASS if the student scores a minimum of 40 in each subject; otherwise, declares
the result as FAIL.
Algorithm:
1. Start
2. Input the student's name.
3. Initialize an array to store marks for five subjects.
4. For each subject (from 1 to 5):
a. Prompt the user to enter marks.
b. Store the marks in the array.
5. Initialize a flag variable (e.g., pass_flag = 1).
6. For each mark in the array:
a. If the mark is less than 40:
i. Set pass_flag = 0.
ii. Break out of the loop.
7. If pass_flag is 1:
a. Display "PASS".
Else:
b. Display "FAIL".
8. End
3. PRIME NUMBERS
Aim:
To write a C program that generates the first n prime numbers.
Algorithm:
1. Start
2. Input the value of n (the number of prime numbers to generate).
3. Initialize a counter variable count = 0 to track the number of primes found.
4. Initialize a number variable num = 2 (since 2 is the first prime number).
5. Repeat steps 6 to 9 until count equals n:
6. Initialize a flag variable isPrime = 1.
7. For i = 2 to sqrt(num):
o If num % i == 0:
Set isPrime = 0 (number is not prime).
Break the loop.
8. If isPrime == 1:
Print num.
Increment count by 1.
9. Increment num by 1.
6. End
4. SORTING ARRAYS
Aim:
To write a C program that sorts and stores the elements of two arrays of integers into a
third array.
Algorithm:
1. Start
2. Input the size of the first array (n1) and the second array (n2).
3. Declare three arrays: arr1[n1], arr2[n2], and merged[n1 + n2].
4. Input elements for arr1 and arr2.
5. Merge arr1 and arr2 into merged.
o Copy all elements of arr1 into merged.
o Append all elements of arr2 to merged.
6. Sort the merged array in ascending order using a sorting algorithm (e.g., Bubble Sort,
Selection Sort).
7. Display the sorted merged array.
8. End
5. STACK OPERATION
Aim:
To implement and experiment with the operations of a stack (push, pop, and display)
using an array in C.
Algorithm:
1. Start
2. Initialize an array stack[MAX] and a variable top = -1 to represent the empty stack.
3. Define the following operations:
o Push Operation:
a. Check if top == MAX - 1 (Stack Overflow).
b. If not, increment top by 1 and insert the new element at stack[top].
o Pop Operation:
a. Check if top == -1 (Stack Underflow).
b. If not, retrieve the element at stack[top] and decrement top by 1.
o Display Operation:
a. If top == -1, print "Stack is empty."
b. Otherwise, print elements from stack[top] to stack[0].
4. Repeat the above operations as per user choice in a loop.
5. End
6. QUEUE OPERATION
Aim:
To develop a menu-driven C program that performs queue operations such as add
(enqueue), remove (dequeue), and display using array implementation.
Algorithm:
1. Start
2. Initialize the queue with a maximum size. Set front = -1 and rear = -1 to indicate an
empty queue.
3. Display Menu:
a. Option 1: Add (Enqueue)
b. Option 2: Remove (Dequeue)
c. Option 3: Display Queue
d. Option 4: Exit
4. Repeat the following steps until the user selects Exit:
a. If the user selects Add (Enqueue):
o Check if the queue is full (rear == MAX - 1).
o If full, display "Queue Overflow."
o Else,
If front == -1, set front = 0.
Increment rear by 1.
Insert the new element at queue[rear].
Display a success message.
b. If the user selects Remove (Dequeue):
o Check if the queue is empty (front == -1 or front > rear).
o If empty, display "Queue Underflow."
o Else,
Display the element at queue[front] as removed.
Increment front by 1.
If front > rear, reset both front and rear to -1 (queue becomes empty).
c. If the user selects Display:
o Check if the queue is empty (front == -1).
o If empty, display "Queue is empty."
o Else,
Display elements from queue[front] to queue[rear].
d. If the user selects Exit:
o Terminate the program.
5. End.
7. PALINDROME
Aim:
To develop a C++ program that checks whether a given string is a palindrome using
pointers.
Algorithm:
1. Start
2. Input the String:
o Read the input string from the user.
3. Initialize Pointers:
o Set a pointer start to the beginning of the string.
o Set another pointer end to the last character of the string.
4. Check for Palindrome:
o While start is less than end:
Compare the characters pointed to by start and end.
If they are not the same, the string is not a palindrome. Exit the loop.
If they are the same, increment start and decrement end.
5. Display Result:
o If all corresponding characters match, print that the string is a palindrome.
o Otherwise, print that the string is not a palindrome.
6. End