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

Practical File

This document is a practical file for a C programming lab submitted by a student named Kartikey for the BCA 1st semester. It contains a list of 23 practical exercises, each with corresponding code examples and outputs, covering various programming concepts such as input/output, conditional statements, loops, arrays, and matrix operations. The submission date is noted as November 2nd, and it includes sections for teacher feedback and grading.

Uploaded by

yash69lite
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 views32 pages

Practical File

This document is a practical file for a C programming lab submitted by a student named Kartikey for the BCA 1st semester. It contains a list of 23 practical exercises, each with corresponding code examples and outputs, covering various programming concepts such as input/output, conditional statements, loops, arrays, and matrix operations. The submission date is noted as November 2nd, and it includes sections for teacher feedback and grading.

Uploaded by

yash69lite
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
You are on page 1/ 32

Page |1

Govt College Solan


BCA/ PGDCA Department

Practical File
Subject Title:C programming lab-I Subject Code:BCA0104(p)

No. of Pages:23

Submitted By: Submitted To:

Student Name:kartikey Teacher Name:mrs simmi sahini

Class & Sem. Bca 1st semester Date of Submission:2nd november

Class Roll No. 2305 Last date of Submission:2nd november

(For Teachers)

Signature Marks: _____________________

Remarks (If any): _____________________________________________________


Page |2

Sr.no. title Page no.


Page |3

1. Practical 1 3
2. Practical 2 4
3. Practical 3 5
4. Practical 4 6
5. Practical 5 7
6. Practical 6 8-9
7. Practical 7 10-11
8. Practical 8 12-14
9. Practical 9 15
10. Practical 10 16-17
11. Practical 11 18
12. Practical 12 19
13. Practical 13 20-21
14. Practical 14 22-23
15. Practical 15 24
16. Practical 16 25
17. Practical 17 26
18. Practical 18 27
19. Practical 19 28-29
20. Practical 20 30
21. Practical 21 31
Page |4

1. Two numbers are input through the keyboard into two locations C and D. Write a
program to interchange the contents of C and D.
#include<stdio.h>
#include<conio.h>

main()
{

int c,d;
printf("enter the value of c and d:");
scanf("%d%d",&c,&d);
int t;
t=c;
c=d;
d=t;
printf("c=%d d=%d",c,d);
getch();
}
Output:
Page |5

2. In a company an employee is paid as under:


If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary and DA = 90% of
basic salary. If his salary is either equal to or above Rs. 1500, then HRA = Rs. 500 and DA
= 98% of basic salary. If the employee's salary is input through the keyboard write a
program to find his gross salary.

#include<stdio.h>
#include<conio.h>
main()
{

int bs,hra,da;
printf("enter basic salary:");
scanf("%d",&bs);
if(bs<1500)
{

hra=10*bs/100;
da=90*bs/100;
}
else if(bs>=1500)
{
hra=500;
da=98*bs/100;
}
int gs=bs+hra+da;
printf("gross salary=%d",gs);
getch();

}
Output:
Page |6

3. If cost price and selling price of an item are input through the keyboard, write a program
to determine whether the seller has made profit or incurred loss. Also determine how
much profit he made or loss he incurred.

#include<stdio.h>
#include<conio.h>
int main()
{

int sp,cp;
printf("enter selling price and cost price:");
scanf("%d%d",&sp,&cp);
int d=sp-cp;
if(d>0)
{

printf("profit=%d",d);
}
else if(d<0)
{
d=d*-1;
printf("loss=%d",d);
}
else
{
printf("neither profit nor loss");
}

getch();
return 0;}

output:
Page |7

4. Any year is input through the keyboard. Write a program to determine whether the year
is a leap year or not. (Hint: Use the % (modulus) operator)
#include<stdio.h>
main()
{
int year;
printf("enter year:");
scanf("%d",&year);
if(year%4==0)
{
printf("%d year is a leap year\n",year);
}
else
{
printf("%d year is not a leap year\n",year);
}

}
Output:
Page |8

5. If the ages of Ram, Sham and Ajay are input through the keyboard, write a program to
determine the youngest of the three.
#include<stdio.h>
#include<conio.h>
main()
{
printf("enter age of ram shyam and ajay:");
int r,s,a;
scanf("%d%d%d",&r,&s,&a);
if(r<s && r<a)
{
printf("ram is the youngest");

if(s<r && s<a)


{ printf("shyam is the youngest");
}
if(a<r&&a<s)
{
printf("ajay is the youngest");
}
getch();
}
Output:
Page |9

6. The marks obtained by a student in 5 different subjects are input through the keyboard.
The student gets a division as per the following rules:
Percentage above or equal to 60 - First division
Percentage between 50 and 59 - Second division
Percentage between 40 and 49 - Third division
Percentage less than 40 – Fail
Write a program to calculate the division obtained by the student.
#include<stdio.h>
main()
{
int a[5],i,sum=0;
printf("enter marks in 5 subjects:");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<5;i++)
{
sum=sum+a[i];
}
int avg=sum/5;
if(avg<40)
{
printf("fail");
}
else if(avg>=40&&avg<50)
{
printf("third divison divison");
}

else if(avg>=50&&avg<60)
{
printf("second divison");
}
else
{
printf("first divison");
}
}
Output:
P a g e | 10
P a g e | 11

7. If the three sides of a triangle are entered through the keyboard, write a program to
check whether the triangle is valid or not. The triangle is valid if the sum of two sides is
greater than the largest of the three sides.

#include<stdio.h>
main()
{
printf("enter the sides of the triangle:");
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
int sum=0;;
int greatest;
if(a>c&&a>b)
{
greatest=a;
}
else
{
sum=sum+a;
}
if(a<c&&c>b)
{
greatest=c;
}
else
{
sum=sum+c;
}
if(b>c&&a<b)
{
greatest=b;
}
else
{
sum=sum+b;
}
if(sum>greatest)
{

printf("triangle is valid\n");
}
else
P a g e | 12

printf("triangle is not valid\n");

}
}
Output:
P a g e | 13

8. Write a program that receives month and date of birth as input and prints the
corresponding Zodiac sign based on the following table:
Sun Sign From - To
Capricorn December 22 - January 19
Aquarius January 20 - February 17
Pisces February 18 - March 19
Aries March 20 - April 19
Taurus April 20 - May 20
Gemini May 21 - June 20
Cancer June 21 - July 22
Leo July 23 - August 22
Virgo August 23 - September 22
Libra September 23 - October 22
Scorpio October 23 - November 21
Sagittarius November 22 - December 21

#include<stdio.h>

main()
{
int month, day;

printf("Enter your birth month(1-12)\n");


scanf("%d", &month);

printf("Enter your birth day\n");


scanf("%d", &day);

if( (month == 12 && day >= 22) || (month == 1 && day <= 19) )
{
printf("Your Zodiac Sign based on your Birth date is Capricorn\n");
}
else if( (month == 1 && day >= 20) || (month == 2 && day <= 17) )
{
printf("Your Zodiac Sign based on your Birth date is Aquarius\n");
}
else if( (month == 2 && day >= 18) || (month == 3 && day <= 19) )
{
printf("Your Zodiac Sign based on your Birth date is Pisces\n");
P a g e | 14

}
else if( (month == 3 && day >= 20) || (month == 4 && day <= 19) )
{
printf("Your Zodiac Sign based on your Birth date is Aries\n");
}
else if( (month == 4 && day >= 20) || (month == 5 && day <= 20) )
{
printf("Your Zodiac Sign based on your Birth date is Taurus\n");
}
else if( (month == 5 && day >= 21) || (month == 6 && day <= 20) )
{
printf("Your Zodiac Sign based on your Birth date is Gemonthini\n");
}
else if( (month == 6 && day >= 21) || (month == 7 && day <= 22) )
{
printf("Your Zodiac Sign based on your Birth date is Cancer\n");
}
else if( (month == 7 && day >= 23) || (month == 8 && day <= 22) )
{
printf("Your Zodiac Sign based on your Birth date is Leo\n");
}
else if( (month == 8 && day >= 23) || (month == 9 && day <= 22) )
{
printf("Your Zodiac Sign based on your Birth date is Virgo\n");
}
else if( (month == 9 && day >= 23) || (month == 10 && day <= 22) )
{
printf("Your Zodiac Sign based on your Birth date is Libra\n");
}
else if((month==10&&day>=23)||(month==11&&day<=21))
{
printf("Your Zodiac Sign based on your Birth date is Scorpio\n");
}
else if((month==11 && day >= 22)||(month==12&&day <= 21) )
{
printf("Your Zodiac Sign based on your Birth date is Sagittarius\n");
P a g e | 15

}
else
{
printf("Invalid Birth date entered\n");
}
return 0;
}
Output:
P a g e | 16

9. Write a program to find average marks obtained by a class of 10 students in a test


using array.
#include<stdio.h>
main()
{
float arr[10];
float avg;float sum=0;
printf("enter the marks of 10 students");
for(int i=0;i<10;i++)
{
scanf("%f",&arr[i]);
}
for(int j=0;j<10;j++)
{
sum=sum+arr[j];
}
avg=sum/10;
printf("sum=%f average=%f",sum,avg);
}
Output:
P a g e | 17

10.Write a program to find the ascending order of elements in an array. Size of an array
is 5.
#include<stdio.h>
main()
{
int arr[5];
int t,i,j,k;
printf("enter elements of array:\n");
for(i=0;i<5;i++)
{
scanf("%d",&arr[i]);
}
for(j=0;j<5;j++)
{
for(k=j;k<5;k++)
{
if(arr[j]>arr[k])
{
t=arr[j];
arr[j]=arr[k];
arr[k]=t;
}
}
}
printf("array in ascending order:\n");
for(j=0;j<5;j++)
{
printf("%d\n",arr[j]);
}
}
Output:
P a g e | 18
P a g e | 19

11.Write a program to print array elements in reverse order.


#include<stdio.h>
main()
{
printf("enter length of array:");
int l;
scanf("%d",&l);
int arr[l];
for(int i=0;i<l;i++)
{
scanf("%d",&arr[i]);
}
printf("reverse order of array:");
for(int i=l-1;i>=0;i--)
{
printf("%d\n",arr[i]);
}

}
Output:
P a g e | 20

12.Write a program to store the elements entered by user in a 2d array and display the
elements of a two dimensional array.(3 x 3)
#include<stdio.h>
main()
{
int arr[3][3],i,j;
printf("enter the elements of array:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&arr[i][j]);
}
}
printf("elements of array:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",arr[i][j]);
}
printf("\n");
}
}
Output:
P a g e | 21

13.Write a program to find the sum of two matrices.


#include <stdio.h>
main() {
int l, m, arr1[100][100], arr2[100][100], arr3[100][100], i, j;
printf("Enter the number of rows (between 1 and 100): ");
scanf("%d", &l);
printf("Enter the number of columns (between 1 and 100): ");
scanf("%d", &m);

printf("\nEnter elements of 1st matrix:\n");


for (i = 0; i < l; ++i)
for (j = 0; j < m; ++j) {
scanf("%d", &arr1[i][j]);
}

printf("Enter elements of 2nd matrix:\n");


for (i = 0; i < l; ++i)
for (j = 0; j < m; ++j) {

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

for (i = 0; i < l; ++i)


for (j = 0;j<m; ++j) {
arr3[i][j] =arr1[i][j]+arr2[i][j];
}

printf("\nSum of two matrices:\n");


for (i = 0; i < l; ++i)
{for (j = 0; j < m; ++j) {
printf("%d ", arr3[i][j]);

}
printf("\n");
}
}
P a g e | 22

Output:
P a g e | 23

14.Write a program to calculate the product of two matrices.


#include <stdio.h>
main() {
int l, m, arr1[100][100], arr2[100][100], arr3[100][100], i, j;
printf("Enter the number of rows (between 1 and 100): ");
scanf("%d", &l);
printf("Enter the number of columns (between 1 and 100): ");
scanf("%d", &m);

printf("\nEnter elements of 1st matrix:\n");


for (i = 0; i < l; ++i)
for (j = 0; j < m; ++j) {
scanf("%d", &arr1[i][j]);
}

printf("Enter elements of 2nd matrix:\n");


for (i = 0; i < l; ++i)
for (j = 0; j < m; ++j) {

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

for (i = 0; i < l; ++i)


for (j = 0;j<m; ++j) {
arr3[i][j] =arr1[i][j]*arr2[i][j];
}

printf("\nproduct of two matrices:\n");


for (i = 0; i < l; ++i)
{for (j = 0; j < m; ++j) {
printf("%d ", arr3[i][j]);

}
printf("\n");
}
}
P a g e | 24

Output:
P a g e | 25

15.Write a program to implement passing entire array to a function.

#include<stdio.h>
void fun(int);
void fun(int arr[] ) { // Receiving array base address and size

int i=0;
printf("elements of array passed from fun function are:");
for (i = 0; i < 5; i++) {
printf("%d\n",arr[i]);
}

}
int main() {
int arr[5] = {
76,
89,
67,
23,
24
};
fun(arr);
}
Output:
P a g e | 26

16.Write a program that converts a given decimal number to its binary equivalent.
#include<stdio.h>
void main()
{
printf("enter no:");
int n;
scanf("%d",&n);
int a=0;
while(n>1)
{
a=a*10+(n%2);
n=n/2;
}
printf("no after binary conversion=%d",a);
}
P a g e | 27

17.Write a program in C to find the square of any number using the function.(using
call by value)
#include<stdio.h>
int square(int);
int square(int m)
{

int s=m*m;
return s;
}
main()
{
printf("enter any number:");
int n;
scanf("%d",&n);
int res=square(n);
printf("square=%d",res);
}
Output:
P a g e | 28

18.Write a program in C to swap two numbers using a function.(call by reference)


#include <stdio.h>
void swap(int*, int*);
int main()
{
int x, y;
printf("Enter the value of x and y\n");
scanf("%d%d",&x,&y);
printf("Before Swapping\nx = %d\ny = %d\n", x, y);
swap(&x, &y);
printf("After Swapping\nx = %d\ny = %d\n", x, y);
return 0;
}

void swap(int *a, int *b)


{
int temp;

temp = *b;
*b = *a;
*a = temp;
}
Output:
P a g e | 29

19.Write a program in C to get the largest element of three numbers using the
function.
#include<stdio.h>
int greatest(int,int,int);
int greatest(int a,int b,int c)
{
if(a>b&&a>c)
{
return a;
}
else if(b>a&&b>c)
{
return b;
}
else
{
return c;
}
}
main()
{
int a,b,c;
printf("enter numbers:");
scanf("%d%d%d",&a,&b,&c);
int k=greatest(a,b,c);
printf("greatest no=%d",k);
}
Output:
P a g e | 30
P a g e | 31

20.Write a program in C to calculate factorial of a number using recursion.


#include<stdio.h>
int fact(int);
int fact(int n)
{
if(n>1)
{
return n*fact(n-1);
}
else{
return 1;
}
}
main()
{

printf("enter any number:");


int n;
scanf("%d",&n);
int k=fact(n);
printf("factorial of %d=%d",n,k);
}
Output:
P a g e | 32

21. Write a program to display the current system date.


#include<stdio.h>
#include<time.h>

int main()
{

time_t t;
time(&t);

printf("date and time:%s", ctime(&t));


return 0;
}
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy