0% found this document useful (0 votes)
3 views68 pages

Practical Files

This document is a practical file for the Computer Programming Laboratory (PBC-101) for BCA students in their first semester at Haldwani Campus. It includes details about the student, Pramod Aithani, and outlines various programming exercises with objectives, code, and outputs for each program. The file serves as a record of completed experiments and is part of the requirements for the BCA degree course prescribed by Graphic Era Hill University, Dehradun.

Uploaded by

temp.meee3
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)
3 views68 pages

Practical Files

This document is a practical file for the Computer Programming Laboratory (PBC-101) for BCA students in their first semester at Haldwani Campus. It includes details about the student, Pramod Aithani, and outlines various programming exercises with objectives, code, and outputs for each program. The file serves as a record of completed experiments and is part of the requirements for the BCA degree course prescribed by Graphic Era Hill University, Dehradun.

Uploaded by

temp.meee3
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

HALDWANI CAMPUS

PRACTICAL FILE
Computer programming laboratory

PBC-101

COURSE: BCA

SEMESTER: 1st

SESSION: 24-25

SUBMITTED TO SUBMITTED BY

Mr. DIWAKAR UPADHYAY NAME: PRAMOD AITHANI

Assist. Prof. ROLL NO. 20

DEPARTMENT OF COMPUTER SCIENCE & APPLICATION

COLLEGE ROLL NO.________ EXAMINATION ROLL NO.__________________


HALDWANI CAMPUS

THIS IS TO CERTIFY THAT Mr. ____________________________________________ HAS SATISFAC-

TORILY COMPLETED ALL THE EXPERIMENTS IN THE LABORATORY OF THIS COLLEGE. THE

COURSE OF THE EXPERIMENTS / TERM WORK ___________________________________ IN PAR-

TIAL FULLFILLMENT OF THE REQUIREMENT IN _____________ SEMESTER OF BCA DEGREE

COURSE PRESCRIBED BY GRAPHIC ERA HILL UNIVERSITY, DEHRADUN DURING THE YEAR

_______ - _______

CONCERNED FACULTY HEAD OF DEPARTMENT

NAME OF EXAMINER:

SIGNATURE OF EXAMINER:
STUDENT LAB REPORT SHEET

Computer programming Lab (PBC-101)

Name of Student: -PRAMOD AITHANI [Link]: -9917888411

Address Permanent: -KAPKOTE, BAGESHWAR Mo. No: -9410995698

Father’s Name: - MADAN SINGH AITHANI Mo. No: -9410995698

Mother’s Name: - HAMA DEVI

Section: - B Semester: - 1ST Class Roll No: - 41

Local Address: -LALKUAN Email: -


IMPRAMODAITHANI040@[Link]
Grade A B C

Marks 5 3 1

S. No. Name of the Experiment D.O.P. Date of Grade Grade Total Student’s Teacher’s
Submission (Viva) (Re- Marks Signature Signature
port (out of 10)
File)

10

11

12
13

14

15
16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37
Total No of Practical allotted ……………………………………….

Total No of Practical completed ………………………………….

Percentage Attendance of Practical …………………………….


Page No.

PROGRAM NO 1
NAME: PRAMOD AITHANI
COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to print hello world.

2. PROGRAM:

#include<stdio.h>

int main ()

printf(“hello world\n”);

return 0;

3. OUTPUT:

hello world
Page No.

PROGRAM NO 2
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to perform all arithmetic operations.

2. PROGRAM:

#include<stdio.h>

int main (){

int a, b;

printf(“enter first number=”);

scanf(“%d”,&a);

printf(“\n enter second number=”);

scanf(“%d”,&b);

printf(“\n addition=%d”, a + b);

printf(“\n subtraction=%d” ,a-b);

printf(“\n multiplication=%d” ,a*b);

printf(“\n division=%d” ,a/b);

return 0;

3. OUTPUT:

enter first number=8


enter second number=4

addition=12

subtraction=4

multiplication=32

division=2

Page No.

PROGRAM NO 3
NAME: PRAMOD AITHANI

COURSE: BCA
SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to find the area and perimeter of rectan-


gle.

2. PROGRAM:

#include<stdio.h>

int main () {

int l, b, a, p;

printf(“length of a rectangle=”);

scanf(“%d”,&l);

printf(“breadth of rectangle=”);

scanf(“%d”,&b);

printf(“perimeter of the rectangle =%d\n”, p=2*(l + b));

printf(“area of the rectangle =%d”, a=l*b);

return 0;

}
[Link]:

length of a rectangle=10

breadth of rectangle=20

perimeter of the rectangle =60

area of the rectangle =200

Page No.

PROGRAM NO 4
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to find the diameter, perimeter and area


of a circle. (pi=3.14)

2. PROGRAM:

#include<stdio.h>

int main () {

float r, d, a, p, pi;

pi=3.14;

printf(“enter the radius of the circle =”);

scanf(“%f”, &r);

printf(“diameter of the circle =%f\n”, d=2*r);

printf(“perimeter of the circle =%f\n”, p=2*pi*r);

printf(“area of the circle =%f\n”, a=pi*r*r);

return 0;

}
[Link]:

enter the radius of the circle =5.0

diameter of the circle =10.000000

perimeter of the circle =31.400002

area of the circle =78.500000

Page No.

PROGRAM NO 5
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to find the area of a triangle.

2. PROGRAM:

#include<stdio.h>

int main () {

float b, h, a;

printf(“enter the base of the triangle =”);

scanf(“%f”,&b);

printf(“enter the height of the triangle =”);

scanf(“%f”,&h);

printf(“area of the triangle =%f\n”, a=0.5*b*h);

return 0;

[Link]:
enter the base of the triangle =10.00

enter the height of the triangle =15.00

area of the triangle =75.000000


Page No.

PROGRAM NO 6
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program for temperature conversion from degree


Celsius to Fahrenheit.
2. PROGRAM:

#include<stdio.h>

int main () {

float c, f;

printf(“enter the temperature in celsius=”);

scanf(“%f”, &c);

printf(“temperature in fahrenheit =%f”,f=(c*9/5)+32);

return 0;

[Link]:

enter the temperature in celsius=35.00

temperature in Fahrenheit =95.000000


Page No.

PROGRAM NO 7
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program for length conversion from meter to kilo-


meter.
2. PROGRAM:

#include<stdio.h>

int main () {

float m, km;

printf(“enter the length in meter =”);

scanf(“%f”, &m);

printf(“length in kilometer=%f km”, km=m/1000);

return 0;

[Link]:

enter the length in meter =1200.00

length in kilometer=1.200000 km
Page No.

PROGRAM NO 8
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to exchange the values of two integer


variables.
2. PROGRAM:

#include<stdio.h>

int main () {

int a, b, x;

printf(“enter two integers=”);

scanf(“%d %d”, &a, &b);

printf(“before exchanging: a =%d b=%d\n”, a, b);

x= a;

a= b;
b= x;

printf(“after exchanging: a =%d b =%d”, a, b);

return 0;

[Link]:

enter two integers= 6 5

before exchanging: a =6 b=5

after exchanging: a =5 b =6
Page No.

PROGRAM NO 9
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:
1. OBJECTIVE: Write a program to calculate simple interest from given
principle, rate and term. (SI=P*R*T/100)

2. PROGRAM:

#include<stdio.h>

int main () {

float p, r, t, si;

printf(“enter the principle amount =”);

scanf(“%f”, &p);

printf(“enter the rate of interest =”);

scanf(“%f”, &r);

printf(“enter the time(in years) =”);

scanf(“%f”, &t);

printf(“simple interest = %f”, si=p*r*t/100);

return 0;

[Link]:

enter the principle amount =500

enter the rate of interest =5

enter the time(in years) =4


simple interest = 100.000000

Page No.

PROGRAM NO 10
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to calculate compound interest.


(CI=p*(1+rate/100)^T)

2. PROGRAM:

#include <stdio.h>

#include <math.h>

int main() {

float principal, rate, time, amount, compoundInterest;

int n;

printf("Enter the principal amount: ");

scanf("%f", &principal);

printf("Enter the rate of interest (in percentage): ");

scanf("%f", &rate);

printf("Enter the number of times that interest is compounded per year: ");

scanf("%d", &n);

printf("Enter the time in years: ");

scanf("%f", &time);

amount = principal * pow((1 + (rate / (n * 100))), n * time);

compoundInterest = amount - principal;


printf("The amount after %f years is: %f\n", time, amount);

printf("The compound interest is: %f\n", compoundInterest);

return 0;

[Link]:

Enter the principal amount: 500.00

Enter the rate of interest (in percentage): 5.0

Enter the number of times that interest is compounded per year: 4

Enter the time in years: 4.0

The amount after 4.000000 years is: 609.945251

The compound interest is: 109.945251


Page No.

PROGRAM NO 11
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to find the third angle of a triangle if two


angles are given.
2. PROGRAM:

#include <stdio.h>

int main() {

int a, b, c;

printf("enter the first angle of a triangle=");

scanf("%d", &a);

printf("enter the second angle of the triangle=");

scanf("%d", &b);

printf("enter the third angle of the triangle=%d", c=180- ( a+ b));


return 0;

[Link]:

enter the first angle of a triangle= 60

enter the second angle of the triangle=50

enter the third angle of the triangle=70


Page No.

PROGRAM NO 12
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to enter any number and calculate its


square root.
2. PROGRAM:

#include <stdio.h>

#include <math.h>

int main() {

float number, squareRoot;

printf("Enter a number: ");

scanf("%f", &number);

if (number < 0) {

printf("invalid input\n");
} else {

squareRoot = sqrt(number);

printf("The square root of %f is: %f\n", number, squareRoot);

return 0;

[Link]:

Enter a number: 324.00

The square root of 324.000000 is: 18.000000


Page No.

PROGRAM NO 13
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program using conditional operators.

2. PROGRAM:

#include <stdio.h>

int main() {

int num;

printf("Enter an integer: ");

scanf("%d", &num);

(num % 2 == 0) ? printf("%d is even.\n", num) : printf("%d is odd.\n", num);

return 0;

[Link]:

Enter an integer: 5

5 is odd.
Page No.

PROGRAM NO 14
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to find the maximum between two num-


bers using conditional operator.
2. PROGRAM:

#include <stdio.h>

int main () {

int a, b, max;

printf("enter first number =");

scanf("%d", &a);

printf("enter second number =");

scanf("%d", &b);

max= ((a>b)? a:b);


printf("maximum of %d and %d is %d", a, b, max);

return 0;

[Link]:

enter first number =56

enter second number =32

maximum of 56 and 32 is 56
Page No.

PROGRAM NO 15
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to find the maximum between three num-


ber using conditional operator.
2. PROGRAM:

#include <stdio.h>

int main () {

int a, b, c, max;

printf("enter first number =");

scanf("%d", &a);

printf("enter second number =");

scanf("%d", &b);

printf("enter third number =");


scanf("%d", &c);

max= (a>b? (a>c?a:c):(b>c?b:c));

printf("maximum of %d, %d and %d is %d", a, b, c, max);

return 0;

[Link]:

enter first number = 23

enter second number = 52

enter third number = 45

maximum of 23, 52 and 45 is 52


Page No.

PROGRAM NO 16
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to check whether a number is odd or


even using conditional operator.

2. PROGRAM:

#include <stdio.h>

int main () {

int a;

printf("enter the number =");

scanf("%d", &a);

(a%2==0? printf("%d is even ", a) : printf("%d is odd ", a));

return 0;

[Link]:

enter the number = 13

13 is odd
Page No.

PROGRAM NO 17
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to find the size and range of different


data types using sizeof operator.
2. PROGRAM:

#include <stdio.h>

#include<limits.h>

#include<float.h>

int main(){

printf("size of int : %lu bytes\n",sizeof(int));

printf ("range of int %d to %d\n\n",INT_MIN,INT_MAX);

printf("size of char : %lu bytes\n",sizeof(char));


printf("range of char %d to %d\n\n",CHAR_MIN,CHAR_MAX);

printf("size of short int : %lu bytes\n",sizeof(short int));

printf("range of short int %d to %d\n\n",SHRT_MIN,SHRT_MAX);

printf("size of long int : %lu bytes\n",sizeof(long int));

printf("range of long int %d to %d\n\n",LONG_MIN,LONG_MAX);

printf("size of float : %lu bytes\n",sizeof(float));

printf("range of float %d to %d\n\n",FLT_MIN,FLT_MAX);


printf("size of double : %lu bytes\n",sizeof(double));

printf("range of double %d to %d\n\n",DBL_MIN,DBL_MAX);

printf ("size of long double: %lu bytes\n",sizeof(long double));

printf ("range of long double %d to %d\n\n",LDBL_MIN,LDBL_MAX);

return 0;

[Link]:

size of int : 4 bytes

range of int -2147483648 to 2147483647

size of char : 1 bytes

range of char -128 to 127

size of short int : 2 bytes

range of short int -32768 to 32767

size of long int : 4 bytes

range of long int -2147483648 to 2147483647

size of float : 4 bytes

range of float 0 to -536870912

size of double : 8 bytes

range of double 0 to -1

size of long double: 16 bytes


range of long double -2101347744 to -2101347760
Page No.

PROGRAM NO 18
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to check whether a year is leap year or


not using if-else.
2. PROGRAM:

#include <stdio.h>

int main () {

int year;

printf("enter the year=");

scanf("%d", &year);

if(year%400||year!=100&&year%4==0)

printf("%d is a leap year \n", year);

else
printf("%d is not a leap year", year);

return 0;

[Link]:

enter the year=2024

2024 is a leap year


Page No.

PROGRAM NO 19
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to check whether a number is divisible by


some other number using if-else.
2. PROGRAM:

#include <stdio.h>

int main() {

int num1, num2;

printf("Enter the first number: ");

scanf("%d", &num1);

printf("Enter the second number: ");

scanf("%d", &num2);

if (num1 % num2 == 0)
printf("%d is divisible by %d\n", num1,num2);

else

printf("%d is not divisible by %d\n", num1, num2);

return 0;

[Link]:

Enter the first number: 19

Enter the second number: 5

19 is not divisible by 5
Page No.

PROGRAM NO 20
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: Write a program to check whether a character is alphabet,


digit or special character using if-else.
2. PROGRAM:

#include <stdio.h>

int main() {

char x;

printf("enter the character = ");

scanf("%c", &x);

if(x>='0'&&x<='9')

printf("%c is a digit", x);

else if((x>='A'&&x<='Z')||(x>='a'&&x<='z'))
printf("%c is an alphabet", x);

else

printf("%c is a special character", x);

return 0;

[Link]:

enter the character = *

* is a special character
Page No.

PROGRAM NO 21
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: WAP to input basic salary of an employee and calculate


gross salary according to given conditions,
Basic Salary <= 10000 : HRA = 20%, DA = 80%

Basic Salary is between 10001 to 20000 : HRA = 25%, DA = 90%

Basic Salary >= 20001 : HRA = 30%, DA = 95%

2. PROGRAM:

#include<stdio.h>

int main()

float bs, gs, HRA, DA;

printf("enter the basic salary of employee=");

scanf("%f", &bs);

if (bs <= 10000)

HRA = bs * 20 / 100;

DA = bs * 80 / 100;

else if (bs > 10000 && bs <= 20000)

HRA = bs * 25 / 100;
DA = bs * 90 / 100;

if (bs > 20000)

HRA = bs * 30 / 100;

DA = bs * 95 / 100;

gs = bs + HRA + DA;

printf("gross salary of the employee=%.2f",gs);

return 0;

[Link]:

enter the basic salary of employee=21000.00

gross salary of the employee=47250.00


Page No.

PROGRAM NO 22
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: write a c program to check whether an alphabet is vowel


or consonant using switch case.
2. PROGRAM:

#include <stdio.h>

int main()

char ch;

printf("enter an alphabet= ");

scanf(" %c", &ch);

if (ch >= 65 && ch <= 90)

ch = ch + 32;

switch (ch)

case 'a':

case 'e':

case 'i':

case 'o':
case 'u':

printf("%c is a vowel!\n", ch);

break;

default:

if ((ch >= 'a' && ch <= 'z'))

printf("%c is a consonant!\n", ch);

else

printf("invalid input!\n");

break;

return 0;

[Link]:

enter an alphabet= Z

z is a consonant!
Page No.

PROGRAM NO 23
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: write a program to check whether a number is positive,


negative or zero using switch case.
2. PROGRAM:

#include <stdio.h>

int main()

int num;

printf("enter a number= ");

scanf("%d", &num);

if (num > 0)

num = 1;

if (num == 0)

num = 0;

if (num < 0)

num = 2;

}
switch (num)

case 0:

printf("zero");

break;

case 1:

printf("positive number!\n");

break;

case 2:

printf("negative number!\n");
break;

default:

printf("invalid\n");

break;

return 0;

[Link]:

enter a number= -45

negative number!
Page No.

PROGRAM NO 24
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: write a program to input electricity unit charges and calcu-


late total electricity bill according to the given condition .
For first 50 units Rs 0.75/unit

For next 100 units Rs 0.75/unit

For next 100 units Rs 1.20/unit

For unit above 250 Rs 1.50/unit

An additional surcharge of 20% is added to the bill.

2. PROGRAM:

#include <stdio.h>

int main()

float unit, sc, bill, tbill;

printf("enter the units = ");

scanf("%f", &unit);

if (unit <= 50)

bill = unit * 0.50;

else if (unit <= 150)

bill = (unit - 50) * 0.75 + 50 * 0.50;


}

else if (unit <= 250)

bill = (unit - 150) * 1.20 + 100 * 0.75 + 50 * 0.50;

else

bill = (unit - 250) * 1.50 + 100 * 1.20 + 100 * 0.75 + 50 * 0.50;

sc = bill * 20 / 100;
tbill = bill + sc;

printf("total electricity bill =Rs.%.2f\n”,tbill);

return 0;

[Link]:

enter the units = 300

total electricity bill =Rs.354.00


Page No.

PROGRAM NO 25
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: write a program to input cost price and selling price of a


product and check profit or loss using if-else.
2. PROGRAM:

#include <stdio.h>

int main()

float cp, sp, profit, loss;

printf("enter the cost price = Rs. ");

scanf("%f", &cp);

printf("enter the selling price = Rs. ");

scanf("%f", &sp);

if (sp > cp)

profit = sp - cp;

printf("we have a profit of Rs.%.2f", profit);

if (sp < cp)

loss = cp - sp;

printf("we have a loss of Rs.%.2f", loss);

}
if (sp == cp)

printf("no profit no loss!");

return 0;

[Link]:

enter the cost price = Rs. 45

enter the selling price = Rs. 45

no profit no loss!
Page No.

PROGRAM NO 26
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE: write a program to find frequency of each digit in a given


integer.
2. PROGRAM:

#include <stdio.h>

void findDigitFrequency(int num)

int frequency[10] = {0};

if (num < 0)

num = -num;

while (num > 0)

int digit = num % 10;

frequency[digit]++;

num /= 10;

printf("Digit Frequency:\n");

for (int i = 0; i < 10; i++)

{
if (frequency[i] > 0)

printf("Digit %d: %d times\n", i, frequency[i]);

int main()

int num;

printf("Enter an integer: ");

scanf("%d", &num);

findDigitFrequency(num);

return 0;

[Link]:

Enter an integer: 76658888

Digit Frequency:

Digit 5: 1 times

Digit 6: 2 times

Digit 7: 1 times

Digit 8: 4 times
Page No.

PROGRAM NO 27
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE:write a c program to print all Armstrong numbers between


given interval using functions.

2. PROGRAM:
#include <stdio.h>

#include <math.h>

int getNumberOfDigits(int num)

int count = 0;

while (num != 0)

num /= 10;

count++;

return count;

int isArmstrong(int num)

int originalNum = num;

int sum = 0;

int digits = getNumberOfDigits(num);

while (num != 0)

{
int digit = num % 10;

sum += pow(digit, digits);

num /= 10;

return (sum == originalNum);

void printArmstrongNumbersInRange(int start, int end)

printf("Armstrong numbers between %d and %d are:\n", start, end);

for (int num = start; num <= end; num++)


{

if (isArmstrong(num))

printf("%d ", num);

printf("\n");

int main()

int start, end;

printf("Enter the starting number of the interval: ");

scanf("%d", &start);

printf("Enter the ending number of the interval: ");

scanf("%d", &end);

printArmstrongNumbersInRange(start, end);

return 0;

[Link]:

Enter the starting number of the interval: 100

Enter the ending number of the interval: 1000


Armstrong numbers between 100 and 1000 are:

153 370 371 407


Page No.

PROGRAM NO 28
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE:write a c program to find all prime numbers between given


interval using functions.

2. PROGRAM:
#include <stdio.h>

#include <stdbool.h>

bool isPrime(int num) {

if (num <= 1) {

return false;

for (int i = 2; i * i <= num; i++) {

if (num % i == 0) {

return false;

return true;

void printPrimesInRange(int start, int end) {

printf("Prime numbers between %d and %d are:\n", start, end);

for (int num = start; num <= end; num++) {

if (isPrime(num)) {

printf("%d ", num);

}
}

printf("\n");

int main() {

int start, end;

printf("Enter the starting number of the interval: ");

scanf("%d", &start);

printf("Enter the ending number of the interval: ");

scanf("%d", &end);

printPrimesInRange(start, end);
return 0;

[Link]:

Enter the starting number of the interval: 1

Enter the ending number of the interval: 100

Prime numbers between 1 and 100 are:

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Page No.

PROGRAM NO 29
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE:write a c program to find the factorial of any number using


tail recursion.

2. PROGRAM:
#include <stdio.h>

long long factorial(int n, long long result) {

if (n == 0 || n == 1) {

return result;

return factorial(n - 1, n * result);

int main() {

int num;

printf("Enter a number: ");

scanf("%d", &num);

long long fact = factorial(num, 1);

printf("Factorial of %d is %lld\n", num, fact);

return 0;

[Link]:

Enter a number: 5

Factorial of 5 is 120
Page No.

PROGRAM NO 30
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE:Write a C program to find GCD (HCF) and LCM of two num-


bers using recursion.

2. PROGRAM:
#include <stdio.h>

int gcd(int a, int b) {

if (b == 0) {

return a;

return gcd(b, a % b);

int lcm(int a, int b) {

return (a * b) / gcd(a, b);

int main() {

int num1, num2;

printf("Enter two numbers: ");

scanf("%d %d", &num1, &num2);

int gcd_result = gcd(num1, num2);

int lcm_result = lcm(num1, num2);

printf("GCD of %d and %d is: %d\n", num1, num2, gcd_result);

printf("LCM of %d and %d is: %d\n", num1, num2, lcm_result);

return 0;
}

[Link]:

Enter two numbers: 51 70

GCD of 51 and 70 is: 1

LCM of 51 and 70 is: 3570


Page No.

PROGRAM NO 31
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE:Write a C program to count total number of even and odd


elements in an array.

2. PROGRAM:

#include <stdio.h>

int main() {

int n;

printf("Enter the number of elements in the array: ");

scanf("%d", &n);

int arr[n];

printf("Enter %d elements:\n", n);

for (int i = 0; i < n; i++) {

scanf("%d", &arr[i]);
}

int evenCount = 0, oddCount = 0;

for (int i = 0; i < n; i++) {

if (arr[i] % 2 == 0) {

evenCount++;

} else {

oddCount++;

printf("Total even numbers: %d\n", evenCount);


printf("Total odd numbers: %d\n", oddCount);

return 0;

[Link]:

Enter the number of elements in the array: 10

Enter 10 elements:

4
5

10

Total even numbers: 5

Total odd numbers: 5


Page No.

PROGRAM NO 32
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE:Write a C program to find and interchange the biggest/


smallest element in an array of N elements

2. PROGRAM:
#include <stdio.h>

int main() {

int n;

printf("Enter the number of elements in the array: ");

scanf("%d", &n);

int arr[n];

printf("Enter %d elements:\n", n);

for (int i = 0; i < n; i++) {

scanf("%d", &arr[i]);

int largestIndex = 0, smallestIndex = 0;

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

if (arr[i] > arr[largestIndex]) {

largestIndex = i;

if (arr[i] < arr[smallestIndex]) {

smallestIndex = i;

}
printf("Largest element is %d at index %d\n", arr[largestIndex], largestIndex);

printf("Smallest element is %d at index %d\n", arr[smallestIndex], smallestIn-


dex);

int temp = arr[largestIndex];

arr[largestIndex] = arr[smallestIndex];

arr[smallestIndex] = temp;

printf("Array after interchanging largest and smallest elements:\n");

for (int i = 0; i < n; i++) {

printf("%d ", arr[i]);

}
printf("\n");

return 0;

[Link]:

Enter the number of elements in the array: 6

Enter 6 elements:

12

14

77

Largest element is 77 at index 3

Smallest element is 1 at index 5

Array after interchanging largest and smallest elements:

12 14 4 1 8 77
Page No.

PROGRAM NO 33
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE:Write a C program to read elements in two matrices and


multiply them.

2. PROGRAM:

#include <stdio.h>

void readMatrix(int matrix[][10], int rows, int cols, const char *name) {

printf("Enter elements of matrix %s (%dx%d):\n", name, rows, cols);

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

printf("Element [%d][%d]: ", i + 1, j + 1);

scanf("%d", &matrix[i][j]);

}
}

void printMatrix(int matrix[][10], int rows, int cols) {

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

printf("%d ", matrix[i][j]);

printf("\n");

}
void multiplyMatrices(int mat1[][10], int mat2[][10], int result[][10], int r1, int c1,
int c2) {

for (int i = 0; i < r1; i++) {

for (int j = 0; j < c2; j++) {

result[i][j] = 0; // Initialize result cell to 0

for (int k = 0; k < c1; k++) {

result[i][j] += mat1[i][k] * mat2[k][j];

}
}

int main() {

int r1, c1, r2, c2;

int mat1[10][10], mat2[10][10], result[10][10];

printf("Enter rows and columns for the first matrix: ");

scanf("%d %d", &r1, &c1);

printf("Enter rows and columns for the second matrix: ");

scanf("%d %d", &r2, &c2);

if (c1 != r2) {

printf("Matrix multiplication not possible! Number of columns in first matrix


must equal number of rows in second matrix.\n");

return 1;

readMatrix(mat1, r1, c1, "A");

readMatrix(mat2, r2, c2, "B");

multiplyMatrices(mat1, mat2, result, r1, c1, c2);


printf("Resultant matrix after multiplication:\n");

printMatrix(result, r1, c2);

return 0;

[Link]:

Enter rows and columns for the first matrix: 2 3


Enter rows and columns for the second matrix: 3 2

Enter elements of matrix A (2x3):

Element [1][1]: 1

Element [1][2]: 2

Element [1][3]: 3

Element [2][1]: 4

Element [2][2]: 5

Element [2][3]: 6

Enter elements of matrix B (3x2):

Element [1][1]: 7

Element [1][2]: 8

Element [2][1]: 9

Element [2][2]: 10

Element [3][1]: 11

Element [3][2]: 12

Resultant matrix after multiplication:

58 64

139 154
Page No.

PROGRAM NO 34
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE:Develop a program to check whether given string is palin-


drome or not.

2. PROGRAM:

#include <stdio.h>

#include <string.h>

#include <ctype.h>

int isPalindrome(char str[]) {

int start = 0;

int end = strlen(str) - 1;

while (start < end) {

while (start < end && !isalnum(str[start])) {

start++;

while (start < end && !isalnum(str[end])) {

end--;

if (tolower(str[start]) != tolower(str[end])) {

return 0;

}
start++;

end--;

return 1;

int main() {

char str[100];

printf("Enter a string: ");


fgets(str, sizeof(str), stdin);

str[strcspn(str, "\n")] = '\0';

if (isPalindrome(str)) {

printf("\"%s\" is a palindrome.\n", str);

} else {

printf("\"%s\" is not a palindrome.\n", str);

return 0;

[Link]:

Enter a string: A man, a plan, a canal: Panama

"A man, a plan, a canal: Panama" is a palindrome.


Page No.

PROGRAM NO 35
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE:Create a structure called "Student" with members name,


age, and total marks. Write a C program to input data for two stu-
dents, display their information, and find the average of total marks.

2. PROGRAM:

#include <stdio.h>

#include<string.h>

struct Student {

char name[50];

int age;

float totalMarks;

};

int main() {
struct Student student1, student2;

float averageMarks;

printf("Enter details for Student 1:\n");

printf("Name: ");

fgets([Link], sizeof([Link]), stdin);

[Link][strcspn([Link], "\n")] = '\0';

printf("Age: ");

scanf("%d", &[Link]);
printf("Total Marks: ");

scanf("%f", &[Link]);

getchar();

printf("\nEnter details for Student 2:\n");

printf("Name: ");

fgets([Link], sizeof([Link]), stdin);

[Link][strcspn([Link], "\n")] = '\0';

printf("Age: ");

scanf("%d", &[Link]);
printf("Total Marks: ");

scanf("%f", &[Link]);

printf("\nStudent 1 Details:\n");

printf("Name: %s\n", [Link]);

printf("Age: %d\n", [Link]);

printf("Total Marks: %.2f\n", [Link]);

printf("\nStudent 2 Details:\n");

printf("Name: %s\n", [Link]);

printf("Age: %d\n", [Link]);

printf("Total Marks: %.2f\n", [Link]);

averageMarks = ([Link] + [Link]) / 2;

printf("\nAverage Total Marks: %.2f\n", averageMarks);

return 0;

[Link]:
Enter details for Student 1:

Name: pramod

Age: 99

Total Marks: 21.5

Enter details for Student 2:

Name: aithani

Age: 98

Total Marks: 20.5

Student 1 Details:

Name: pramod

Age: 99

Total Marks: 21.50

Student 2 Details:

Name: aithani

Age: 98

Total Marks: 20.50

Average Total Marks: 21.00


Page No.

PROGRAM NO 36
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE:Define a structure named Time with members hours, min-


utes, and seconds. Write a C program to input two times, add them,
and display the result in proper time format.

2. PROGRAM:

#include <stdio.h>

struct Time {

int hours;

int minutes;

int seconds;

};

struct Time addTimes(struct Time t1, struct Time t2) {

struct Time result;

[Link] = [Link] + [Link];

[Link] = [Link] + [Link] + ([Link] / 60);

[Link] %= 60;

[Link] = [Link] + [Link] + ([Link] / 60);

[Link] %= 60;

[Link] %= 24;
return result;

int main() {

struct Time time1, time2, result;

printf("Enter the first time (hours minutes seconds): ");

scanf("%d %d %d", &[Link], &[Link], &[Link]);

printf("Enter the second time (hours minutes seconds): ");

scanf("%d %d %d", &[Link], &[Link], &[Link]);

result = addTimes(time1, time2);

printf("\nThe resultant time is: %02d:%02d:%02d\n", [Link], [Link]-


utes, [Link]);

return 0;

[Link]:

Enter the first time (hours minutes seconds): 1 30 30

Enter the second time (hours minutes seconds): 2 45 25

The resultant time is: 04:15:55


Page No.

PROGRAM NO 37
NAME: PRAMOD AITHANI

COURSE: BCA

SEMESTER:1ST

ROLL NO. :20

DATE:

1. OBJECTIVE:Create a structure named "Employee" to store employee de-


tails such as employee ID, name, and salary. Write a program to input
data for three employees, find the highest salary employee, and dis-
play their information.

2. PROGRAM:

#include <stdio.h>

#include <string.h>

struct Employee {

int id;

char name[50];

float salary;

};

int main() {
struct Employee employees[3], highestSalaryEmployee;

printf("Enter details for 3 employees:\n");

for (int i = 0; i < 3; i++) {

printf("\nEmployee %d:\n", i + 1);

printf("ID: ");

scanf("%d", &employees[i].id);

getchar();

printf("Name: ");

fgets(employees[i].name, sizeof(employees[i].name), stdin);

employees[i].name[strcspn(employees[i].name, "\n")] = '\0';


printf("Salary: ");

scanf("%f", &employees[i].salary);

highestSalaryEmployee = employees[0];

for (int i = 1; i < 3; i++) {

if (employees[i].salary > [Link]) {

highestSalaryEmployee = employees[i];

printf("\nEmployee with the highest salary:\n");


printf("ID: %d\n", [Link]);

printf("Name: %s\n", [Link]);

printf("Salary: %.2f\n", [Link]);

return 0;

[Link]:

Enter details for 3 employees:

Employee 1:

ID: 11

Name: pramod

Salary: 1000

Employee 2:

ID: 12

Name: prakash

Salary: 2000

Employee 3:

ID: 13

Name: pradeep

Salary: 3000
Employee with the highest salary:

ID: 13

Name: pradeep

Salary: 3000.00

You might also like