0% found this document useful (0 votes)
19 views31 pages

Practical File

The document outlines a series of practical programming exercises for a BCA course, detailing aims, steps, coding examples, and expected outputs for each task. Each practical focuses on fundamental programming concepts using C, including displaying strings, user input, arithmetic operations, and control structures. The exercises culminate in tasks such as calculating simple interest, swapping numbers, and implementing a basic calculator.

Uploaded by

ashkum2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views31 pages

Practical File

The document outlines a series of practical programming exercises for a BCA course, detailing aims, steps, coding examples, and expected outputs for each task. Each practical focuses on fundamental programming concepts using C, including displaying strings, user input, arithmetic operations, and control structures. The exercises culminate in tasks such as calculating simple interest, swapping numbers, and implementing a basic calculator.

Uploaded by

ashkum2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

NAME : ASHISH KUMAR

COURSE : BCA
ID : 202505
BATCH : 2025 – 28
SEMESTER : 1
SUBJECT : PPS
TEACHER : Dr. Pri Sharma
Practical-1

Aim: Program to display “Hello”.


STEPS:
1. Open turbo c
2. Create a new file
3. Display a string “hello” using printf()
4. Save program by pressing F2.
5. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include <stdio.h>
int main(){
printf("Hello");
return 0;
}

OUTPUT:
Practical-2

Aim: Program to display Name, DOB and Address.


STEPS:
1. Display a string “NAME” using printf () function.
2. Display a string “DOB” using printf () function.
3. Display a string “ADDRESS” using printf () function.
4. Save program by pressing F2.
5. Compile (Alt + F9) and run (Ctrl+ F9) to see the output

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
clrscr();
printf(" \n NAME: Ashish Kumar");
printf(" \n DOB: 18/12/2007");
printf(" \n LOC:DEVLI”);
getch();
return 0;
}

OUTPUT:
Practical-3

Aim: Program to ask the user for Empid, Age, Salary and display the same.
STEPS:
1. Declare the variables in main using different data types.
2. Take employee id by user using scanf() function.
3. Take name from the user by using scanf() function.
4. Take age as input from the user by using scanf() function.
5. Take salary by the user by using scanf() function.
6. Display all the details taken by user using printf() function.
7. Save program by pressing F2.
8. Compile (Alt + F9) and run (Ctrl+ F9) to see the output

CODING:
#include<stdio.h>
#include<conio.h>
int main (){
int empid,age;
float salary;
clrscr();
printf("Enter Employee Id:");
scanf("%d",&empid);
printf("Enter Employee Age:");
scanf("%d",&age);
printf("Enter Salary of Employee: ");
scanf("%f",&salary);
printf("\n\n Employee Details:\n Emp Id:%d \n Employee Age:%d \n Salary of
Employee:%f",empid,age,salary);
getch();
return 0;
}

OUTPUT:
Practical-4

Aim: Program to generate the following table:


1992 29210
1993 17421
1994 100523

STEPS:
1. Use printf() function to display the series.
2. Use \n for new line and \t for tab.
3. By using \t and \n display the above mentioned table.
4. Save program by pressing F2.
5. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
clrscr();
printf(" \n 1992 \t 29210 ");
printf(" \n 1993 \t 17421 ");
printf(" \n 1994 \t 100523 ");
getch();
return 0;
}

OUTPUT:
Practical-5

Aim: Program to calculate sum of 5 subjects and find percentage.


STEPS:
1. Declare the variables in main() using correct data types.
2. Declare 5 variables for marks of five different subjects, one for percentage and one for
total.
3. Take the marks as input from the user using scanf() function.
4. Add marks of all the subjects using ‘+’ arithmetic operator and add the value in total.
5. Apply the logic for percentage using different arithmetic operators.
6. Display the total and percentage using printf() function.
7. Save program by pressing F2.
8. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
int main(){
int s1,s2,s3,s4,s5;
float sum,percent;
printf("Enter Marks of First Subject:");
scanf("%d",&s1);
printf("Enter Marks of Second Subject:");
scanf("%d",&s2);
printf("Enter Marks of Third Subject:");
scanf("%d",&s3);
printf("Enter Marks of Forth Subject:");
scanf("%d",&s4);
printf("Enter Marks of Fifth Subject:");
scanf("%d",&s5);
sum=s1+s2+s3+s4+s5;
percent=(sum/500)*100;
printf("\n Sum of Five Subjects :%f",sum);
printf("\n Percentage of Five Subject:%f",percent);
return 0;
}

OUTPUT:
Practical-6

Aim: Program to find simple interest.

STEPS:
1. Declare the variables in main with correct data types.
2. Take the values from the user by using scanf() function.
3. Apply the formula of calculating the simple interest.
4. Display the simple interest to user by printf() function.
5. Save program by pressing F2.
6. Compile (Alt + F9) and run (Ctrl+ F9) to see the output

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
int p,t;
float r,si;
clrscr();
printf("Enter Value of Principle: ");
scanf("%d",&p);
printf("Enter Value of Rate of Interest: ");
scanf("%f",&r);
printf("Enter Value of Time: ");
scanf("%d",&t);
si=(p*r*t)/100;
printf(" Value of SI :%f",si);
getch();
return 0;
}

OUTPUT:
Practical-7

Aim: Program to swap two numbers using third variable.

STEPS:
1. Declare the variables in main with correct data types.
2. Take the values from the user by using scanf() function.
3. First store the value of a in temp.
4. Then store the value of b in a.
5. Then store the value of temp in b.
6. Display the result using printf() function.
7. Save program by pressing F2.
8. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
int a,b,temp;
clrscr();
printf("\n Enter Value of A: ");
scanf("%d",&a);
printf("\n\n Enter Value of B: ");
scanf("%d",&b);
temp=a;
a=b;
b=temp;
printf("\n Value of A :%d",a);
printf("\n Value of B :%d",b);
getch();
return 0;
}

OUTPUT:
Practical-8

Aim: Program to convert temperature from Celsius to Fahrenheit by taking


input from user.

STEPS:
1. Declare the variables in main with correct data types.
2. Take the values from the user by using scanf() function.
3. Apply the formula for converting degree centigrade to Fahrenheit.
4. Display the result using printf() function.
5. Save program by pressing F2.
6. Compile (Alt + F9) and run (Ctrl+ F9) to see the output

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
float tempc,tempf;
clrscr();
printf("Enter Temperature in Celsius: ");
scanf("%f",&tempc);
tempf=(1.8*tempc)+32;
printf("\n Temperature in Fahrenheit : %f",tempf);
getch();
return 0;
}

OUTPUT:
Practical-9

Aim: Program to swap two numbers without using third variable.

STEPS:
1. Declare the variables in main with correct data types.
2. Take the values from the user by using scanf() function.
3. First store the value of a + b in a.
4. Then store value of a-b in b.
5. Then store value of a-b in a.
6. Display the result using printf() function.
7. Save program by pressing F2.
8. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
int a,b;
clrscr();
printf("\n Enter Value of A: ");
scanf("%d",&a);
printf("\n Enter Value of B: ");
scanf("%d",&b);
a=a+b;
b=a-b;
a=a-b;
printf(" \n Value of A :%d",a);
printf(" \n Value of B :%d",b);
getch();
return 0;
}

OUTPUT:
Practical-10

Aim: Program to find whether given number is even or odd.

STEPS:
1. Declare the variables in main with correct data types.
2. Take the values from the user by using scanf() function.
3. Use if else statement for different conditions.
4. Divide number by 2 and if remainder is equal to zero then it is an even number.
5. Display the result using printf() function.
6. Save program by pressing F2.
7. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
int n;
clrscr();
printf("\n Enter a number: ");
scanf("%d", &n);
if (n%2 == 0)
{
printf(" \n Entered Number is Even");
}
else
{
printf("\n Entered Number is Odd");
}
getch();
return 0;
}

OUTPUT:
Practical-11

Aim: Program to find the greatest number among 3 numbers given by the
user.

STEPS:
1. Declare the variables in main with correct data types.
2. Take the values from the user by using scanf() function.
3. Use if else statements for different conditions.
4. Display the result using printf() function.
5. Save program by pressing F2.
6. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
int num1,num2,num3;
clrscr();
printf("\n Enter Value of first number: ");
scanf("%d",&num1);
printf("\n Enter Value of second number: ");
scanf("%d",&num2);
printf("\n Enter Value of third number: ");
scanf("%d",&num3);
if((num1>num2)&&(num1>num3))
{
printf("\n %d is Greatest",num1);
}
else if((num2>num1)&&(num2>num3))
{
printf("\n %d is Greatest",num2);
}
else
{
printf("\n %d is Greatest",num3);
}
getch();
return 0;
}

OUTPUT:
Practical-12

Aim: Program to find that the entered year is a Leap year or not.

STEPS:
1. Declare the variables in main with correct data types.
2. Take the values from the user by using scanf() function.
3. Use if else statement for different conditions.
4. Divide year by 4 and if remainder is equal to zero then its a leap year.
5. Display the result using printf() function.
6. Save program by pressing F2.
7. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
# include<stdio.h>
# include<conio.h>
int main(){
int year;
clrscr();
printf("Enter Year:");
scanf("%d", &year);
if(year%4==0)
{
printf("\n Entered year is a leap year");
}
else
{
printf("\n Entered year is not a leap year");
}
getch();
return 0;
}

OUTPUT:
Practical-13

Aim: Program to use Switch Statement to display Monday to Sunday.

STEPS:
Declare the variables in main with correct data types.
Take the value from the user by using scanf() function.
Use switch statement for different conditions.
Take case 1 for Monday and case 7 for Sunday.
Take last case as default for wrong choice.
Display the result using printf() function.
Save program by pressing F2.
Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
int day;
clrscr();
printf("\n Enter day(1-7): ");
scanf("%d",&day);
switch(day){
case 1: printf("Monday");
break;
case 2: printf("Tuesday");
break;
case 3: printf("Wednesday");
break;
case 4: printf("Thursday");
break;
case 5: printf("Friday");
break;
case 6: printf("Saturday");
break;
case 7: printf("Sunday");`
break;
default : printf("Invalid Choice");
}
getch();
return 0;
}

OUTPUT:
Practical-14

Aim: Program to perform basic arithmetic operations/calculator using


switch case.

STEPS:
1. Declare the variables in main with correct data types.
2. Take the values from the user by using scanf() function.
3. Use switch statement for different conditions.
4. Use case 1 for Addition, case 2 for Subtraction, case 3 for Multiplication, case 4 for
Division and case 5 for Modulus.
5. Use last case as default for Invalid Choice.
6. Display the result using printf() function.
7. Save program by pressing F2.
8. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
int num1,num2,res,choice;
clrscr();
printf("\n Enter First Number: ");
scanf("%d",&num1);
printf("\n Enter Second Number: ");
scanf("%d",&num2);
printf("\n Enter 1 for Add:");
printf("\n Enter 2 for Sub:");
printf("\n Enter 3 for Mult:");
printf("\n Enter 4 for Div: ");
printf("\n Enter 5 for Mod: ");
printf("\n Enter your choice from 1 to 5: ");
scanf("%d",&choice);
switch(choice){
case 1:res=num1+num2;
printf("\n Result is : %d",res);
break;
case 2:res=num1-num2;
printf("\n Result is : %d",res);
break;
case 3:res=num1*num2;
printf("\n Result is : %d",res);
break;
case 4:res=num1/num2;
printf("\n Result is : %d",res);
break;
case 5:res=num1%num2;
printf("\n Result is : %d",res);
break;
default: printf("\n Invalid Choice ");
}
getch();
return 0;
}

OUTPUT:
Practical-15

Aim: Program to display first 10 Natural Nos.

STEPS:
Declare the variables in main with correct data types.
Write a for loop with condition i=1, i<=10 and i++.
The above mentioned for loop will run 10 times .
In for loop print the variable i using printf() function.
Save program by pressing F2.
Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
int i;
clrscr();
for(i=1;i<=10;i++)
{
printf("\n%d",i);
}
getch();
return 0;
}

OUTPUT:
Practical-16

Aim: Program to display Even Numbers between 1 to 100.

STEPS:
Declare the variables in main with correct data types.
Write a for loop with condition i=1, i<=100 and i++.
Use if else statement to check the condition.
Divide number by 2 and if remainder is equal to zero then it is an even number.
In for loop print the variable i using printf() function.
Save program by pressing F2.
Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
int i;
clrscr();
for(i=1;i<=100;i++)
{
if(i%2==0)
{
printf("%d ",i);
}
}
getch();
return 0;
}

OUTPUT:
Practical-17

Aim: Program to print table of a number entered by user.

STEPS:
8. Declare the variables in main with correct data types.
9. Run the for loop 10 times.
10. Multiply the table by the value of i.
11. In for loop print the table using printf() function.
12. Save program by pressing F2.
13. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
int i,num;
clrscr();
printf("Enter a number to print its table: ");
scanf("%d",&num);
for(i=1;i<=10;i++)
{
printf(" \n%d * %d = %d",num,i,num*i);
}
getch();
return 0;
}

OUTPUT:
Practical-18

Aim: Program to find Factorial of a Number.

STEPS:
1. Declare the variables in main with correct data types.
2. Run the loop n number of times.
3. Multiply the fact by the value of i in the loop.
4. Outside for loop print the variable fact using printf() function.
5. Save program by pressing F2.
6. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
int i,num,fact=1;
clrscr();
printf("Enter number to find its factorial: ");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
fact=fact*i;
}
printf("\nFactorial of %d is %d”,num,fact);
getch();
return 0;
}

OUTPUT:
Practical-19

Aim: Program to print Fibonacci Series.

STEPS:
1. Declare the variables in main with correct data types.
2. Run the loop n number of times.
3. Write the logic according to the statement in loop.
4. In for loop print the variable a using printf() function.
5. Save program by pressing F2.
6. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
int n,i,a=0,b=1,c;
clrscr();
printf("Enter no. of terms: ");
scanf("%d ",&n);
for(i=1;i<=n;i++)
{
printf("%d ",a);
c=a+b;
a=b;
b=c;
}
getch();
return 0;
}

OUTPUT:
Practical-20

Aim: Program to find whether a number entered by user is Prime or not.

STEPS:
1. Declare the variables in main with correct data types.
2. Run the loop from 2 to n-1.
3. Apply the respective conditions for finding prime number.
4. Inside the if else statement print the number is prime or not using printf() function.
5. Save program by pressing F2.
6. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
int n,i,isprime=1;
clrscr();
printf("Enter a number: ");
scanf("%d",&n);
if(n<=1){
isprime=0;
}
else{
for(i=2;i<=n-1;i++)
{
if(n%i==0)
{
isprime=0;
}
}
}
if(isprime)
printf("\n%d is a Prime Number”,n);
else
printf("\n%d is not a Prime Number”,n);
getch();
return 0;
}

OUTPUT:
Practical-21

Aim: Program to shift input data by two bits to the left.

STEPS:
1. Declare the variables in main with correct data types.
2. Take the values from the user by using scanf() function.
3. Use ‘<<’ this sign to shift to left.
4. Put x<<=2 to shift left to 2 bytes.
5. Display the result using printf() function.
6. Save program by pressing F2.
7. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
int x,y;
clrscr();
printf("\n Enter an Integer Value: ");
scanf("%d",&x);
x<<=2;
y=x;
printf("\n Left shifted data is: %d ",y);
getch();
return 0;
}

OUTPUT:
Practical-22

Aim: Program to show the use of Conditional Operator.

STEPS:
1. Declare the variables in main with correct data types.
2. Take the values from the user by using scanf() function.
3. Conditional operators are ? and :
4. The true statement is written after ?
5. The false statement is written after :
6. Display the result using printf() function.
7. Save program by pressing F2.
8. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int main(){
int num1,num2,num3;
clrscr();
printf(" \n Enter the value of first number: ");
scanf("%d",&num1);
printf("\n Enter the value of second number: ");
scanf("%d",&num2);
num3=(num1==num2? printf("\nTwo numbers are equal"): printf("\nTwo numbers are not
equal"));
getch();
return 0;
}

OUTPUT:
Practical-23

Aim: Program to reverse a number.

STEPS:
1. Declare the variables in main with correct data types.
2. Run the while loop with the condition num!=0.
3. Calculate the modulus of number by 10 and then divide by 10.
4. Print the variable reversed using printf() function.
5. Save program by pressing F2.
6. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
void main()
{
long int num,reversed=0,remainder;
clrscr();
printf("\n Enter the number: ");
scanf("%ld",&num);
while(num!=0)
{
remainder=num%10;
reversed=reversed*10+remainder;
num=num/10;
}
printf(“Reversed Number: %ld”, reversed);
getch();
}

OUTPUT:
Practical-24

Aim: Program to find factorial of a number using function.

STEPS:
1. Declare the variables with correct data types.
2. Take a value from user
3. Then pass it through function parameters
4. Then using for loop find its factorial and display it.
5. Save program by pressing F2.
6. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int factorial(int);
int main(){
int n;
clrscr();
printf("\nEnter number: ");
scanf("%d",&n);
factorial(n);
getch();
return 0;
}
int factorial(n){
long int i,fact=1;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf(" \nFactorial of %d is %ld”,n,fact);
return 0;
}

OUTPUT:
Practical-25

Aim: Program to print table of a number using function.

STEPS:
1. Declare the variables with correct data types.
2. Take a value from user
3. Then pass it through function parameters
4. Then using for loop find its table and display it.
5. Save program by pressing F2.
6. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int table(int);
int main(){
int n;
clrscr();
printf("\nEnter number: ");
scanf("%d",&n);
table(n);
getch();
return 0;}
int table(n){
int i;
for(i=1;i<=10;i++){
printf("%d * %d = %d”,n,i,n*i);
}
return 0;
}

OUTPUT:
Practical-26

Aim: Program to print Fibonacci Series up to n terms using function.

STEPS:
1. Declare the variables with correct data types.
2. Take a value from user
3. Then pass it through function parameters
4. Then using for loop print Fibonacci series and display it.
5. Save program by pressing F2.
6. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int fib(int);
int main(){
int n;
clrscr();
printf("\nEnter number: ");
scanf("%d",&n);
fib(n);
getch();
return 0;
}
int fib(n){
int a=0,b=1,c,i;
for(i=1;i<=n;i++)
{
printf("%d”,a);
c=a+b;
a=b;
b=c;
}
return 0;
}

OUTPUT:
Practical-27

Aim: Program to swap two numbers using Call by Value.

STEPS:
1. Declare the variables with correct data types.
2. First take two values from user.
3. Pass these values through arguments.
4. Then swap in into function.
5. Then display that numbers.
6. Save program by pressing F2.
7. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>

int swap(int num1,int num2)


{
int temp;
temp=num1;
num1=num2;
num2=temp;
return 0;
}
int main()
{
int num1=50,num2=70;
swap(num1,num2);
printf("\n The value of num1 is %d ",num1);
printf("\n The value of num2 is %d ",num2);
getch();
return 0;
}

OUTPUT:
Practical-28

Aim: Program to swap two numbers using Call by Reference.

STEPS:
1. Declare the variables with correct data types.
2. First take two values from user
3. Pass these values through arguments
4. Then swap in into function
5. Then display that numbers.
6. Save program by pressing F2.
7. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>

int swap(int *num1,int *num2)


{
int temp;
temp=*num1;
*num1=*num2;
*num2=temp;
return 0;
}
int main()
{
int num1=50,num2=70;
swap(&num1,&num2);
printf("\n The value of num1 is %d ",num1);
printf("\n The value of num2 is %d ",num2);
getch();
return 0;
}

OUTPUT:
Practical-29

Aim: Program to find factorial of a number using Recursion.

STEPS:
1. Declare the variables with correct data types.
2. Take a number from user
3. Then pass it by arguments in factorial function.
4. Then use if condition if n>1 calculate factorial with recursion.
5. Otherwise return 1.
6. Save program by pressing F2.
7. Compile (Alt + F9) and run (Ctrl+ F9) to see the output.

CODING:
#include<stdio.h>
#include<conio.h>
int factorial(int n);
int main()
{
int n;
clrscr();
printf("\n Enter a number to print its Factorial: ");
scanf("%d",&n);
printf("\n Factorial of %d is %d",n,factorial(n));
getch();
return 0;
}
int factorial(int n)
{
if(n>1)
{
return n*factorial(n-1);
}
else
{
return 1;
}
}

OUTPUT:

You might also like