0% found this document useful (0 votes)
862 views65 pages

Aman Choudhary BCA-1 C Practical

The document is a practical assignment submitted by Prakritee John for their Bachelor of Computer Application 1st year program. It involves writing a C program that declares variables of all the data types supported in C, takes input from the user, and prints the value of each variable. The program first declares variables of different character, integer, short, long, float, and double data types. It then takes input from the user for each variable and prints the value. The program demonstrates declaring and using basic variable types in C.

Uploaded by

Poras Chahande
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)
862 views65 pages

Aman Choudhary BCA-1 C Practical

The document is a practical assignment submitted by Prakritee John for their Bachelor of Computer Application 1st year program. It involves writing a C program that declares variables of all the data types supported in C, takes input from the user, and prints the value of each variable. The program first declares variables of different character, integer, short, long, float, and double data types. It then takes input from the user for each variable and prints the value. The program demonstrates declaring and using basic variable types in C.

Uploaded by

Poras Chahande
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/ 65

A

PRACTICAL ASSIGNMENT
ON
“PROGRAMMING IN C LANGUAGE ”
Submitted in partial fullfillment of the requierments for the
BACHELOR OF COMPUTER APPLICATION – 1ST YEAR
From

HEMCHAND YADAV VISHWAVIDYALAYA DURG (C.G)

SESSION: 2021 - 2022

GUIDED BY: SUBMITTED BY:


Dr Jyoti Upadhyay Prakritee John
(ASSISTANT PROFESSOR)

SUBMITTED TO:
GD RUNGTA COLLEGE OF SCIENCE AND TECHNOLOGY, BHILAI (C.G)
CERTIFICATE BY THE EXAMINER

This is to certify that the project work entitled “PROGRAMMING IN C


LANGUAGE” submitted by Prakritee John of BCA 1st YEAR Enrollment No. –
has been examined by the undersigned as a part of the examination and is here by
recommended for the degree of Bachelor of Computer Application of Hemchand
Yadav vishwavidyalaya, Durg.

Internal Examiner

Date:
ACKNOWLEDGEMENT

The real spirit of achieving a goal is through the way of excellence and
austerious discipline. I want to thank GDRCST, Bhilai for providing me the
necessary software, tools and other resources to deliver my Practical assignment.

I acknowledge with gratitude and humanity my indebtedness to


Dr. Jyoti Upadhyay, Assistant Professor, GDRCST Bhilai, under whose guidance I
had the privilege to complete this assignment.

I shall be failing in my duties if I do not express my duty sense of gratitude


towards HOD Dr. Jyoti Upadhyay, Assistant Professor & Head of Department of
Computer Science GDRCST, Bhilai.

I owe my sincere thanks to Dr. Neema S. Balan, Principal, GDRCST, Bhilai for
inspiration and constant encouragement that enabled me to present my work in
this form.

My greatest thanks go to my parents and my family who has been my driving


force. Above all I render my gratitude to the almighty, who bestowed self-
confidence, ability and strength in me to complete this work.

Prakritee John

Enrollment no.
INDEX

S Name Of The Programs Page Date Of Signature


NO. No. Submission
1. Write a program in which you 1-3
declare variable of all data
type supported by ‘C’
language. Get input form user
and print the value of each
variable with.
2. Write a program to print all 4
combination of 1 2 3.

3. Write a program to generate 5-15


following pattern :
a) b)
ABCDEFG *
ABC EFG * *
AB FG * * *
A G * * * *
c) d)
1 1
1 2 1 2 1
1 2 3 1 3 3 1

4. Write a program to perform 16-19


following task using switch case,
loop and conditional operator (as
when necessary).
a) Find factorial no.
b) Print Fibonacci series up to n
terms and its sum.
c) Print Sin series up to n terms and
its sum.
d) Print Exponential series up to n
terms and its sum.
e) Print prime no. up to n term.
5. Create a single program to perform 20-23
following task using switch, if..else
,loop and single dimension
character array with out using
library function:
a) To reverse string.
b) To count the no. of characters
in string.
c) To copy one string to other
string.
d) To find weather a given string
is palindrome or not.
e) To count number of vowels ,
consonants in words of a
string.
f) To arrange the alphabets of a
string in ascending order.
6. Create a single program to perform 24-26
following task using switch, if..else
,loop and single dimension integer
array:
a) Sort the elements.
b) Search for the presence of
particular value in array
elements using linear search.
c) Search for the presence of
particular value in array
elements using binary search.
7. Write a program that read the 27-28
afternoon day temperature for
each day of the month and
then report the month average
temperature as well as the
days on which hottest and
coolest days occurred.
8. Create a single program to 29-35
perform following task using
switch, if ..Else loop and
double dimension integer
array of size 3X3
a) Addition of two matrix.
b) Subtraction of two
Matrix.
c) Multiplication Of two
matrix.
d) Sum of diagonal
elements.
e) Transpose of Matrix
9. write a program using the 36
function power (a,b) to
calculate the value of a raised
to b.
10. Write a program to demonstrate 37
the difference between local and
global variable.

11. Create a program to perform 38-41


following task using switch…
case , loops and functions.
a) Find factorial of a
number.
b) Print Fibonacci series up
to n terms and its sum.
c) Print Sin series up to n
terms and its sum.
d) Print Exponential series
up to n terms and its
sum.
12. Write a function to accept 10 42-43
Characters and display weather
each input character, digit ,
uppercase letter or lower case
letter .

13. Create a structure Student 44-46


having data members to store
roll number , name of student ,
name of three subjects , max
marks , obtained marks .
Declare a structure variable of
student . Provide facilities to
input data in data members
and display result of student.
14. Create a structure Date with 47-48
data member’s dd , mm , yy (to
store date). Create another
structure Employee with data
members to hold name of
employee id and date of
joining (date of joining will be
hold by variable of structure
Date which appears as data
member in Employee
Structure) . Store data of an
employee and print the same .
15. Write a program to create 49-50
structure complex having data
members to store real and
imaginary part. Provide
following facilities :
a) Add two complex nos.
using structure variables.
b) Subtract two complex
nos. using structure
variables.
c) Multiply two complex
nos. using structure
variables.
d) Divide two complex nos.
using structure variables.
16. Define union Emp having data 51
members :- One integer , One
float and one single dimension
character array. Declare union
variable in main and test the
union variable.
17. Define an enum Days_of_week 52
members of which will be days
of week.Declare an enum
variable in main and test it.
18. Write a program of swapping 53-54
two numbers that
demonstrates call by value and
call by reference .
19. Write program to find biggest 55
number among three numbers
using pointer and function.
20. Write a program to 56
demonstrate pointer
arithmetic .
BCA 1st YEAR 2021 - 2022

Practical No. 1 : Write a program in which you declare variable of all


data type supported by ‘C’ language. Get input form user and print the
value of each variable with.
Program :
#include<stdio.h>
#include<conio.h>
void main()
{
//************************* Variable Declaration *****************************
//----------- Character Variables Declaration ----------------
char c1;
unsigned char c2;
//----------- Integer variables Declaration-------------------
int i1;
unsigned int i2;
//----------- Short Integer variable Declaration--------------
short int i3;
unsigned short int i4;
//----------- Long Integer Varible Declaration----------------
long int i5;
unsigned long int i6;
//----------- Float Variables Declaration---------------------
float f;
//---------- double Variable Declaration----------------------
double d1;
long double d2;
clrscr();
//****************************** Input **************************************
//-----------------------------Character Input-------------------------------
printf("\n\t Enter any character constant various Character datatypes ");
printf("\n\t\t Char ->>");
scanf("%s",&c1);
printf("\n\t\t Unsigned char ->>");
scanf("%s",&c2);
//----------------------------Integer Input-----------------------------------
printf("\n\t Enter any integer value for various integer datatypes");
printf("\n\t\t int ->>");
scanf("%d",&i1);
printf("\n\t\t unsigned int ->>");
scanf("%u",&i2);
//---------------------------Short Integer Input------------------------------
printf("\n\t Enter any integer value for various short integer datatypes");

Prakritee John Page 1


BCA 1st YEAR 2021 - 2022

printf("\n\t\t short int ->>");

scanf("%d",&i3);
printf("\n\t\t unsigned short int ->>");
scanf("%u",&i4);
//--------------------------Long Integer Input-------------------------------
printf("\n\t Enter any integer value for various long integer datatypes");
printf("\n\t\t long int ->>");
scanf("%ld",&i5);
printf("\n\t\t unsigned long int ->>");
scanf("%lu",&i6);
//-------------------------Float Input----------------------------------------
printf("\n\t Enter any float value for various float datatypes");
printf("\n\t\t float ->>");
scanf("%f",&f);
//------------------------Double Input----------------------------------------
printf("\n\t Enter any float value for various double datatypes");
printf("\n\t\t double ->>");
scanf("%lf",&d1);
printf("\n\t\t long double ->>");
scanf("%Lf",&d2);
//****************************Output******************************
clrscr();
printf("\n\t %c",c1);
printf("\n\t %c",c2);
printf("\n\t %10d",i1);
printf("\n\t %10u",i2);
printf("\n\t %10d",i3);
printf("\n\t %10d",i4);
printf("\n\t %10ld",i5);
printf("\n\t %10lu",i6);
printf("\n\t %10.2f",f);
printf("\n\t %10.2lf",d1);
printf("\n\t %10.2Lf",d2);
getch();
}
Output

Prakritee John Page 2


BCA 1st YEAR 2021 - 2022

Prakritee John Page 3


BCA 1st YEAR 2021 - 2022

Practical No. 2 : Write a program to print all combination of 1 2 3.


Program :
#include<stdio.h>
#include<conio.h>
void main()
{int a,b,c;
clrscr();
printf("\n\tThe combinations of 1,2 & 3 are :");
for(a=1;a<=3;a++)
{ for(b=1;b<=3;b++)
{ for(c=1;c<=3;c++)
{ if(a!=b && a!=c && b!=c)
printf("\n\n\t %d",a*100+b*10+c);
}
}
}
getch();
}
Output :

Prakritee John Page 4


BCA 1st YEAR 2021 - 2022

Practical No. 3: Write a program to generate following pattern :


a) b)
ABCDEFG *
ABC EFG * *
AB FG * * *
A G * * * *

c) d)
1 1
1 2 1 2 1
1 2 3 1 3 3 1
1 2 3 4 1 4 6 4 1
Write main function using switch…..else, if..Else and loops which when
called as<s pattern type: If user 11 then first pattern is generated
using for loop, if user enters the 12 then first pattern is generated
using while loop .if user enter 13 then first pattern is generated using
do while loop. If user enters the 21 then a second pattern is generated
using for loop and so on.
Program:
#include<Stdio.h>
#include<conio.h>
#include<math.h>
void main()
{int choice,sel,a,g,i,j,k,l,m,n;
clrscr();
printf("\n\t Press 1 for ");
printf("\n\n\tA B C D C B A");
printf("\n\tA B C C B A");
printf("\n\tA B B A");
printf("\n\tA A");
printf("\n");
printf("\n\t Press 2 for ");
printf("\n\n\t * ");
printf("\n\t * * ");
printf("\n\t * * * ");
printf("\n");
printf("\n\t Press 3 for ");
printf("\n\n\t1");
printf("\n\t1 2");
printf("\n\t1 2 3");
printf("\n");

Prakritee John Page 5


BCA 1st YEAR 2021 - 2022

printf("\n\t Press 4 for ");


printf("\n\n\t1");
printf("\n\t1 2 1");
printf("\n\t1 3 3 1");
printf("\n\t1 4 6 4 1");
printf("\n\n\t Enter Your Choice : ");
scanf("%d",&choice);
switch(choice)
{case 1:
clrscr();
printf("\n\t Enter 11 to print this pattern using for loop...");
printf("\n\t Enter 12 to print this pattern using While loop...");
printf("\n\t Enter 13 to print this pattern using Do While loop...");
printf("\n\n\t Enter Your Choice : ");
scanf("%d",&sel);
if(sel==11)
{clrscr();
printf("\n\t Enter the number of rows - ");
scanf("%d",&n);
printf("\n\n The pattern 1 by for loop is : ");
printf("\n\n");
for(i=1;i<=n;i++)
{ a='A';
for(m=1;m<=(n+1)-i;m++)
{ printf("%c",a);
a++;
}
for(k=1;k<=(2*(i-1))-1;k++)
{ printf(" ");
a++;
}
if(i==1)
{ for(l=1;l<=n-i;l++)
{ printf("%c",a);
a++;
}
}
else
{
for(l=1;l<=(n+1)-i;l++)
{
printf("%c",a);
a++;
}
}

Prakritee John Page 6


BCA 1st YEAR 2021 - 2022

printf("\n");
}
getch();
}
else
if(sel==12)
{
clrscr();
printf("\n\t Enter the number of rows - ");
scanf("%d",&n);
printf("\n\n The pattern 1 by While loop is : ");
printf("\n\n");
i=1;
while(i<=n)
{
a='A';
m=1;
while(m<=(n+1)-i)
{
printf("%c",a);
a++;
m++;
}
k=1;
while(k<=(2*(i-1))-1)
{
printf(" ");
a++;
k++;
}
if(i==1)
{
int l=1;
while(l<=n-i)
{
printf("%c",a);
a++;
l++;
}
}
else
{
int l=1;
while(l<=(n+1)-i)
{

Prakritee John Page 7


BCA 1st YEAR 2021 - 2022

printf("%c",a);
a++;
l++;
}
}
printf("\n");
i++;
}
getch();
}
else
if(sel==13)
{
clrscr();
printf("\n\t Enter the number of rows - ");
scanf("%d",&n);
printf("\n\n The pattern 1 by Do While loop is : ");
printf("\n\n");
i=1;
do
{
a='A';
m=1;
do
{
printf("%c",a);
a++;
m++;
}while(m<=(n+1)-i);
if(i>1)
{
k=1;
do
{
printf(" ");
a++;
k++;
}while(k<=(2*(i-1))-1);
}
if(i==1)
{
int l=1;
do
{
printf("%c",a);

Prakritee John Page 8


BCA 1st YEAR 2021 - 2022

a++;
l++;
}while(l<=n-i);
}
else
{
int l=1;
do
{
printf("%c",a);
a++;
l++;
}while(l<=(n+1)-i);
}
printf("\n");
i++;
}while(i<=n);
getch();
}
else
printf("\n\t Invalid Input!!");
break;
case 2:
clrscr();
printf("\n\t Enter 21 to print this pattern using for loop...");
printf("\n\t Enter 22 to print this pattern using While loop...");
printf("\n\t Enter 23 to print this pattern using Do While loop...");
printf("\n\n\t Enter Your Choice : ");
scanf("%d",&sel);
if(sel==21)
{
clrscr();
printf("\n\t Enter the number of rows - ");
scanf("%d",&n);
printf("\n\n The pattern 2 by for loop is : ");
printf("\n\n");
for(i=1;i<=n;i++)
{
for(g=1;g<=n-i;g++)
{
printf(" ");
}
for(j=1;j<=(2*i)-1;j++)
{
if(j%2==0)

Prakritee John Page 9


BCA 1st YEAR 2021 - 2022

{
printf(" ");
}
else
{
printf("*");
}
}
printf("\n");
}
getch();
}
else
if(sel==22)
{
clrscr();
printf("\n\t Enter the number of rows - ");
scanf("%d",&n);
printf("\n\n The pattern 2 by While loop is : ");
printf("\n\n");
i=1;
while(i<=n)
{
g=1;
while(g<=n-i)
{
printf(" ");
g++;
}
j=1;
while(j<=(2*i)-1)
{
if(j%2==0)
{
printf(" ");
}
else
{
printf("*");
}
j++;
}
printf("\n");
i++;
}

Prakritee John Page 10


BCA 1st YEAR 2021 - 2022

getch();
}
else
if(sel==23)
{
clrscr();
printf("\n\t Enter the number of rows - ");
scanf("%d",&n);
printf("\n\n The pattern 2 by Do While loop is : ");
printf("\n\n");
i=1;
do
{ g=1;
do
{ printf(" ");
g++;
}while(g<=n-i+1);
j=1;
do
{
if(j%2==0)
{
printf(" ");
}
else
{
printf("*");
}
j++;
}while(j<=(2*i)-1);
printf("\n");
i++;
}while(i<=n);
getch();
}
else
printf("\n\t Invalid Input!!");
break;
case 3:
clrscr();
printf("\n\t Enter 31 to print this pattern using for loop...");
printf("\n\t Enter 32 to print this pattern using While loop...");
printf("\n\t Enter 33 to print this pattern using Do While loop...");
printf("\n\n\t Enter Your Choice : ");
scanf("%d",&sel);

Prakritee John Page 11


BCA 1st YEAR 2021 - 2022

if(sel==31)
{
clrscr();
printf("\n\t Enter the number of rows - ");
scanf("%d",&n);
printf("\n\n The pattern 3 by for loop is : ");
printf("\n\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
printf(" ");
}
printf("\n");
}
getch();
}
else
if(sel==32)
{
clrscr();
printf("\n\t Enter the number of rows - ");
scanf("%d",&n);
printf("\n\n The pattern 3 by While loop is : ");
printf("\n\n");
i=1;
while(i<=n)
{
j=1;
while(j<=i)
{
printf("%d",j);
printf(" ");
j++;
}
printf("\n");
i++;
}
getch();
}
else
if(sel==33)
{
clrscr();

Prakritee John Page 12


BCA 1st YEAR 2021 - 2022

printf("\n\t Enter the number of rows - ");


scanf("%d",&n);
printf("\n\n The pattern 3 by DO While loop is : ");
printf("\n\n");
i=1;
do
{
j=1;
do

{
printf("%d",j);
printf(" ");
j++;
}while(j<=i);
printf("\n");
i++;
}while(i<=n);
getch();
}
else
printf("\n\t Invalid Input!!");
break;
case 4:
clrscr();
printf("\n\t Enter 41 to print this pattern using for loop...");
printf("\n\t Enter 42 to print this pattern using While loop...");
printf("\n\t Enter 43 to print this pattern using Do While loop...");
printf("\n\n\t Enter Your Choice : ");
scanf("%d",&sel);
if(sel==41)
{
clrscr();
printf("\n\t Enter the number of rows - ");
scanf("%d",&n);
printf("\n\n The pattern 4 by for loop is : ");
printf("\n\n");
printf("1");
for(i=2;i<=n;i++)
{
a=pow(11,i);
printf("\n%d",a);
}
getch();
}

Prakritee John Page 13


BCA 1st YEAR 2021 - 2022

else
if(sel==42)
{
clrscr();
printf("\n\t Enter the number of rows - ");
scanf("%d",&n);
printf("\n\n The pattern 4 by While loop is : ");
printf("\n\n");
printf("\n1");
i=2;
while(i<=n)
{
a=pow(11,i);
printf("\n%d",a);
i++;
}
getch();
}
else
if(sel==43)
{
clrscr();
printf("\n\t Enter the number of rows - ");
scanf("%d",&n);
printf("\n\n The pattern 4 by DO While loop is : ");
printf("\n\n");
printf("\n1");
i=2;
do
{
a=pow(11,i);
printf("\n%d",a);
i++;
}while(i<=n);
getch();
}
else
printf("\n\t Invalid Input!!");
break;
default:
clrscr();
printf("\n\n\t\t Invalid Input !!! ");
clrscr();
printf("\n\n\t\t Thank you for using this program");
getch();

Prakritee John Page 14


BCA 1st YEAR 2021 - 2022

}getch();
}
Output :

Prakritee John Page 15


BCA 1st YEAR 2021 - 2022

Practical No. 4: Write a program to perform following task using


switch case, loop and conditional operator (as when necessary).
a) Find factorial no.
b) Print Fibonacci series up to n terms and its sum.
c) Print Sin series up to n terms and its sum.
d) Print Exponential series up to n terms and its sum.
e) Print prime no. up to n term.
f) Program of leap year or not year.
Program :
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int choice,num,i,j,a,b,c=0,x;
long int fact=1;
float sum=0,nume,dummy=1;
clrscr();
printf("\n\tEnter 1 for factorial of a number ");
printf("\n\tEnter 2 for printing fabonacci series upto n terms and its sum");
printf("\n\tEnter 3 for printing Sin series upto n terms and its sum");
printf("\n\tEnter 4 for printing exponential series upto n terms and its sum");
printf("\n\tEnter 5 for printing prime number series upto n terms");
printf("\n\tEnter 6 to print weather a year is leap or not ");
printf("\n\n\tEnter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
clrscr();
printf("\n\tEnter any number to find its factorial : ");
scanf("%d",&num);
for(i=1;i<=num;i++)
fact=fact*i;
printf("\n\factorial of %d is : %ld",num,fact);
getch();
break;
case 2:
clrscr();
a=0;
b=1;
printf("\n\t Enter the n'th term of the series : ");

Prakritee John Page 16


BCA 1st YEAR 2021 - 2022

scanf("%d",&num);
printf("\n\t %d",a);
printf("\t %d",b);
do
{
c=a+b;
a=b;
b=c;
printf("\t %d",c);
sum=sum+c;
}while(c<num);
sum=sum+1;
printf("\n\n\t The sum of series is %f ",sum);
getch();
break;
case 3:
clrscr();
printf("\n\tEnter the number of terms you want in series : ");
scanf("%d",&num);
printf("\n\tEnter the value of x : ");
scanf("%d",&x);
printf("\n\n");
for(i=1;i<=((2*num)-1);i=i+2)
{
c++;
for(a=1;a<=i;a++)
fact=fact*a;
nume=pow(x,i);
if((c%2)==0)
nume=nume*-1;
else
nume=nume*1;
printf("\t %15.0f/%ld ",nume,fact);
sum=sum+(nume/fact);
fact=1;
}
printf("\n\n\t The sum of series is : %1.3f ",sum);
getch();
break;
case 4:
clrscr();
printf("\n\tEnter the number of terms you want in series : ");
scanf("%d",&num);
printf("\n\n");
printf("\t1");

Prakritee John Page 17


BCA 1st YEAR 2021 - 2022

j=1;
while(j<=(num-1))
{
for(a=1;a<=j;a++)
fact=fact*a;
printf("\t+\t%1.0f/%ld",dummy,fact);
sum=sum+(dummy/fact);
fact=1;
j++;
}
sum=sum+1;
printf("\n\n\t The sum of series is : %1.3f ",sum);
getch();
break;
case 5:
clrscr();
printf("\n\tEnter the no. upto which you want to print prime no series :");
scanf("%d",&num);
printf("\n\n\t1");
for(i=2;i<=num;i++)
{
for(j=2;j<=(i-1);j++)
{
x=i%j;
if(x==0)
break;
}
if(x!=0)
printf("\t%d",i);
x=0;
}
break;
case 6:
clrscr();
printf("\n\n\t Enter any year : ");
scanf("%d",&num);
if((num%4)==0)
printf("\n\t The Year you entered is a leap year");
else
printf("\n\t The year you entered is not a leap year");
getch();
break;
default :
printf("\n\t Invalid Entry!!!");
}

Prakritee John Page 18


BCA 1st YEAR 2021 - 2022

getch();
}
Output :

Prakritee John Page 19


BCA 1st YEAR 2021 - 2022

Practical No. 5: Create a single program to perform following task


using switch, if..else ,loop and single dimension character array with
out using library function:
To reverse string.
To count the no. of characters in string.
To copy one string to other string.
To find weather a given string is palindrome or not.
To count number of vowels , consonants in each word of a string.
To arrange the alphabets of a string in ascending order.
Program :
#include<stdio.h>
#include<conio.h>
void main()
{
int choice,count,i=0,j=0,m=0,n,a,b,vowels=0,consonants=0;
char string1[20],string2[20],ab[100];
clrscr();
printf("\n\t Press 1 to reverse the Entered String ");
printf("\n\t Press 2 to count the number of characters in the Entered String ");
printf("\n\t Press 3 to copy one string to other String ");
printf("\n\t Press 4 to find weather Entered String is pallindrome or not ");
printf("\n\t Press 5 to count the no. of vowels,consonants in a sentance ");
printf("\n\t Press 6 to arrange the alphabets of a string in ascending order ");
printf("\n\n\n\t Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
clrscr();
printf("\n\t Enter any string : ");
scanf("%s",&string1);
while(string1[i]!='\0')
{
i++;
}
printf("\n");
for(j=i;j>=0;j--)
printf("%c",string1[j]);
getch();
break;
case 2:
clrscr();

Prakritee John Page 20


BCA 1st YEAR 2021 - 2022

printf("\n\t Enter any string : ");


scanf("%s",&string1);
while(string1[i]!='\0')
{
i++;
}
printf("\n\t The number of characters in string is : %d ",i);
getch();
break;
case 3:
clrscr();
printf("\n\t Enter any string : ");
scanf("%s",&string1);
while(string1[i]!='\0')
{
string2[i]=string1[i];
i++;
}
string2[i+1]='\0';
printf("\n\t The String copied to second variable is : %s",string2);
getch();
break;
case 4:
clrscr();
printf("\n\t Enter any string : ");
scanf("%s",&string1);
while(string1[i]!='\0')
{
i++;
}
n=i;
i=0;
while(string1[i]!='\0')
{
if(string1[i]!=string1[n-(i+1)])
m=m+1;
else
m=m+0;
i++;
}
if(m>0)
printf("\n\n\t The Entered String is not a pallindrome ");
else
printf("\n\n\t The Entered String is a pallindrome ");
getch();
Prakritee John Page 21
BCA 1st YEAR 2021 - 2022

break;
case 5:
clrscr();
printf("\n\n\tEnter any string\n\t");
gets(ab);
for(i=0;i<=100;i++);
{
if(ab[i]==65 || ab[i]==97 || ab[i]==69 || ab[i]==101 || ab[i]==73 || ab[i]==105 ||
ab[i]==79 || ab[i]==111 || ab[i]==85 || ab[i]==117 )
vowels=vowels+1;
if((ab[i]>=65 && ab[i]<=90 )||(ab[i]>=97 && ab[i]<=122))
consonants=consonants+1;
}
consonants=consonants-vowels;
printf("\n\t The number of vowels in the entered String is : %d",vowels);
printf("\n\t The number of consonants in the entered String is : %d",consonants);
getch();
break;
case 6:
clrscr();
printf("\n\t Enter any string : ");
scanf("%s",&string1);
while(string1[i]!='\0')
{
i++;
}
for(a=0;a<=(i-2);a++)
{
for(b=0;b<=(i-2)-a;b++)
{
if (string1[b]>string1[b+1])
{
n=string1[b];
string1[b]=string1[b+1];
string1[b+1]=n;
}}}
printf("\n\n\t");
for(a=0;a<=i;a++)
printf("%c",string1[a]);
getch();
break;
default :
printf("\n\n\t Invalid Key press !!! ");
}
getch();
Prakritee John Page 22
BCA 1st YEAR 2021 - 2022

}
Output :

Prakritee John Page 23


BCA 1st YEAR 2021 - 2022

Practical No. 6: Create a single program to perform following task


using switch, if..else ,loop and single dimension integer array:
a) Sort the elements.
b) Search for the presence of particular value in array elements
using linear search.
c) Search for the presence of particular value in array elements
using binary search.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,j,k=-1,choice,st,fi,la,mid,posi=-1,x;
clrscr();
printf("\n\t Enter 1 for sorting the elements of an array");
printf("\n\t Enter 2 for searching the elements of an array using linear search");
printf("\n\t Enter 3 for searching the elements of an array using binary search");
printf("\n\n\t Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
clrscr();
for(i=0;i<=9;i++)
{
printf("\n\t Enter any value : ");
scanf("%d",&a[i]);
clrscr();
}
for(j=0;j<=8;j++)
{
for(k=0;k<=8-j;k++)
{
if(a[k]>a[k+1])
{
st=a[k];
a[k]=a[k+1];
a[k+1]=st;
}
}
}
printf("\n\t The elements in sorted order are : ");
printf("\n\n\n ");

Prakritee John Page 24


BCA 1st YEAR 2021 - 2022

for(i=0;i<=9;i++)
printf("\t%d",a[i]);
getch();
break;
case 2:
clrscr();
for(i=0;i<=9;i++)
{
printf("\n\t Enter any value : ");
scanf("%d",&a[i]);
clrscr();
}
printf("\n\n\t Enter any value to find its position in the array : ");
scanf("%d",&j);
for(i=0;i<=9;i++)
{
if(j==a[i])
k=i+1;
}
if(k==-1)
printf("\n\t Element not found ");
else
printf("\n\t Position of element in the array is %d ",k);
getch();
break;
case 3:
clrscr();
clrscr();
for(i=0;i<=9;i++)
{
printf("\n\t Enter any value : ");
scanf("%d",&a[i]);
clrscr();
}
printf("\n\n\t Enter any value to find its position in the array : ");
scanf("%d",&x);
fi=0;
la=9;
while(fi<=la && posi==-1)
{
mid=(fi+la)/2;
if(a[mid]==x)
posi=mid+1;
if(a[mid]<x)
fi=mid+1;

Prakritee John Page 25


BCA 1st YEAR 2021 - 2022

else
la=mid-1;
}
if(posi==-1)
printf("\n\t Number not found ");
else
printf("\n\t Position of element in the array is %d",posi);
getch();
break;
default:
printf("\n\n\t Invalid Entry !!!");
}
getch();
}
Output :

Prakritee John Page 26


BCA 1st YEAR 2021 - 2022

Practical No. 7: Write a program that read the afternoon day


temperature for each day of the month and then report the month
average temperature as well as the days on which hottest and coolest
days occurred.
Program :

#include<stdio.h>
#include<conio.h>
void main()
{
float month[31],ave,sum=0,st;
int x,i,j,k;
clrscr();
printf("\n\n\t Enter number of days in the month : ");
scanf("%d",&x);
for(i=0;i<=x-1;i++)
{
printf("\n\t Enter temperature : ");
scanf("%f",&month[i]);
clrscr();
}
for(i=0;i<=x-1;i++)
{
sum=sum+month[i];
}
ave=sum/x;
for(j=0;j<=x-2;j++)
{
for(k=0;k<=(x-2)-j;k++)
{
if(month[k]>month[k+1])
{
st=month[k];
month[k]=month[k+1];
month[k+1]=st;
}
}
}
printf("\n\n\t The average temperature of month is %4.2f ",ave);
printf("\n\n\t The hottest day of month is %4.2f",month[x-1]);
printf("\n\n\t The coolest day of month is %4.2f",month[0]);
getch();
}

Prakritee John Page 27


BCA 1st YEAR 2021 - 2022

Output :

Prakritee John Page 28


BCA 1st YEAR 2021 - 2022

Practical No. 8: Create a single program to perform following task


using switch, if ..Else loop and double dimension integer array of size
3X3
a) Addition of two matrix.
b) Subtraction of two Matrix.
c) Multiplication Of two matrix.
d) Sum of diagonal elements.
e) Transpose of Matrix
Program :
#include<stdio.h>
#include<conio.h>
void main()
{
int choice,a[3][3],b[3][3],c[3][3],i,j,k,sum=0,sum1=0,sum2=0;
clrscr();
printf("\n\t Enter 1 for Addition of two matrix ");
printf("\n\t Enter 2 for Subtraction of two matrix ");
printf("\n\t Enter 3 for Multiplication of two matrix ");
printf("\n\t Enter 4 for sum of diagonal elements ");
printf("\n\t Enter 5 for transpose of matrix ");
printf("\n\n\n\t Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
clrscr();
printf("\n\n Enter the elements of first Matrix ");
getch();
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
clrscr();
printf("\n\t Enter any value : ");
scanf("%d",&a[i][j]);
}
}
clrscr();
printf("\n\n Enter the elements of second Matrix ");
getch();
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)

Prakritee John Page 29


BCA 1st YEAR 2021 - 2022

{
clrscr();
printf("\n\t Enter any value : ");
scanf("%d",&b[i][j]);
}
}
printf("\n\t The first matrix is : \n\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\t %d",a[i][j]);
}
printf("\n\n");
}
printf("\n\t The first matrix is : \n\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\t %d",a[i][j]);
}
printf("\n\n");
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("\n\t The sum of both martices is : \n\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\t %d",c[i][j]);
}
printf("\n\n");
}
getch();
break;
case 2:
clrscr();
printf("\n\n Enter the elements of first Matrix ");

Prakritee John Page 30


BCA 1st YEAR 2021 - 2022

getch();
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
clrscr();
printf("\n\t Enter any value : ");
scanf("%d",&a[i][j]);
}
}
clrscr();
printf("\n\n Enter the elements of second Matrix ");
getch();
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
clrscr();
printf("\n\t Enter any value : ");
scanf("%d",&b[i][j]);
}
}
printf("\n\t The first matrix is : \n\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\t %d",a[i][j]);
}
printf("\n\n");
}
printf("\n\t The second matrix is : \n\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\t %d",b[i][j]);
}
printf("\n\n");
}
for(i=0;i<=2;i++)
{

for(j=0;j<=2;j++)
{

Prakritee John Page 31


BCA 1st YEAR 2021 - 2022

c[i][j]=a[i][j]-b[i][j];
}
}
printf("\n\t The sum of both martices is : \n\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\t %d",c[i][j]);
}
printf("\n\n");
}
getch();
break;
case 3:
clrscr();
printf("\n\n Enter the elements of first Matrix ");
getch();
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
clrscr();
printf("\n\t Enter any value : ");
scanf("%d",&a[i][j]);
}
}
clrscr();
printf("\n\n Enter the elements of second Matrix ");
getch();
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
clrscr();
printf("\n\t Enter any value : ");
scanf("%d",&b[i][j]);
}
}
clrscr();
printf("\n\t The first matrix is : \n\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{

Prakritee John Page 32


BCA 1st YEAR 2021 - 2022

printf("\t %d",a[i][j]);
}
printf("\n\n");
}

printf("\n\t The second matrix is : \n\n");


for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\t %d",b[i][j]);
}
printf("\n\n");
}
printf("\n\n\t The multiplication of these martices is : \n\n");
for(i=0;i<=2;i++)
{ for(j=0;j<=2;j++)
{ for(k=0;k<=2;k++)
sum=sum+a[i][k]*b[k][j];
printf(" \t%d ",sum);
sum=0;
}
printf("\n");
}
getch();
break;
case 4:
printf("\n\n Enter the elements of Matrix ");
getch();
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
clrscr();
printf("\n\t Enter any value : ");
scanf("%d",&a[i][j]);
}
}
clrscr();
printf("\n\t The matrix you entered is : \n\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\t %d",a[i][j]);

Prakritee John Page 33


BCA 1st YEAR 2021 - 2022

}
printf("\n\n");
}
printf("\n\t The transpose of Entered matrix is : \n\n");
for(i=0;i<=2;i++)
{ for(j=0;j<=2;j++)
printf("%d\t",a[j][i]);
printf("\n");
}
getch();
break;
case 6:
printf("\n\n Enter the elements of Matrix ");
getch();
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
clrscr();
printf("\n\t Enter any value : ");
scanf("%d",&a[i][j]);
}
}
clrscr();
printf("\n\t The matrix you entered is : \n\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\t %d",a[i][j]);
}
printf("\n\n");
}
printf("\n\t The sum of diagonal elements of Entered matrix is : \n\n");
for(i=0;i<=2;i++)
{ for(j=0;j<=2;j++)
{ if(i==j)
sum1=sum1+a[i][j];
if((i+j)==2)
sum2=sum2+a[i][j];
}
}
printf("\n\tsum1=%d",sum1);
printf("\n\tsum2=%d",sum2);
getch();

Prakritee John Page 34


BCA 1st YEAR 2021 - 2022

break;
default :
getch();
printf("\n\n\t Invald Entry !!!");
}
getch();
}
Output :

Prakritee John Page 35


BCA 1st YEAR 2021 - 2022

Practical No. 9: write a program using the function power (a,b) to


calculate the value of a raised to b.
Program :
#include<stdio.h>
#include<conio.h>
long int pow(a,b)
{
int i;
long int c=1;
for(i=1;i<=b;i++)
c=c*a;
return(c);
}
void main()
{
int num1,num2;
long int exp;
clrscr();
printf("\n\n\t Enter first number : ");
scanf("%d",&num1);
printf("\n\n\t Enter Second number : ");
scanf("%d",&num2);
exp=pow(num1,num2);
printf("\n\n\t The result of first number raised to second number is %ld ",exp);
getch();
}
Output :

Prakritee John Page 36


BCA 1st YEAR 2021 - 2022

Practical No. 10: Write a program to demonstrate the difference


between local and global variable.
Program :
#include<stdio.h>
#include<conio.h>
int x=10;
void ankur()
{
int y=23;
printf("\n\t The value of x is %d",x);
printf("\n\t The value of y is %d",y);
getch();
}
void main()
{
int y;
clrscr();
printf("\n\t The value of x is %d",x);
printf("\n\t The value of y is %d",y);
printf("\n\n\n");
ankur();
}
Output :

Prakritee John Page 37


BCA 1st YEAR 2021 - 2022

Practical No. 11: Create a program to perform following task using


switch… case , loops and functions.
a) Find factorial of a number.
b) Print Fibonacci series up to n terms and its sum.
c) Print Sin series up to n terms and its sum.
d) Print Exponential series up to n terms and its sum.
Program :
#include<stdio.h>
#include<conio.h>
#include<math.h>
float expo(int bin)
{
int j,a;
long int fact=1;
float dummy=1,sum=0;
printf("\n\n");
printf("\t1");
j=1;
while(j<=(bin-1))
{
for(a=1;a<=j;a++)
fact=fact*a;
printf("\t+\t%1.0f/%ld",dummy,fact);
sum=sum+(dummy/fact);
fact=1;
j++;
}
sum=sum+1;
return(sum);
}
float sine(int ink)
{
float nume,sum=0;
int x,i,c=0,a;
long int fact=1;
printf("\n\tEnter the value of x : ");
scanf("%d",&x);
printf("\n\n");
for(i=1;i<=((2*ink)-1);i=i+2)
{
c++;
for(a=1;a<=i;a++)
fact=fact*a;

Prakritee John Page 38


BCA 1st YEAR 2021 - 2022

nume=pow(x,i);
if((c%2)==0)
nume=nume*-1;
else
nume=nume*1;
printf("\t %15.0f/%ld ",nume,fact);
sum=sum+(nume/fact);
fact=1;
}
return(sum);
}
float fabo(int x)
{
float sum=0;
int a,b,c;
a=0;
b=1;
printf("\n\t %d",a);
printf("\t %d",b);
do
{
c=a+b;
a=b;
b=c;
printf("\t %d",c);
sum=sum+c;
}while(c<x);
sum=sum+1;
return(sum);
}
long int fact(int a)
{
int i,j,x=1;
for(i=1;i<=a;i++)
x=x*i;
return(x);
}
void main()
{
float sum;
int choice,num;
long int back;
clrscr();
printf("\n\tEnter 1 to find Factaorial of given number");
printf("\n\tEnter 2 to print Fabonacci Series");

Prakritee John Page 39


BCA 1st YEAR 2021 - 2022

printf("\n\tEnter 3 for printing Sin series upto n terms and its sum");
printf("\n\tEnter 4 for printing exponential series upto n terms and its sum");
printf("\n\tEnter 5 for printing natural number series upto n terms and its sum");
printf("\n\n\t Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
clrscr();
printf("\n\tEnter any number to find its factorial : ");
scanf("%d",&num);
back=fact(num);
printf("\n\n\t Factorial of entered number is : %ld",back);
getch();
case 2:
clrscr();
sum=0;
printf("\n\t Enter the n'th term of the series : ");
scanf("%d",&num);
sum=fabo(num);
printf("\n\n\t The sum of series is %10.0f ",sum);
getch();
case 3:
clrscr();
sum=0;
printf("\n\tEnter the number of terms you want in series : ");
scanf("%d",&num);
sum=sine(num);
printf("\n\n\t The sum of series is : %1.3f ",sum);
getch();
case 4:
clrscr();
sum=0;
printf("\n\tEnter the number of terms you want in series : ");
scanf("%d",&num);
sum=expo(num);
printf("\n\n\t The sum of series is : %1.3f ",sum);
getch();
case 5:
clrscr();
sum=0;
printf("\n\t Enter the n'th term of the series : ");
scanf("%d",&num);
sum=natural(num);
printf("\n\n\t The sum of series is %10.0f ",sum);

Prakritee John Page 40


BCA 1st YEAR 2021 - 2022

getch();
default :
clrscr();
printf("\n\t Invalid Entry !!!");
getch();
}
getch();
}
Output :

Prakritee John Page 41


BCA 1st YEAR 2021 - 2022

Practical No. 12: Write a function to accept 10 Characters and display


weather each input character, digit , uppercase letter or lower case
letter .
Program :
#include<stdio.h>
#include<conio.h>
void identity(char *a)
{
if(*a>=48 && *a<=57 )
printf("\n\n\t The entered character is a number");
else
if( *a>=65 && *a<=90 )
printf("\n\n\t The entered character is a uppercase letter");
else
if( *a>=97 && *a<=122 )
printf("\n\n\t The entered character is a lowercase letter");
else
printf("\n\n\t The entered character is a special symbol");
getch();
}
void main()
{
int i;
static char a[1];
clrscr();
for(i=0;i<=9;i++)
{
printf("\n\n\tEnter any character : ");
scanf("%c",&a);
identity(a);
clrscr();
}
getch();
}
Output :

Prakritee John Page 42


BCA 1st YEAR 2021 - 2022

Prakritee John Page 43


BCA 1st YEAR 2021 - 2022

Practical No. 13: Create a structure Student having data members to


store roll number , name of student , name of three subjects , max
marks , obtained marks . Declare a structure variable of student .
Provide facilities to input data in data members and display result of
student.
Program :
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
struct student
{
int roll;
char name[15];
char s1[12],s2[12],s3[12];
int max,min,obt;
};
struct student x;
char option='y';
int p=x.max+1,q=x.max+1,r=x.max+1;
clrscr();
while(option=='y')
{
clrscr();
printf("\n\n\tEnter the roll number : ");
scanf("%d",&x.roll);
printf("\n\tEnter the name of the student : ");
scanf("%s",&x.name);
printf("\n\tEnter the name of first subject : ");
scanf("%s",&x.s1);
printf("\n\tEnter the name of second subject : ");
scanf("%s",&x.s2);
printf("\n\tEnter the name of third subject : ");
scanf("%s",&x.s3);
printf("\n\tEnter the maximum marks that can be obtained in each subject : ");
scanf("%d",&x.max);
printf("\n\tEnter the minimum marks that must be obtained to pass the exam : ");
scanf("%d",&x.min);
while(p>=x.max)
{
printf("\n\tEnter the marks obtained in %s : ",x.s1);
scanf("%d",&p);

Prakritee John Page 44


BCA 1st YEAR 2021 - 2022

if(p>x.max)
printf("\n\t Invalid Input !!!");
getch();
}
while(q>=x.max)
{
printf("\n\tEnter the marks obtained in %s : ",x.s2);
scanf("%d",&q);
if(q>x.max)
printf("\n\t Invalid Input !!!");
getch();
}
while(r>=x.max)
{
printf("\n\tEnter the marks obtained in %s : ",x.s3);
scanf("%d",&r);
if(r>x.max)
printf("\n\t Invalid Input !!!");
getch();
}
clrscr();
x.obt=p+q+r;
printf("\n\t Roll number : %d",x.roll);
printf("\n\n\t Name of student : %s",x.name);
printf("\n\n\t %-18s: %d",x.s1,p);
printf("\n\n\t %-18s: %d",x.s2,q);
printf("\n\n\t %-18s: %d",x.s3,r);
printf("\n\n\t maximum marks : %d",x.max);
printf("\n\n\t minimum marks : %d",x.min);
printf("\n\n\t obtained marks : %d",x.obt);
if(x.obt<((3*x.max)/3) || p<x.min || q<x.min || r<x.min)
printf("\n\n\t You are Fail ");
else
printf("\n\n\t Congratulations !! You are pass ");
getch();
clrscr();
printf("\n\n\n\n\tDo you want to countinue press y\n");
option=getch();
}
getch();
}
Output :

Prakritee John Page 45


BCA 1st YEAR 2021 - 2022

Prakritee John Page 46


BCA 1st YEAR 2021 - 2022

Practical No. 14: Create a structure Date with data member’s dd , mm


, yy (to store date). Create another structure Employee with data
members to hold name of employee id and date of joining (date of
joining will be hold by variable of structure Date which appears as
data member in Employee Structure) . Store data of an employee and
print the same .
Program :
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
struct date
{
int dd;
int mm;
int yy;
};
struct employee
{
char name[12];
int id;
struct date doj;
};
struct employee x;
clrscr();
printf("\n\tEnter Employee ID : ");
scanf("%d",&x.id);
printf("\n\tEnter the name of Employee : ");
scanf("%s",&x.name);
printf("\n\tEnter the date of joining : ");
scanf("%d",&x.doj.dd);
printf("\n\tEnter the month of joining : ");
scanf("%d",&x.doj.mm);
printf("\n\tEnter the year of joining : ");
scanf("%d",&x.doj.yy);
clrscr();
printf("\n\t Employee ID : %d",x.id);
printf("\n\t Employee name : %s",x.name);
printf("\n\t Joining date : %d / %d / %d",x.doj.dd,x.doj.mm,x.doj.yy);
getch();
}
Output :
Prakritee John Page 47
BCA 1st YEAR 2021 - 2022

Prakritee John Page 48


BCA 1st YEAR 2021 - 2022

Practical No. 15: Write a program to create structure complex having


data members to store real and imaginary part. Provide following
facilities :
a) Add two complex nos. using structure variables.
b) Subtract two complex nos. using structure variables.
c) Multiply two complex nos. using structure variables.
d) Divide two complex nos. using structure variables.
Program :
#include<stdio.h>
#include<conio.h>
#define san 40.0
#define nil 10.0
struct complex
{ double real,imag;
};
struct complex complex_set(double r, double i);
struct complex complex_add(struct complex ,struct complex);
struct complex complex_sub(struct complex ,struct complex);
struct complex complex_mul(struct complex ,struct complex);
struct complex complex_div(struct complex ,struct complex);
void complex_print(struct complex );
void main()
{ struct complex a,b,c,n,m,d;
clrscr();
a=complex_set(san,nil);
b=complex_set(san,nil
);
c=complex_add(a,b);
printf("%lf",c);
printf("\n");
complex_print(c);
printf("\n\n");
n=complex_sub(a,b);
printf("%lf",n);
printf("\n");
complex_print(n);
printf("\n\n");
m=complex_mul(a,b);
printf("%lf",m);
printf("\n");
complex_print(m);
printf("\n\n");
d=complex_div(a,b);

Prakritee John Page 49


BCA 1st YEAR 2021 - 2022

printf("%lf",d);
printf("\n");
complex_print(d);
getch();
}
struct complex complex_set(double r,double i)
{ struct complex temp;
temp.real=r;
temp.imag=i;
return (temp);
}
void complex_print(struct complex t)
{ printf("%lf %lf",t.real,t.imag);
}
struct complex complex_add(struct complex c1,struct complex c2)
{ struct complex temp;
temp.real=c1.real+c2.real;
temp.imag=c1.imag+c2.imag;
return (temp);
}
struct complex complex_sub(struct complex c1,struct complex c2)
{ struct complex temp;
temp.real=c1.real-c2.real;
temp.imag=c1.imag-c2.imag;
return (temp);
}
struct complex complex_mul(struct complex c1,struct complex c2)
{ struct complex temp;
temp.real=c1.real*c2.real;
temp.imag=c1.imag*c2.imag;
return (temp);
}
struct complex complex_div(struct complex c1,struct complex c2)
{ struct complex temp;
temp.real=c1.real/c2.real;
temp.imag=c1.imag/c2.imag;
return (temp);
}
Output :

Prakritee John Page 50


BCA 1st YEAR 2021 - 2022

Practical No. 16: Define union Emp having data members :- One
integer , One float and one single dimension character array. Declare
union variable in main and test the union variable.
Program :
#include<stdio.h>
#include<conio.h>
void main()
{
union emp
{ int x;
float y;
char z[10];
};
union emp a;
clrscr();
printf("\n\tEnter any integer value : ");
scanf("%d",&a.x);
printf("\n\tEnter any float value : ");
scanf("%f",&a.y);
printf("\n\tEnter any String : ");
scanf("%s",&a.z);
clrscr();
printf("\n\n\t Integer : %d",a.x);
printf("\n\t String : %s",a.z);
printf("\n\t Float : %.2f",a.y);
getch();
}
Output :

Prakritee John Page 51


BCA 1st YEAR 2021 - 2022

Practical No. 17: Define an enum Days_of_week members of which


will be days of week.Declare an enum variable in main and test it.
Program :
#include<stdio.h>
#include<conio.h>
void main()
{
enum Days_of_week
{
sunday,monday,tuesday,wednasday,thursday,friday,saturday
};
enum Days_of_week day;
clrscr();
day=sunday;
printf("\n\t%d",day);
printf("\t : sunday");
day=monday;
printf("\n\t%d",day);
printf("\t : monday");
day=tuesday;
printf("\n\t%d",day);
printf("\t : tuesday");
day=wednasday;
printf("\n\t%d",day);
printf("\t : wednasday");
day=thursday;
printf("\n\t%d",day);
printf("\t : thursday");
day=friday;
printf("\n\t%d",day);
printf("\t : friday");
day=saturday;
printf("\n\t%d",day);
printf("\t : saterday");
getch();
}
Output :

Prakritee John Page 52


BCA 1st YEAR 2021 - 2022

Practical No. 18: Write a program of swapping two numbers that


demonstrates call by value and call by reference .
Program :
#include<stdio.h>
#include<conio.h>
void cbw(int x,int y)
{
int z;
z=x;
x=y;
y=z;
printf("\n\t Swapping of a and b by call by value\n\n");
printf("\n\t The value of a is : %d",x);
printf("\n\t The value of b is : %d",y);
getch();
}
void cbr(int *x,int *y)
{
int z;
z=*x;
*x=*y;
*y=z;
getch();
}
void main()
{
int a,b,c,d;
clrscr();
printf("\n\t Enter any number a : ");
scanf("%d",&a);
printf("\n\t Enter any number b : ");
scanf("%d",&b);
printf("\n\t Enter any number c : ");
scanf("%d",&c);
printf("\n\t Enter any number d : ");
scanf("%d",&d);
clrscr();
cbw(a,b);
cbr(&c,&d);
clrscr();
printf("\n\t\t Swapping of c and d by call by reference");
printf("\n\n\n\t The value of c is : %d",c);
printf("\n\t The value of d is : %d",d);
getch();

Prakritee John Page 53


BCA 1st YEAR 2021 - 2022

}
Out put :

Prakritee John Page 54


BCA 1st YEAR 2021 - 2022

Practical No. 19: Write program to find biggest number among three
numbers using pointer and function.
Program :
#include<stdio.h>
#include<conio.h>
int gre(int *x,int *y,int *z)
{
if(*x>*y && *x>*z)
return(*x);
else if(*y>*z)
return(*y);
else
return(*z);
}
void main()
{
int a,b,c,*x,*y,*z,i;
clrscr();
printf("\n\tEnter first number : ");
scanf("%d",&a);
printf("\n\tEnter second number : ");
scanf("%d",&b);
printf("\n\tEnter third number : ");
scanf("%d",&c);
x=&a;
y=&b;
z=&c;
i=gre(x,y,z);
printf("\n\n\tThe Greatest of all the three numbers is : %d",i);
getch();
}
Output :

Prakritee John Page 55


BCA 1st YEAR 2021 - 2022

Practical No. 20: Write a program to demonstrate pointer arithmetic .


Program :
#include<stdio.h>
#include<conio.h>
void main()
{ int a,b,*c,*d,sum,sub,div,mul;
float area,r,*s;
clrscr();
printf("\n\tEnter any integer value : ");
scanf("%d",&a);
printf("\n\tEnter any integer value : ");
scanf("%d",&b);
printf("\n\tEnter the radius of the circle : ");
scanf("%f",&r);
c=&a;
d=&b;
s=&r;
sum=*c + *d;
sub=*c - *d;
div=*c/ *d;
mul=*c * *d;
area=3.14* *s * *s;
printf(" \n\n\t Addition of the pointer expression : %d",sum);
printf(" \n\n\t The subtraction of the pointer expression : %d",sub);
printf(" \n\n\t The division of the pointer expression : %d",div);
printf(" \n\n\t The multiplication of the pointer expression : %d",mul);
printf(" \n\n\t The area of the circle : %.2f",area);
getch();
}
Output :

Prakritee John Page 56


BCA 1st YEAR 2021 - 2022

Prakritee John Page 57

You might also like