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

C Programs with Test Cases Guide

Uploaded by

sathyakcs
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)
2 views4 pages

C Programs with Test Cases Guide

Uploaded by

sathyakcs
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

Basic C Programs with Test Cases – Software Testing Lab

1. Check Whether a Number is Even or Odd

Program:
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);

if (num % 2 == 0)
printf("Even Number");
else
printf("Odd Number");
return 0;
}

Test Cases:
Test Case ID Input Expected Output

TC01 4 Even Number

TC02 7 Odd Number

TC03 0 Even Number

2. Check Whether Number is Positive, Negative or Zero

Program:
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);

if (num > 0)
printf("Positive");
else if (num < 0)
printf("Negative");
else
printf("Zero");
return 0;
}

Test Cases:
Test Case ID Input Expected Output

TC01 5 Positive

TC02 -3 Negative

TC03 0 Zero

3. Find Largest of Two Numbers

Program:
#include <stdio.h>
int main() {
int a, b;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);

if (a > b)
printf("%d is Larger", a);
else if (b > a)
printf("%d is Larger", b);
else
printf("Both are Equal");
return 0;
}

Test Cases:
Test Case ID Input Expected Output

TC01 10, 5 10 is Larger

TC02 5, 10 10 is Larger

TC03 7, 7 Both are Equal


4. Sum of First N Natural Numbers

Program:
#include <stdio.h>
int main() {
int n, sum = 0;
printf("Enter n: ");
scanf("%d", &n);

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


sum += i;

printf("Sum = %d", sum);


return 0;
}

Test Cases:
Test Case ID Input Expected Output

TC01 5 15

TC02 1 1

TC03 0 0

5. Factorial of a Number

Program:
#include <stdio.h>
int main() {
int n, fact = 1;
printf("Enter a number: ");
scanf("%d", &n);

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


fact *= i;

printf("Factorial = %d", fact);


return 0;
}

Test Cases:
Test Case ID Input Expected Output
TC01 5 120

TC02 0 1

TC03 1 1

You might also like