ST Lab New
ST Lab New
AIM: CODING :
To create a program for calculating the sum of
digits. #include<stdio.h>
int main()
ALGORITHM : {
long long n;
Step 1: Start the process. int sum = 0, rem;
printf("ENTER A NUMBER: ");
Step 2: Declare variables n, sum, and rem. scanf("%lld", &n);
Step 3: Take input for the number n.
while (n > 9)
Step 4: Repeat the following steps while n is greater than 9: {
sum = 0;
Set sum to 0. while (n > 0) {
Find the remainder of n when divided by 10 and add rem = n % 10;
it to sum. sum = sum + rem;
Reduce n by dividing it by 10.
n = n / 10;
Step 5: Set n to the sum obtained in the previous step. }
n = sum;
Step 6: Display the final single digit sum. }
return 0;
}
TEST CASE :
AIM :
CODING:
Program for generating n prime numbers #include <stdio.h>
int main() {
ALGORITHM : int n, num = 2, count = 0;
printf("ENTER THE NUMBER OF PRIMES TO
Step 1: Start the process. GENERATE :");
scanf("%d", &n);
Step 2: Initialize n, num = 2, and count = 0. printf("GENERATING %d PRIME NUMBERS:\n", n);
while (count < n)
Step 3: Get input for the number of primes to generate (n).
{
Step 4: Loop while count is less than n and check if num int prime = 1;
is divisible by any number from 2 to √num. for (int i = 2; i * i <= num; i++)
if (num % i == 0)
Step 5: If num is not divisible (prime), print num and {
increment count. prime = 0;
break;
Step 6: Increment num to check the next number.
}
Step 7: Stop the process. if (prime)
{
printf("%d ", num);
count++;
}
num++;
}
return 0;
}
TEST CASE :
TEST TEST EXPECTED ACTUAL
S.NO TEST NAME TEST DESCRIPTION RESULT
ID DATA VALUE VALUE
Check behavior for
Valid Input (Single
1 TC01 generating 5 prime 5 2 3 5 7 11 2 3 5 7 11 SUCCESS
Digit)
numbers.
Check behavior for
Valid Input (Double 2 3 5 7 11 13 17 2 3 5 7 11 13
2 TC02 generating 10 prime 10 SUCCESS
Digits) 19 23 29 17 19 23 29
numbers.
Valid Input (Large Check behavior for
3 TC03 1 2 2 SUCCESS
Number) generating 1 prime number.
Invalid Input Check behavior when input Error (invalid
4 TC04 abc123 Error SUCCESS
(Alphanumeric) is alphanumeric. input)
Invalid Input Check behavior when input Error (invalid
5 TC05 !@#123 Error SUCCESS
(Symbols) contains symbols. input)
Invalid Input (Mix of Check behavior with a mix Error (invalid
6 TC06 $123abc Error SUCCESS
Symbols) of symbols and numbers. input)
Invalid Input (Empty Check behavior when no Error (invalid
7 TC07 (empty) Error SUCCESS
Input) input is provided. input)
8 TC08 Valid Input (Zero) Check behavior for input 0. 0 No output No output SUCCESS
Invalid Input Check behavior when input Error (invalid
9 TC09 -5 Error SUCCESS
(Negative Number) is a negative number. input)
Invalid Input Check behavior when input Error (invalid
10 TC10 (spaces) Error SUCCESS
(Spaces Only) contains only spaces. input)
5. STACK OPERTION
AIM :
Experiment the operations of Stack using array implementation.
ALGORITHM :
CODING : break;
// Display stack elements case 2:
#include <stdio.h> void display() { pop();
#define MAX 100 if (top >= 0) { break;
for (int i = 0; i <= top; i++) { case 3:
int stack[MAX], top = -1; printf("%d ", stack[i]); peek();
} break;
// Push operation printf("\n"); case 4:
void push(int v) { } else { display();
if (top < MAX - 1) { printf("STACK IS EMPTY\ break;
stack[++top] = v; n"); default:
printf("%d PUSHED\n", v); } printf("INVALID
} else { } CHOICE. TRY AGAIN..\n");
printf("STACK OVERFLOW\n"); }
} int main() { }
} int choice, value; return 0;
while (1) { }
// Pop operation // Menu
void pop() { printf("\n1.PUSH \n2.POP \
if (top >= 0) { n3.PEEK \n4.DISPLAY \n5.EXIT \
printf("%d POPPED\n", nENTER YOUR CHOICE: ");
stack[top--]); scanf("%d", &choice);
} else {
printf("STACK UNDERFLOW\ if (choice == 5) {
n"); break;
} }
}
switch (choice) {
// Peek operation case 1:
void peek() { printf("ENTER VALUE
if (top >= 0) { TO PUSH: ");
printf("Top: %d\n", stack[top]); scanf("%d", &value);
} else { push(value);
printf("STACK IS EMPTY\n");
}
}
TEST CASE :
TEST EXPECTED ACTUAL
S.NO TEST ID TEST NAME TEST DATA RESULT
DESCRIPTION VALUE VALUE
Push a single-
Push Single "5
1 TC01 digit value to the 5 "5 PUSHED" SUCCESS
Value PUSHED"
stack
Push multiple "10 PUSHED, 20
Push Multiple Matches
2 TC02 values 10, 20, 30 PUSHED, 30 SUCCESS
Values Expected
sequentially PUSHED"
Pop the top value Last pushed value Matches
3 TC03 Pop a Value Pop operation SUCCESS
from the stack (30) is popped Expected
Check the top
Matches
4 TC04 Peek Top Value value of the stack Peek Top value (20) SUCCESS
Expected
without popping
Display all
Display Stack Matches
5 TC05 elements in the Display "10 20" SUCCESS
Contents Expected
stack
Push until the
Overflow "STACK Matches
6 TC06 stack exceeds its 101 values SUCCESS
Condition OVERFLOW" Expected
capacity
Underflow Pop from an "STACK Matches
7 TC07 Pop operation SUCCESS
Condition empty stack UNDERFLOW" Expected
Peek on Empty Peek when the "STACK IS Matches
8 TC08 Peek SUCCESS
Stack stack is empty EMPTY" Expected
Push a zero value Matches
9 TC09 Push Zero 0 "0 PUSHED" SUCCESS
to the stack Expected
"STACK
Push Negative Push a negative OVERFLOW" Matches
10 TC10 -5 SUCCESS
Values value to the stack (Program Expected
constraint)
6. QUEUE OPERTION
AIM
Test the C program : Menu-driven option for queue operations like add,remove and display.
ALGORITHM
printf("\n");
CODING : }
}
#include <stdio.h> int main() {
#define SIZE 5 int choice, value;
int queue[SIZE]; do {
int front = -1, rear = -1; printf("\nQueue Operations Menu:\n");
printf("1. Add (Enqueue)\n");
void enqueue(int value) { printf("2. Remove (Dequeue)\n");
if (rear == SIZE - 1) { printf("3. Display\n");
printf("Queue is full. Cannot add %d.\n", value); printf("4. Exit\n");
} else { printf("Enter your choice: ");
if (front == -1) front = 0; scanf("%d", &choice);
rear++;
queue[rear] = value; switch (choice) {
printf("%d added to the queue.\n", value); case 1:
} printf("Enter value to add: ");
} scanf("%d", &value);
void dequeue() { enqueue(value);
if (front == -1 || front > rear) { break;
printf("Queue is empty. Cannot remove.\n"); case 2:
} else { dequeue();
printf("%d removed from the queue.\n", break;
queue[front]); case 3:
front++; display();
if (front > rear) front = rear = -1; break;
} case 4:
} printf("Existing...\n");
void display() { break;
if (front == -1 || front > rear) { default:
printf("Queue is empty.\n"); printf("invalid choice! please try again.\n");
} else { break;
printf("Queue: "); }
for (int i = front; i <= rear; i++) { }
printf("%d ", queue[i]); while(choice !=4);
} return 0;
}
TEST CASE :
TEST EXPECTED ACTUAL
S.NO TEST NAME TEST DESCRIPTION TEST DATA RESULT
ID VALUE VALUE
Enqueue to Add a single digit to an 5 added to the
1 TC01 5 5 added SUCCESS
Empty Queue empty queue queue.
Attempt to add an
Enqueue to Full
2 TC02 element when the queue [1, 2, 3, 4, 5] Queue is full. Queue full SUCCESS
Queue
is full
Dequeue from
Remove the front [1, 2, 3], 1 removed from the
3 TC03 Non-Empty 1 removed SUCCESS
element from the queue dequeue queue.
Queue
Dequeue from Attempt to remove from Queue is empty.
4 TC04 Empty queue Empty error SUCCESS
Empty Queue an empty queue Cannot remove.
Display Non- Display elements in a
5 TC05 [10, 20, 30] Queue: 10 20 30 Queue: 10.. SUCCESS
Empty Queue non-empty queue
Display Empty Display elements in an Empty
6 TC06 Empty queue Queue is empty. SUCCESS
Queue empty queue queue
Enqueue Add multiple elements All values added to
7 TC07 5, 10, 15 All added SUCCESS
Multiple Values consecutively the queue.
Circular Use Add elements, dequeue [5, dequeue
8 TC08 8 added after reset. 8 added SUCCESS
After Reset all, and add again all, 8]
Add and Proper functioning
Enqueue and dequeue [1, 2,
9 TC09 Remove to Full of enqueue and Success SUCCESS
until the queue is reused dequeue, 3]
Cycle dequeue
Add: 1, 2;
Perform add, remove,
10 TC10 Mix Operations Remove: 1; Queue: 2 Queue: 2 SUCCESS
and display in sequence
Display
7. PALINDROME
AIM : CODING :
TEST CASE :
TEST TEST TEST EXPECTED ACTUAL
S.NO TEST NAME RESULT
ID DESCRIPTION DATA VALUE VALUE
Check if a single
Valid Palindrome The string is a The string is
1 TC01 character is a a SUCCESS
(Single Character) palindrome. a palindrome.
palindrome
Check if an odd-
Valid Palindrome (Odd The string is a The string is
2 TC02 length string is a racecar SUCCESS
Length) palindrome. a palindrome.
palindrome
Check if an even-
Valid Palindrome (Even The string is a The string is
3 TC03 length string is a abba SUCCESS
Length) palindrome. a palindrome.
palindrome
Check if a string The string is
Invalid Palindrome The string is not
4 TC04 with mixed cases Racecar not a SUCCESS
(Mixed Case) a palindrome.
fails as a palindrome palindrome.
Check if a string
Invalid Palindrome The string is
with non-matching The string is not
5 TC05 (Non-Matching hello not a SUCCESS
characters is not a a palindrome.
Characters) palindrome.
palindrome
The string is not
a man a
Check if a string a palindrome. The string is
Valid Palindrome plan a
6 TC06 with spaces is a (ignores not a SUCCESS
(Spaces) canal
palindrome case/special palindrome.
panama
handling)
Check behavior for (empty The string is a The string is
7 TC07 Empty String SUCCESS
an empty string input) palindrome. a palindrome.
Check if a string
Valid Palindrome with only special The string is a The string is
8 TC08 !!! SUCCESS
(Special Characters) characters is a palindrome. a palindrome.
palindrome
Check if a string
Invalid Palindrome with only whitespace The string is a The string is
9 TC09 "" SUCCESS
(Whitespace) is not considered a palindrome. a palindrome.
palindrome
Check if numeric
Valid Palindrome The string is a The string is
10 TC10 input is treated as a 12321 SUCCESS
(Numbers) palindrome. a palindrome.
palindrome