PROGRAMMING IN C
Practical Work submitted to ST. FRANCIS COLLEGE FOR WOMEN in partial
fulfilment of the requirements for the award of the degree of
BACHELORS OF COMPUTER SCIENCE
by
YOUR NAME
Your Roll Number
Under the guidance and supervision of
MS JENIFER JOHNSON
DEPARTMENT OF COMPUTER SCIENCE
ST. FRANCIS COLLEGE FOR WOMEN
BEGUMPET, HYDERABAD.
OCTOBER, 2025
CERTIFICATE
This is to certify that the bonafide record of lab entitled Programming in C in the Semester
I submitted to the St. Francis College for Women in partial fulfilment of the requirements
for the award of the Degree of Bachelors in Computer Science, is an original record work
done by NAME bearing the ROLL NUMBER during the academic year 2023-2024 under
the supervision and guidance of MS. Jenifer Johnson, Department of Computer Science, St.
Francis College for Women, Begumpet, Hyderabad -16.
Internal Examiner External Examiner
S.N PROGRAM TITLE
O
1.
Program to find greatest of two numbers using ternary (conditional )operator
2.
Program to find if a given number is even or odd
3.
Program to find largest of 3 numbers
4. Accept students no, name, sub1, sub2, sub3 marks. Calculate total and average and
display in a neat format with grade. (if-else if statement)
5.
Accept two numbers and perform arithmetic operations using switch case.
6.
Program to find the factorial of a number
7.
Program to display multiplication table for a given number
8.
Program to print even numbers and sum of even numbers from 1 to n
9.
Program to print odd numbers and sum of odd numbers from 1 to n
10.
Program to display Fibonacci series from 1 to n
11.
Program to find the reverse of a given number
12.
Program to check whether a given number is palindrome of a number
13.
Program to check whether a given number is Armstrong or not
14.
Program to display prime numbers ranging from 1 to n
15.
Program to check whether a given number is perfect or not
16.
Program to demonstrate break and continue statement
17.
Program to accept a list of values and display their sum and average.
18.
Program to accept a list of values and display their maximum value.
19.
Program to accept a list of values and display their minimum value.
20.
Program to accept a list of values and display the sorted list in ascending order.
21.
Program to search for an element in a given list of values.
22.
Program to perform matrix addition on 2 matrices elements of 2x2 dimension.
23 Program to find sum of two numbers using functions (with arguments and with return
value)
24 Program to demonstrate functions with arguments and without return value
25 Program using call by value and call by reference
26
Program to print factorial of a number using recursion
27 Program to print Fibonacci using recursion
28 Program to demonstrate structures
29
Program to demonstrate unions
30 Program to demonstrate Pointers
1.Program to find greatest of two numbers using ternary
(conditional )operator
#include <stdio.h>
int main() {
int a, b, largest;
// Input two numbers
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
// Ternary operator to find the largest
largest = (a > b) ? a : b;
printf("The largest number is: %d\n", largest);
return 0;
}
2. Program to find if a given number is even or odd
#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d", &number);
if (number%2 == 0)
{
printf("%d is an even integer.",number);
}
else
{
printf("%d is an odd integer.",number);
}
return 0;
}
3. Program to find largest of 3 numbers
#include <stdio.h>
int main() {
int a, b, c;
// Input 3 numbers
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
// Using if-else ladder to find the maximum
if (a >= b && a >= c) {
printf("Maximum number is: %d\n", a);
}
else if (b >= a && b >= c) {
printf("Maximum number is: %d\n", b);
}
else {
printf("Maximum number is: %d\n", c);
}
return 0;
}
4. Accept students no, name, sub1, sub2, sub3 marks. Calculate total and
average and display in a neat format with grade. (if-else if statement)
#include <stdio.h>
int main()
{
int sub1,sub2,su3,marks;
float Average;
printf(“Enter marks of subject1:”);
scanf(“%d”,&sub1);
printf(“Enter marks of subject2:”);
scanf(“%d”,&sub2);
printf(“Enter marks of subject3:”);
scanf(“%d”,&sub3);
marks=sub1+sub2+sub3;
Average=(float)marks/3;
printf(Total marks is %d”, marks);
printf(Average is %f”,Average);
if (marks <= 100 && marks >= 90)
printf("A+ Grade");
else if (marks < 90 && marks >= 80)
printf("A Grade");
else if (marks < 80 && marks >= 70)
printf("B Grade");
else if (marks < 70 && marks >= 60)
printf("C Grade");
else if (marks < 60 && marks >= 50)
printf("D Grade");
else
printf("F Failed");
return 0;
}
5. Accept two numbers and perform arithmetic operations using switch
case.
#include <stdio.h>
int main() {
float num1, num2, result;
char op;
// Input two numbers and an operator
printf("Enter first number: ");
scanf("%f", &num1);
printf("Enter an operator (+, -, *, /): ");
scanf(" %c", &op); // Note the space before %c to catch newline
printf("Enter second number: ");
scanf("%f", &num2);
switch (op) {
case '+':
result = num1 + num2;
printf("Result = %.2f\n", result);
break;
case '-':
result = num1 - num2;
printf("Result = %.2f\n", result);
break;
case '*':
result = num1 * num2;
printf("Result = %.2f\n", result);
break;
case '/':
if (num2 != 0) {
result = num1 / num2;
printf("Result = %.2f\n", result);
} else {
printf("Error: Division by zero is not allowed.\n");
}
break;
default:
printf("Invalid operator!\n");
}
return 0;
}
6. Program to find the factorial of a number
#include<stdio.h>
int main()
{
int i, fact=1,number;
printf("Enter a number: ");
scanf("%d",&number);
for(i=1;i<=number;i++)
{
fact=fact*i;
}
printf("Factorial of %d is: %d",number,fact);
return 0;
}
7. Program to display multiplication table for a given number
#include <stdio.h>
int main() {
int n;
printf("Enter an integer: ");
scanf("%d", &n);
for (int i = 1; i <= 10; ++i) {
printf("%d * %d = %d \n", n, i, n * i);
}
return 0;
}
8. Program to print even numbers and sum of even numbers from 1 to n
#include <stdio.h>
int main() {
int i,n,sum=0;
printf("enter an integer:");
scanf("%d",&n);
for(i=2;i<=n;i+=2)
{sum+=i;}
printf("the sum of all even numbers is: %d", sum);
return 0;
}
9. Program to print odd numbers and sum of odd numbers from 1 to n
#include <stdio.h>
int main() {
int i,n,sum=0;
printf("enter an integer:");
scanf("%d",&n);
for(i=1;i<=n;i+=2)
{sum+=i;}
printf("the sum of all even numbers is: %d", sum);
return 0;
}
10. Program to display Fibonacci series from 1 to n
#include<stdio.h>
int main()
{
int n1=0,n2=1,n3,i,number;
printf("Enter the number of elements:");
scanf("%d",&number);
printf("\n%d %d",n1,n2);
for(i=2;i<number;++i)
{ n3=n1+n2;
printf(" %d",n3);
n1=n2;
n2=n3; }
return 0;
}
11. Program to find the reverse of a given number
#include<stdio.h>
int main()
{
int n, reverse=0, rem;
printf("Enter a number: ");
scanf("%d", &n);
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
printf("Reversed Number: %d",reverse);
return 0;
}
12. Program to check whether a given number is palindrome of a number
#include <stdio.h>
int main() {
int num, original, reversed = 0, remainder;
printf("Enter a number: ");
scanf("%d", &num);
original = num;
while (num != 0) {
remainder = num % 10;
reversed = reversed * 10 + remainder;
num = num / 10;
}
if (original == reversed) {
printf("%d is a Palindrome number.\n", original);
} else {
printf("%d is NOT a Palindrome number.\n", original);
}
return 0;
}
13. Program to check whether a given number is Armstrong or not
#include <stdio.h>
#include <math.h>
int main() {
int num, original, remainder, n = 0;
float result = 0.0;
printf("Enter a number: ");
scanf("%d", &num);
original = num;
int temp = num;
while (temp != 0) {
temp /= 10;
n++;
}
temp = num;
while (temp != 0) {
remainder = temp % 10;
result += pow(remainder, n);
temp /= 10;
}
if ((int)result == original) {
printf("%d is an Armstrong number.\n", original);
} else {
printf("%d is NOT an Armstrong number.\n", original);
}
return 0;
}
14. Program to display prime numbers ranging from 1 to n
#include <stdio.h>
int main() {
int n, i, j, isPrime;
printf("Enter the value of n: ");
scanf("%d", &n);
printf("Prime numbers between 1 and %d are:\n", n);
for (i = 2; i <= n; i++) {
isPrime = 1; // Assume number is prime
for (j = 2; j <= i / 2; j++) {
if (i % j == 0) {
isPrime = 0; // Not prime
break;
}
}
if (isPrime == 1) {
printf("%d ", i);
}
}
return 0;
}
15. Program to check whether a given number is perfect or not
#include <stdio.h>
int main() {
int num, i, sum = 0;
printf("Enter a number: ");
scanf("%d", &num);
for (i = 1; i <= num / 2; i++) {
if (num % i == 0) {
sum += i;
}
}
if (sum == num && num != 0) {
printf("%d is a Perfect number.\n", num);
} else {
printf("%d is NOT a Perfect number.\n", num);
}
return 0;
}
16. Program to demonstrate break and continue statement
#include <stdio.h>
int main() {
int i;
for (i = 1; i <= 10; i++) {
if (i == 5) {
printf("Encountered 5, breaking the loop.\n");
break; // Exit loop when i = 5
}
printf("%d ", i);
}
for (i = 1; i <= 10; i++) {
if (i == 5) {
printf("Skipping 5 using continue.\n");
continue;
}
printf("%d ", i);
}
return 0;
}
17. Program to accept an Array of values and display their sum and
average.
#include <stdio.h>
int main() {
int values[5];
printf("Enter 5 integers: ");
for(int i = 0; i < 5; ++i)
{
scanf("%d", &values[i]);
}
printf("Displaying integers: ");
for(int i = 0; i < 5; ++i)
{
printf("%d\n", values[i]);
}
return 0;
}
18. Program to accept an array of values and display their maximum value.
#include <stdio.h>
int main() {
int n;
double arr[100];
printf("Enter the number of elements (1 to 100): ");
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
printf("Enter number%d: ", i + 1);
scanf("%lf", &arr[i]);
}
for (int i = 1; i < n; ++i) {
if (arr[0] < arr[i]) {
arr[0] = arr[i];
}
}
printf("Largest element = %.2lf", arr[0]);
return 0;
}
19. Program to accept a list of values and display their minimum value.
#include <stdio.h>
int main() {
int n;
double arr[100];
printf("Enter the number of elements (1 to 100): ");
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
printf("Enter number%d: ", i + 1);
scanf("%lf", &arr[i]);
}
for (int i = 1; i < n; ++i) {
if (arr[0] > arr[i]) {
arr[0] = arr[i];
}
}
printf("Minimum element = %.2lf", arr[0]);
return 0;
}
20. Program to accept a list of values and display the sorted list in
ascending order.
#include <stdio.h>
void main (){
int num[20];
int i, j, a, n;
printf("enter number of elements in an array
");
scanf("%d", &n);
printf("Enter the elements
");
for (i = 0; i < n; ++i)
scanf("%d", &num[i]);
for (i = 0; i < n; ++i){
for (j = i + 1; j < n; ++j){
if (num[i] > num[j]){
a = num[i];
num[i] = num[j];
num[j] = a;
}
}
}
printf("The numbers in ascending order is:
");
for (i = 0; i < n; ++i){
printf("%d
", num[i]);
}
}
21. Program to search for an element in a given list of values.
#include <stdio.h>
int main() {
int size, element, found = 0;
// Input size and elements of the array
printf("Enter the size of the array: ");
scanf("%d", &size);
int arr[size];
printf("Enter %d elements -\n", size);
for (int i = 0; i < size; i++) {
scanf("%d", &arr[i]);
}
// Input the element to search
printf("\nEnter the element to search: ");
scanf("%d", &element);
for (int i = 0; i < size; i++) {
if (arr[i] == element) {
found = 1;
printf("Element %d found at position %d", element, i + 1);
break;
}
}
if (!found) {
printf("Element %d not found in the array", element);
}
return 0;
}
22. Program to perform matrix addition on 2 matrices elements of 2x2
dimension.
#include <stdio.h>
int main() {
int r, c, a[100][100], b[100][100], sum[100][100], i, j;
printf("Enter the number of rows (between 1 and 100): ");
scanf("%d", &r);
printf("Enter the number of columns (between 1 and 100): ");
scanf("%d", &c);
printf("\nEnter elements of 1st matrix:\n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
printf("Enter element a%d%d: ", i + 1, j + 1);
scanf("%d", &a[i][j]);
}
printf("Enter elements of 2nd matrix:\n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
printf("Enter element b%d%d: ", i + 1, j + 1);
scanf("%d", &b[i][j]);
}
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
sum[i][j] = a[i][j] + b[i][j];
}
// printing the result
printf("\nSum of two matrices: \n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
printf("%d ", sum[i][j]);
if (j == c - 1) {
printf("\n\n");
}
}
return 0;
}
23. Program to find sum of two numbers using functions (with arguments
and with return value)
#include <stdio.h>
int sum(int a, int b)
{
return a + b;
}
int main()
{
int a = 30, b = 40;
int res = sum(a, b);
printf("Sum is: %d", res);
return 0;
}
24. Program to demonstrate functions with arguments and without return
value
#include <stdio.h>
void addNumbers(int a, int b) {
int sum = a + b;
printf("Sum of %d and %d is: %d\n", a, b, sum);
}
int main() {
int x, y;
printf("Enter two numbers: ");
scanf("%d %d", &x, &y);
addNumbers(x, y);
return 0;
}