C Programming Lab - Manual Final
C Programming Lab - Manual Final
C Programming Lab - Manual Final
Workbook
Name
Roll No.
Branch
Year/Section
Semester
Academic Year
23ADL001 - C Programming Laboratory
Name : _________________________________
Class : _________________________________
Certified that this is bonafide record of work done by the above student of the
_____________________________ _____________________________
Staff In-Charge Head of the Department
_____________________________ _____________________________
Internal Examiner External Examiner
List of Exercises
Average(out of 75)
AIM:
To develop a C program to perform basic mathematical and logical operations using
primitive datatypes.
1-a) Write a program to perform basic arithmetic operations (addition, subtraction, multiplication,
division) on two integers.
ALGORITHM:
Step 1: Start the process
Step 2: Get two integers as input from the user
Step 3: Calculate sum, difference, product and division for given inputs
Step 4: Print the output
Step 5: Stop the process.
FLOW CHART:
START
READ a, b
c1 = a + b
c2 = a - b
c3 = a * b
c4 = a / b
STOP
PROGRAM:
#include<stdio.h>
void main( )
{
int a,b,c1,c2,c3,c4;
clrscr( );
printf(\n Enter a,b:”);
scanf(“%d%d”,&a,&b);
c1=a+b;
c2=a-b;
c3=a*b;
c4=a/b;
printf(“\n Addition result=%d”,c1);
printf(“\n Subtraction result=%d”,c2);
printf(“\n Multiplication result=%d”,c3);
printf(“\n division result=%d”,c4);
getch( );
}
OUTPUT:
1-b) Create a program that calculates the area of a circle using the radius (floating-point
arithmetic).
ALGORITHM:
Step 1: Start the process.
Step 2: Enter the radius of the circle from the user.
Step 3: Calculate the area of the circle with the formula
Step 4: Print the result (i.e.) area of the circle.
Step 5: Stop the process.
FLOW CHART:
START
READ r
area = 3.14*r*r
PRINT area
STOP
PROGRAM:
#include<stdio.h>
void main( )
{
float r,area;
clrscr( );
printf(“\n Enter radius of a circle:”);
scanf(“%f”,&r);
area=3.14*r*r;
printf(“\n Area of circle=%f”,area);
getch( );
}
OUTPUT:
1-c) Implement a program that takes a character as input and checks whether it is a vowel or a
consonant.
ALGORITHM:
Step 1: Start the process.
Step 2: Read one character from the user and store it in a variable "ch"
Step 3: Compare "ch" with the vowels in both upper and lower case.
Step 4: If it matches print "vowel" else print "Consonant".
Step 5: Stop the process.
FLOW CHART:
START
READ ch
if(ch==’A’ || ch==’E’ ||
T ch==’I’ || ch==’O’ || || F
ch==’U’ ch==’a’ || ch==’e’ ||
ch==’i’ || ch==’o’ || ch==’u’)
STOP
PROGRAM:
#include<stdio.h>
void main()
{
char ch;
clrscr();
printf(“\n Enter a character:”);
scanf(“%c”,&ch);
if(ch==’A’ || ch==’E’ || ch==’I’ || ch==’O’ || ch==’U’ || ch==’a’ || ch==’e’ || ch==’i’ ||
ch==’o’ || ch==’u’)
{
printf(“\n The given character is a vowel”);
}
else
{
printf(“\n The given character is a consonant”);
}
getch();
}
OUTPUT:
RESULT:
Thus the C program to perform basic mathematical and logical operations using primitive
datatypes was developed and output was verified successfully.
Evaluation by Faculty
Criteria Marks
Preparation /20
Observation /25
Record /20
Viva /10
Total /75
Faculty Signature with Date
2. Implement programs using Operators and Expressions
2-a) Create a program that calculates and prints the remainder when dividing two integers.
2-b) Write a program that demonstrates the use of increment and decrement operators.
2-c) Implement a program to compare two numbers using relational operators (>, <, >=, <=, ==,
!=).
AIM:
To implement C program to perform basic operations using Operators and Expressions.
2-a) Create a program that calculates and prints the remainder when dividing two integers.
ALGORITHM:
Step 1: Start the process
Step 2: Get two integers as input from the user
Step 3: Perform division operation
Step 4: Print the remainder.
Step 5: Stop the process.
FLOW CHART:
START
READ a, b
quotient = a / b
remainder = a % b
STOP
PROGRAM:
#include<stdio.h>
void main()
{
int a,b,quotient, remainder;
clrscr();
printf(“\n Enter a,b:”);
scanf(“%d%d”,&a,&b);
quotient=a/b;
remainder=a%b;
printf(“\n Quotient=%d”,quotient);
printf(“\n Remainder=%d”,remainder);
getch();
}
OUTPUT:
2-b) Write a program that demonstrates the use of increment and decrement operators.
ALGORITHM:
Step 1: Start the process
Step 2: Get inputs from user
Step 3: Perform increment and decrement operation.
Step 4: Print the result.
Step 5: Stop the process.
FLOW CHART:
START
READ a, b, c, d
p = a++
q = ++b
r = c--
s = --d
PRINT a, b, c, d, p, q, r, s
STOP
PROGRAM:
#include<stdio.h>
void main( )
{
int a,b,c,d,p,q,r,s;
clrscr( );
printf(“\n Enter a,b,c,d:”);
scanf(“%d%d%d%d”,&a,&b,&c,&d);
p=a++;
q=++b;
r=c--;
s=--d;
printf(“\n a=%d”,a);
printf(“\n b=%d”,b);
printf(“\n c=%d”,c);
printf(“\n d=%d”,d);
printf(“\n p=%d”,p);
printf(“\n q=%d”,q);
printf(“\n r=%d”,r);
printf(“\n s=%d”,s);
getch( );
}
OUTPUT:
2-c) Implement a program to compare two numbers using relational operators (>, <, >=, <=, ==,
!=).
ALGORITHM:
Step 1: Start the process
Step 2: Get two integers as input from the user
Step 3: Compare the values using relational operators
Step 4: Print the result.
Step 5: Stop the process.
FLOW CHART:
START
READ a, b
PRINT 1 PRINT 0
STOP
PROGRAM:
#include<stdio.h>
void main( )
{
int a,b;
clrscr( );
printf(“\n Enter a,b:”);
scanf(“%d%d”,&a,&b);
printf(“%d > %d: %d \n”,a,b,a>b);
printf(“%d < %d: %d \n”,a,b,a<b);
printf(“%d >= %d: %d \n”,a,b,a>=b);
printf(“%d <= %d: %d \n”,a,b,a<=b);
printf(“%d == %d: %d \n”,a,b,a==b);
printf(“%d != %d: %d \n”,a,b,a!=b);
getch( );
}
OUTPUT:
RESULT:
Thus the C program to perform basic operations using operators and expressions was
developed and output was verified successfully.
Evaluation by Faculty
Criteria Marks
Preparation /20
Observation /25
Record /20
Viva /10
Total /75
Faculty Signature with Date
3. Develop Programs using Branching statements
3-a) Write a program that takes an integer as input and prints whether it is positive, negative, or
zero using if-else statements.
3-b) Implement a program that checks whether a given year is a leap year using conditional
statements.
3-c) Implement a calculator program to do simple commercial calculator operations like addition,
subtraction, multiplication and division using a switch case statement.
3-d) Implement a program that uses a ‘for’ loop to calculate the factorial of a given number.
AIM:
To develop C Program to perform basic operations using branching statements.
3-a) Write a program that takes an integer as input and prints whether it is positive, negative, or
zero using if-else statements.
ALGORITHM:
Step 1: Start the process
Step 2: Get a value as input from the user
Step 3: Check whether that value is a zero or a positive number or a negative number
using if else statements.
Step 4: Print the result.
Step 5: Stop the process.
FLOW CHART:
START
READ n
If(n==0)
F F F
If(n>0) If(n<0)
T T T
STOP
PROGRAM:
#include<stdio.h>
void main( )
{
int n;
clrscr( );
printf(“\n Enter n:”);
scanf(“%d”,&n);
if(n==0)
{
printf(“\n The given value is zero”);
}
else if(n>0)
{
printf(“\n The given value is a positive number”);
}
else if(n<0)
{
printf(“\n The given value is a negative number”);
}
else
{
printf(“\n Please enter a valid number”);
}
getch( );
}
OUTPUT:
3-b) Implement a program that checks whether a given year is a leap year using conditional
statements.
ALGORITHM:
Step 1: Start the process
Step 2: Get a year as input from the user
Step 3: Check whether that year is a leap year or not.
Step 4: Print the result.
Step 5: Stop the process.
FLOW CHART:
START
READ year
T T T
STOP
PROGRAM:
#include<stdio.h>
void main()
{
int year;
clrscr( );
printf("\n Enter year:");
scanf("%d",&year);
if(year%400==0)
{
printf("It ia a leap year");
}
else if(year%100==0)
{
printf("\n It is a not leap year");
}
else if(year%4==0)
{
printf("\n It is a leap year");
}
else
{
printf("\n It is not a leap year");
}
getch( );
}
OUTPUT:
3-c) Implement a calculator program to do simple commercial calculator operations like addition,
subtraction, multiplication and division using a switch case statement.
ALGORITHM:
Step 1: Start the process
Step 2: Get an operator (+, -, *, /) as input from user
Step 3: Get two values as inputs from the user.
Step 4: Perform the specific calculation.
Step 5: Print the result.
Step 6: Stop the process.
FLOW CHART:
START
READ op
READ a, b
Switch(op)
case ‘+’
a+b
case ‘-’
a-b
PRINT RESULT
case ‘*’
a*b
3-d) Implement a program that uses a ‘for’ loop to calculate the factorial of a given number.
ALGORITHM:
Step 1: Start the process
Step 2: Get a value as input from the user
Step 3: Find the factorial value for the given input value
Step 4: Print the result.
Step 5: Stop the process.
FLOW CHART:
START
READ n
fact=1
i=1
F
i<=n PRINT fact
fact=fact*i STOP
i++
PROGRAM:
#include<stdio.h>
int main()
{
int n,i,fact=1;
clrscr( );
printf("\n Enter a number: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("Factorial of %d is %d",n,fact);
getch( );
}
OUTPUT:
RESULT:
Thus the C program to perform basic operations using branching statements was
developed and output was verified successfully.
Evaluation by Faculty
Criteria Marks
Preparation /20
Observation /25
Record /20
Viva /10
Total /75
Faculty Signature with Date
4. Implement Programs using Control Structures
4 –a) Write a program to generate the Fibonacci series up to a given number using a while loop.
4-b) Write a program that checks whether a given number is an Armstrong number or not using
loops and conditionals.
AIM:
To develop a C program to perform basic operations using control structures.
4 –a) Write a program to generate the Fibonacci series up to a given number using a while loop.
ALGORITHM:
Step 1: Start the process.
Step 2: Get the limit of the Fibonacci series.
Step 3: Calculate the Fibonacci series using while loop.
Step 4: Display the result.
Step 5: Stop the process.
FLOW CHART:
START
f1=-1
f2=1
READ n
F
i<=n STOP
PRINT fact
f3=f1+f2
f1=f2
f2=f3
i++
PROGRAM:
#include<stdio.h>
void main( )
{
int f1,f2,f3,i=1,n;
f1=-1;
f2=1;
clrscr( );
printf(“\n Enter total numbers:”);
scanf(“%d”,&n);
printf(“\n The Fibonacci series is \n”);
while(i<=n)
{
f3=f1+f2;
f1=f2;
f2=f3;
printf(“%d \n”,f3);
i++;
}
getch( );
}
OUTPUT:
4-b) Write a program that checks whether a given number is an Armstrong number or not using
loops and conditionals.
ALGORITHM:
Step 1: Start the process.
Step 2: Get a number as input.
Step 3: Check whether that number is an Armstrong number or not using loops and
conditionals.
Step 4: Display the result.
Step 5: Stop the process.
FLOW CHART:
START
sum=0
READ n
temp=n
F F
n>0 temp=sum
T T
f3=f1+f2
f1=f2
PRINT PRINT not an
f2=f3
Armstrong Armstrong
number number
STOP
PROGRAM:
#include<stdio.h>
void main( )
{
int n,r,sum=0,temp;
clrscr( );
printf(“\n Enter a number:”);
scanf(“%d”,&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp= =sum)
{
printf(“%d is an armstrong number”,temp);
}
else
{
printf(“%d is not an armstrong number”,temp);
}
getch( );
}
OUTPUT:
RESULT:
Thus the C program to perform basic operations using control structures was developed
and output was verified successfully.
Evaluation by Faculty
Criteria Marks
Preparation /20
Observation /25
Record /20
Viva /10
Total /75
Faculty Signature with Date
5. Develop programs using Arrays
5-a) Create a program that finds the largest and smallest elements in an array of numbers.
5-b) Create a program to add two matrices and print the result.
AIM:
To develop a C program to perform operations on one dimensional and two dimensional
array.
5-a) Create a program that finds the largest and smallest elements in an array of numbers.
ALGORITHM:
Step 1: Start the process.
Step 2: Get array values as inputs from user.
Step 3: Initialize the small and large variable with a[0].
Step 4: Now traverse the array iteratively and keep track of the smallest and largest
element until the end of the array.
Step 5: In the last, will get the smallest and largest number in the variable small and
large respectively.
Step 6: Print both the variables.
Step 7: Stop the process.
FLOW CHART:
START
READ n, a[i]
small=a[0]
large=a[0]
T T
small=a[i] large=a[i]
PRINT
small, large STOP
PROGRAM:
#include <stdio.h>
void main()
{
int a[10],n,i,small,large;
clrscr();
printf("\n Enter the size of the array:");
scanf("%d",&n);
printf("\n Enter array values one by one:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
small=a[0];
large=a[0];
for(i=1;i<n;i++)
{
if(small>a[i])
{
small=a[i];
}
if(large<a[i])
{
large=a[i];
}
}
printf("\n The smallest value in the array=%d",small);
printf("\n The largest value in the array=%d",large);
getch();
}
OUTPUT:
5-b) Create a program to add two matrices and print the result.
ALGORITHM:
Step 1: Start the process.
Step 2: Get row size and column size as inputs from user.
Step 3: Get two array values as inputs from user.
Step 4: Add the values of two matrices.
Step 5: Print the result.
Step 6: Stop the process.
FLOW CHART:
START
F
i<=n PRINT c[i][j]
i++
STOP
PROGRAM:
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],m,n,i,j;
clrscr();
printf("\n Enter row and column size:");
scanf("%d%d",&m,&n);
printf("\n Enter the values of first array:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n Enter the values of second array:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("\n The array values after addition:");
for(i=0;i<n;i++)
{
printf("\n\t");
for(j=0;j<n;j++)
{
printf("\t%d",c[i][j]);
}
}
getch();
}
OUTPUT:
RESULT:
Thus the C program to perform operations on one dimensional and two dimensional
array was developed and output was verified successfully.
Evaluation by Faculty
Criteria Marks
Preparation /20
Observation /25
Record /20
Viva /10
Total /75
Faculty Signature with Date
6. Implement programs using Functions
6-a) Write a program that checks whether a given number is prime using a function.
6-b) Develop a program that calculates the sum of elements in an array using a separate
function.
6-c) Create a program that reverses the elements of an array using a function.
AIM:
To implement C program to perform basic operations using functions.
6-a) Write a program that checks whether a given number is prime using a function.
ALGORITHM:
Step 1: Start the process.
Step 2: Get a number as input.
Step 3: Check whether that number is prime number or not using function.
Step 4: Display the result.
Step 5: Stop the process.
FLOW CHART:
START
READ n
I=2
F F
PRINT
i<=n/2 r==0 Not Prime number
T T
n%i==0 PRINT
Prime number STOP
flag++
i++
PROGRAM:
#include <stdio.h>
void main()
{
int prime(int);
int n,r;
clrscr( );
printf("\n Enter a number:");
scanf("%d",&n);
r=prime(n);
if(r==0)
{
printf("%d is a prime number",n);
}
else
{
printf("%d is a not prime number",n);
}
getch( );
}
int prime(int x)
{
int flag=0,i;
for(i=2;i<=x/2;i++)
{
if(x%i==0)
{
flag++;
break;
}
}
return(flag);
}
OUTPUT:
6-b) Develop a program that calculates the sum of elements in an array using a separate
function.
ALGORITHM:
Step 1: Start the process.
Step 2: Get array values as inputs from user.
Step 4: Calculate sum of all elements in an array using a separate function.
Step 5: Print the result.
Step 6: Stop the process.
FLOW CHART:
START
READ n, a[i]
sum=0, i=0
sum=sum+a[i]
i++
STOP
PROGRAM:
#include <stdio.h>
void main()
{
int add(int[],int);
int a[10],n,r,i;
clrscr();
printf("\n Enter the size of the array:");
scanf("%d",&n);
printf("\n Enter array values one by one:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
r=add(a,n);
printf("\n Sum=%d",r);
getch();
}
int add(int x[],int y)
{
int sum=0,j;
for(j=0;j<y;j++)
{
sum=sum+x[j];
}
return(sum);
}
OUTPUT:
6-c) Create a program that reverses the elements of an array using a function.
ALGORITHM:
Step 1: Start the process.
Step 2: Get array values as inputs from user.
Step 4: Reverse the elements of an array using a function.
Step 5: Print the result.
Step 6: Stop the process.
FLOW CHART:
START
READ n, a[i]
j=n-1
F
j>=0 STOP
PRINT a[j]
j--
PROGRAM:
#include <stdio.h>
void main()
{
int add(int[],int);
int a[10],n,r,i;
clrscr();
printf("\n Enter the size of the array:");
scanf("%d",&n);
printf("\n Enter array values one by one:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
add(a,n);
getch();
}
int add(int x[],int y)
{
int j;
printf("\n The array values after reverse:");
for(j=y-1;j>=0;j--)
{
printf("\n%d",x[j]);
}
}
OUTPUT:
RESULT:
Thus the C program to perform basic operations using functions was developed and
output was verified successfully.
Evaluation by Faculty
Criteria Marks
Preparation /20
Observation /25
Record /20
Viva /10
Total /75
Faculty Signature with Date
7. Implement programs using String Operations
7-b) Implement a program that checks whether a given string is a palindrome or not.
AIM:
To implement C program to perform basic operations in strings using string functions.
ALGORITHM:
Step 1: Start the process.
Step 2: Get two strings as inputs from user.
Step 4: Perform various sting functions such as strlen(), strcpy(),strlwr(),strupr()
strcat(),strrev().
Step 5: Print the result.
Step 6: Stop the process.
FLOW CHART:
START
READ S1,S2
n1=strlen(s1)
n2=strlen(s2)
strcpy(s1,s2)
strlwr(s1)
strupr(s2)
strcat(s1,s2)
strrev(s1)
PRINT result
STOP
PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
{
char s1[10],s2[10],s3[20];
int n1,n2,n3;
clrscr();
printf("\n Enter two strings:");
scanf("%s%s",&s1,&s2);
n1=strlen(s1);
n2=strlen(s2);
printf("\n Length of string 1=%d",n1);
printf("\n Length of string 2=%d",n2);
strcpy(s1,s2);
printf("\n String1 after copy=%s",s1);
printf("\n String2 after copy=%s",s2);
strlwr(s1);
strupr(s2);
printf("\n Lower case of string1=%s",s1);
printf("\n Upper case of string2=%s",s2);
strcat(s1,s2);
printf("\n Joined string=%s",s1);
strrev(s1);
printf("\n Reverserd string of String1=%s",s1);
getch();
}
OUTPUT:
7-b) Implement a program that checks whether a given string is a palindrome or not.
ALGORITHM:
Step 1: Start the process.
Step 2: Get a string as input from user.
Step 4: Check whether the string is a palindrome or not..
Step 5: Print the result.
Step 6: Stop the process.
FLOW CHART:
START
c=0
READ s
n=strlen(s)
F F
T T
s[i]==s[n-i-1]
PRINT
Palindrome STOP
c++
PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
{
char s[10];
int n,i,c=0;
clrscr();
printf("\n Enter a string:");
scanf("%s",&s);
n=strlen(s);
for(i=0;i<n/2;i++)
{
if(s[i]==s[n-i-1])
{
c++;
}
}
if(c==i)
{
printf("\n The given string is a palindrome");
}
else
{
printf("\n The given string is not a palindrome");
}
getch();
}
OUTPUT:
RESULT:
Thus the C program to perform basic operations in strings using string functions was
developed and output was verified successfully
Evaluation by Faculty
Criteria Marks
Preparation /20
Observation /25
Record /20
Viva /10
Total /75
Faculty Signature with Date
8. Develop programs using Pointers
8) Write a C program to perform arithmetic operations using pointers.
AIM:
To develop a C program to perform basic operations using pointer.
READ a, b
p1=&a
p2=&b
c1=(*p1)+(*p2)
c2=(*p1)-(*p2)
c3=++(*p1)
c4=--(*p2)
STOP
PROGRAM:
#include<stdio.h>
void main( )
{
int a=10,b=5,c1,c2,c3,c4;
int *p1,*p2;
clrscr( );
p1=&a;
p2=&b;
c1=(*p1)+(*p2);
c2=(*p1)-(*p2);
c3=++(*p1);
c4=--(*p2);
printf(“\n c1= %d”,c1);
printf(“\n c2= %d”,c2);
printf(“\n c3= %d”,c3);
printf(“\n c4= %d”,c4);
getch( );
}
OUTPUT:
RESULT:
Thus the C program to perform basic operations using pointer was developed and output
was verified successfully.
Evaluation by Faculty
Criteria Marks
Preparation /20
Observation /25
Record /20
Viva /10
Total /75
Faculty Signature with Date
9. Implement programs using Structures
9) Create a C program to display the information of N students using structure.
AIM:
To develop a C program to perform basic operations using structure.
START
READ n, name,
rollno,mark1,mark2,mark3
total=mark1+mark2+mark3
avg=total/3
PRINT result
STOP
PROGRAM:
#include<stdio.h>
struct student
{
char name[20];
int rollno,mark1,mark2,mark3,total;
float avg;
}s[10];
void main( )
{
int n,i;
clrscr( );
printf(“\n Enter number of students:”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf(“\n Enter student name:”);
scanf(“%s”,&s[i].name);
printf(“\n Enter rollno:”);
scanf(“%d”,&s[i].rollno);
printf(“\n Enter mark1::”);
scanf(“%d”,&s[i].mark1);
printf(“\n Enter mark2:”);
scanf(“%d”,&s[i].mark2);
printf(“\n Enter mark3:”);
scanf(“%d”,&s[i].mark3);
}
printf(“\n - - - - - - - - - - STUDENT SETAILS - - - - - - - - - - \n”);
for(i=0;i<n;i++)
{
printf(“\n Student name=%s”,s[i].name);
printf(“\n Roll no=%d”,s[i].rollno);
printf(“\n Mark1=%d”,s[i].mark1);
printf(“\n Mark2=%d”,s[i].mark2);
printf(“\n Mark3=%d”,s[i].mark3);
s[i].total=s[i].mark1+s[i].mark2+s[i].mark3;
s[i].avg=s[i].total/3;
printf(“\n Total=%d”,s[i].total);
printf(“\n Average=%f”,s[i].avg);
}
getch( );
}
OUTPUT:
RESULT:
Thus the C program to perform basic operations using structure was developed and
output was verified successfully.
Evaluation by Faculty
Criteria Marks
Preparation /20
Observation /25
Record /20
Viva /10
Total /75
Faculty Signature with Date
10. Develop programs using Union
AIM:
To develop a C program to perform basic operations using union.
10) Create a C program to display the employee details using union.
ALGORITHM:
Step 1: Start the process.
Step 2: Get employee name, employee id and salary as input..
Step 3: Display the result.
Step 4: Stop the process.
FLOW CHART:
START
STOP
PROGRAM:
#include<stdio.h>
union employee
{
char emp_name[10];
int emp_id,
float salary;
};
void main()
{
union employee s;
clrscr();
printf("\n Enter employee name:");
scanf("%s",&s.emp_name);
printf("\n Enter employee id:");
scanf("%d",&s.emp_id);
printf("\n Enter salary:");
scanf("%d",&s.salary);
printf("\n---------- EMPLOYEE DETAILS ----------\n");
printf("\n Employee name=%s",s.emp_name);
printf("\n Employee id=%d",s.emp_id);
printf("\n Salary=%d",s.salary);
getch();
}
OUTPUT:
RESULT:
Thus the C program to perform basic operations using union was developed and output
was verified successfully.
Evaluation by Faculty
Criteria Marks
Preparation /20
Observation /25
Record /20
Viva /10
Total /75
Faculty Signature with Date