Professional Documents
Culture Documents
CP Labmanual
CP Labmanual
PRACTICE LABORATORY-I
LIST OF EXPERIMENTS:
9. Program using Recursive Function and conversion from given program to flow
chart.
TOTAL: 45 PERIODS
Flowcharts by
A) Word Processing
B) Spread Sheet
A. Word Processing
Scientific Notation
Procedure:
Step 2: Alignment
For Left Alignment press Ctrl+L or press Align Left Button on the
formatting toolbar.
Select the text where you want to add Bullets and Numberings.
Then click Bullets on the Formatting Tool Bar or choose Bullets and
Numbering option from the Format menu. It shows the Bullets and
Numbering dialog box .
Choose Select All option from Edit menu or by pressing Ctrl +A.
Type the text, then put the cursor where you want to add the symbol.
Step 5: Equations
For Subscript, Choose the Font option from the Format menu, then enable
the superscript check box from the Font dialog box.
To enter a header that repeats on all pages in your document choose Header
and footer.
Procedure:
Step 1: For Table Insertion
Procedure:
Step1: Mail Merge
Select File option in the menu bar and click New, to open a new document.
From the Tools menu select the mail merge
It shows the mail merge helper dialog box.
In the Main Document area of mail merge helper dialog box, click on
create button.
Step 2: Creating a data source
In the mail merge helper dialog box, click Get data button
select create Data source... to get create Data Source dialog box.
Step 3: Creating the merged document
Click on the Insert Merged Field on the mail merge toolbar.
Selected the desired results from the drop down menu of the insert merge
field.
After inserting the merge fields, choose Tools->mail merge
Step 4: Printing labels
Choose tools->Envelopes and labels option
It shows the Envelopes and labels dialog box.
Step 5: Printing envelope letters
Choose Tools->Envelope and Labels option.
It shows Envelope and Labels dialog box.
Procedure:
Step 1: Drawing Picture
Choose the Up Ribbon option in the Stars and Banners of the Auto
Shapes menu in the Drawing Toolbar.
Type the text in the Symbol, but right click then choose Add Text.
Using the Arrow button Line Style Using the Arrow button Line Style Arrow
Style in the drawing Toolbar draw the lines connecting to the different
flowchart symbols.
B. Spreadsheet
Procedure:
Step1: chart in excel
Enter the data in the Worksheet as follows
Choose Chart option from the Insert menu, or choose the chart wizard
button from the Insert menu, or choose the Chart Wizard button from the
Standard toolbar.
Choose the appropriate Chart type from the Chart type list box then click
Next.
Shows the Chart Wizard Step 2 of 4 Chart source Data dialog box, then
click Next.
Shows the Chart Wizard Step 3 of 4 Chart options dialog box, here we can
give the Chart Titles ie X and Y-Axis Titles etc then click Next.
Shows the Chart Wizard step 3 of 4 Chart Locations dialog box the click
Finish.
Procedure:
Step 1:For calculation
ex: Employee pay
Enter the employee details as shown in the table above
click in cell D2, type =IF(C2<8000,C2*56/100,C2*44/100)
click in cell F2, type =C2*0.1
click in cell G2, type =C2+D2+E2
Click in cell H2 type=G2-F2
copy the formulae to the remaining records
Place the cursor in H8,type=MAX(H2:H4)
The maximum salary will be displayed.) Place the cursor in
H9,type=MIN(H2:H4)
The minimum salary will be displayed.
ex: To find the sum of the marks
Enter the student name, marks in three subjects.
Place the cursor in E2, type=SUM (B2...D3)
Step 2:Conversions
Click Tools->Add ins dialog box
In the Add-ins dialog box, click the checkbox of Analysis toolpak,Analysis
toolpak-VBA
Click on A2, enter the decimal number in rows. Click on B2,
type=dec2bin(A2), copy the formula to the remaining, as it converts decimal
number to binary.
There are so many objects that can be inserted into the worksheets.
Choose appropriate object from the Auto shape menu of the Drawing
toolbar.
password to unprotect.
.
Step 7: Protecting the Workbook
Open the Workbook to protect.
Choose Tools->protection, then choose Protect Workbook, it shows the
Protect
Workbook dialog box asking the Password to protect sheet.
To remove protection, choose Tools->Protection->Unprotect sheet, then
type the same
Password to unprotect.
Procedure:
Step 1 : Enter the data into the Worksheet
Enter the Name, Department, Salary in different columns.
Click New button in the Form to add the rows to the list.
After adding the rows, place the cursor in the list in the worksheet.
Step 2: Subtotals
The Subtotals are helpful to analyze the data in the list and quickly
create reports and
Charts.
Procedure:
Press F5.
Usage of powerpoint:
Using Animation tab we give animation for the slides. In Design tab
it have various templates for slides
Using insert menu insert the pictures, shapes, cliparts, chart, textbox,
wordart and so on.
Aim: To write a program to find the area and circumference of the circle.
Algorithm:
Flow Chart:
Start
Read radius
Area=3.14 * r *r
circumference= 2 * 3.14 * r
Print
area,circumference
Stop
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
float radius,area,circum;
Output:
Algorithm:
Flow Chart:
Start
Read Celsius
Fahrenheit=(1.8*Celsius)+32
Print Fahrenheit
Stop
Source Code
#include<stdio.h>
#include<conio.h>
void main()
{
float cels,fah;
clrscr();
printf("Enter the temperature in Celsius:");
scanf("%f",&cels);
fah=(1.8*cels)+32;
printf("\nConverted Temperature is %.2f%cF",fah,248);
getch();
}
17 R. M. K COLLEGE OF ENGINEERING &T
ECHNOLOGY
-COMPUTER
PRACTICE LABORATORY-I
Output
Algorithm:
Flow Chart
Start
Stop
Source Code
#include<stdio.h>
#include<conio.h>
void main()
{
double a;
clrscr();
printf("\nSize of different datatypes in C");
printf("\n--------------------------------");
printf("\nSize of Integer : %d bytes",sizeof(int));
printf("\nSize of Long : %d bytes",sizeof(long));
printf("\nSize of Float : %d bytes",sizeof(float));
Output
y=sin 30
z=e3t+5
Step 4: Print the value of x,y and z.
Step 5: Stop the program
Flow Chart
Start
Read t
X=8*pow(t,2)-t+4
Y=sin
Z= exp(3*t+5)
Stop
Source Code
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x,y,z,t;
clrscr();
printf("Enter the value of t :");
scanf("%f",&t);
x=8*pow(t,2)-t*t*t+4;
y=sin(3.1415*30/180);
z=exp(3.0*t +5.0);
printf("\nx = %.3f, y = %.3f, z= %.3f", x,y,z);
getch();
}
Output
Aim: To write a C program to find the area of a triangle given the length of three sides
Algorithm:
Step 1: Start the program.
Step 2: Read the side lengths a, b and c
Step 3 : Calculate area using the formula
area =
where s = (a + b + c)/ 2
Step 4: Print the area
Step 5: Stop the program
Flow Chart
Start
Read a,b,c
s=(a+b+c)/2
area =
Print area
Stop
Program
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c, s, area;
clrscr();
printf("\nEnter the length of the three sides of the triangle:");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("\nArea of the Triangle :%.3f sq.meters",area);
getch();
}
Output
Aim: To write a C program to find the slope and midpoint of a given line segment.
Algorithm:
Midpoint=
Flow Chart
Start
Read the
endpoints (x1,y1)
and (x2,y2)
Slope=
Midpoint=
Print area
Stop
Source Code
#include<stdio.h>
#include<conio.h>
void main()
{
float x1,x2,y1,y2,slope,midX,midY;
clrscr();
printf("\nEnter the endpoints of a line");
printf("\nEndpoint 1 (x1,y1):");
scanf("%f%f",&x1,&y1);
printf("\nEndpoint 2 (x2,y2):");
scanf("%f%f",&x2,&y2);
slope=(float)(y2-y1)/(float)(x2-x1);
midX=(x1+x2)/2;
midY=(y1+y2)/2;
printf("\nSlope : %.2f",slope);
printf("\nMidpoint : (%.2f,%.2f)",midX,midY);
getch();
}
Output
Algorithm
first second
second next
Step 5: Print next in each iteration
Step 6: Stop the program
Flowchart
start
Read n
Initialize i=0
no
27 R. M. K COLLEGE OF ENGINEERING &T
ECHNOLOGY If
i<n
-COMPUTER
PRACTICE LABORATORY-I
yes
yes
If
i<=
1
no
next=i
next = first + second;
first = second;
second = next
i=i +1
Print next
stop
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int n, first = 0, second = 1, next, c;
printf("Enter the number of terms\n");
scanf("%d",&n);
printf("First %d terms of Fibonacci series are \n",n);
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
Algorithm:
Step 6 : Stop
FlowChart:
Start
Read bnum
Binbnum
Is
bnum=
0
bnum
Digital bnum % 10
Decimaldecimal+(digital< base)
Bnum bnum/10
Print
bin,decimal
Stop
Source Code:
#include<stdio.h.
main()
{
int bnum,digit,decimal=0,bin,base=0;
printf(\nEnter the binary number);
scanf(%d,&bnum);
printf(%d,bnum);
bin=bnum;
while(bnum!=0)
{
digit=bnum%10;
decimal=decimal+(digit< < base);
base=base+1;
bnum=bnum/10;
}
printf(\n The binary equivalent of %d in decimal = %d,bin,decimal);
}
Output:
Enter the binary number 100
The binary equivalent of 100 in decimal =4
Alogrithm:
Flow Chart:
start
Read
x,n
x=x*3.1412/180
for i=0;i<n;i++
T=(t*(pow(double)(1),(double
(2*i-1))*x*x)/(2*i*(2*i+1)
T1=(t1*pow((double)(1),
(double)
(2*i-1))*x*x)/(2*i*(2*i-1));
Print sum
stop
Source Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x,t,sum,t1,sum1;
int i,n;
clrscr();
printf("Enter the value of x,n : ");
scanf("%f%d",&x,&n);
printf("%4.2f %d\n",x,n);
x=x*3.1412/180;
t=x;
sum=x;
t1=x;
sum1=x;
for(i=1;i<n;i++)
{
t=(t*pow((double)(-1),(double)(2*i-1))*x*x)/(2*i*(2*i+1));
sum=sum+t;
}
for(i=1;i<n;i++)
{
t1=(t1*pow((double)(-1),(double)(2*i-1))*x*x)/(2*i*(2*i-1));
sum1=sum1+t1;
}
printf("The value of SINE(%f)=%6.4f\n",x,sum);
printf("the value of COSINE(%f)=%6.4f\n",x,sum1);
getch();
}
Output
Algorithm:
Step1: Start
Step 2: Enter the X and n Value.
Step 3: Set a loop upto n
Step 4: Find the exponent value of x
temp= temp* x / i
Sum= sum+ temp
Step 5: After the execution of the loop print the exponent value of x
Step 6: Stop
Flowchart
Start
read x,no
i=1
is Print
i<no Sum
i=i+
1
temp=temp * x /i Stop
Sum = sum + temp
Source Code:
// Exponential Series
#include<stdio.h>
main()
[
float x,temp=1,sum=1;
int i,no;
printf(Enter the numbers);
scanf(%f%d,&x,&no);
for(i=1;i<no;i++)
{
temp=temp * x / I;
sum=sum + temp;
}
printf(Exponent of x is %f\n,sum);
}
Output:
Enter the numbers
5
Exponent of x is 65.375000
Algorithm:
Flow Chart:
start
Read N no of
triangle
for(i=1;j=n-I;i<=n;i++;j--)
for(k=1;k<=l;k++)
for(k=1;k<=l;k++)
Print i
Increment I by2
stop
Source Code:
#include<stdio.h>
main()
{
int i,j,k,l,n;
printf(type n-no of lines in triangle \n);
scanf(%d,&n);
l=1;
for(i=1;j=n-i;i<=n,i++,j--)
{
for(k=1;k<=j;k++)
printf( );
for(k=1;k<=l;k++)
printf( %d,i);
printf((\n);
l+=2;
}
}
OUTPUT
Type N-no of lines in triangle
4
1
2 2 2
3 3 3 3 3
4 4 4 4 4 4 4
Algorithm:
Flowchart:
star
t
Read
choice,num
41 R. M. K COLLEGE OF ENGINEERING &T
ECHNOLOGY
-COMPUTER
PRACTICE LABORATORY-I
Original = num
yes
If(ch=
=1)
Compute Armstrong of
num
NO
If(ch= yes
=2)
Compute Palindrome of
num
NO
yes
If(ch=
=3)
Compute primality of
NO num
stop
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int choice,num,original,ans,r,i,flag;
clrscr();
do
{
printf("\n MENU");
printf("\n 1.Check Armstrong or not");
printf("\n 2.Check Palindrome or not");
printf("\n 3.Check Prime or not");
printf("\n 4.Exit");
printf("\nEnter your choice:");
scanf("%d",&choice);
printf("\nEnter the number:");
scanf("%d",&num);
original=num;
switch(choice)
{
case 1:
ans=0;
while(num>0)
{
r=num%10;
ans=ans+r*r*r;
num=num/10;
}
if(ans==original)
printf("%d is an armstrong number",original);
else
printf("%d is not an armstrong number",original);
break;
case 2:
ans=0;
while(num>0)
{
r=num%10;
ans=ans*10+r;
num=num/10;
}
if(ans==original)
printf("%d is palindrome",original);
else
printf("%d is not palindrome",original);
break;
case 3:
flag=0;
for(i=2;i<num/2;i++)
{
if(num%i==0)
{
flag=1;
break;
}
else
continue;
}
if(flag==1)
printf("%d is not a prime number",num);
else
printf("%d is a prime number",num);
break;
default:
exit(0);
}
}while(1);
}
Output
MENU
Algorithm:
If determinant = 0
If determinant<0
Flowchart:
start
Read
a,b, c
d =b2-4ac
yes
NO
No yes
r1 = r2 = -b/
(2*a)
Print
r1,r2
stop
Program
#include <stdio.h>
#include <math.h>
void main()
{
float a, b, c, determinant, r1,r2, real, imag;
printf("Enter coefficients a, b and c: ");
scanf("%f%f%f",&a,&b,&c);
determinant=b*b-4*a*c;
if (determinant>0)
{
r1= (-b+sqrt(determinant))/(2*a);
r2= (-b-sqrt(determinant))/(2*a);
Output
EX.NO.4 Simple programming for one dimensional and two dimensional arrays.
Ex. No: 4a linear search
Algorithm
Break
Program
#include<stdio.h>
#include<conio.h>
void main()
int a[10],item,size,pos,flag,i;
clrscr();
flag=1;
scanf("%d",&size);
for(i=0;i<size;i++)
scanf("%d",&a[i]);
scanf("%d",&item);
for(i=0;i<size;i++){
if(item==a[i])
pos=i;
flag=1;
break;
else
continue;
if(flag==1)
else
getch();
Output
20 is at position 3
Algorithm:
Break
Program:
#include<stdio.h>
#include<conio.h>
void main(){
int a[10],i,n,item,flag=0,low,high,mid;
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
scanf("%d",&item);
low=0,high=n-1;
while(low<=high){
mid=(low+high)/2;
if(item==a[mid]){
flag=1;
break;
else if(item<a[mid]){
high=mid-1;
else
low=mid+1;
if(flag==0)
else
getch();
Output
40 is at position 4
Algorithm
Program
#include<stdio.h>
#include<conio.h>
void main()
int a[10],temp,i,j,size;
clrscr();
scanf("%d",&size);
for(i=0;i<size;i++)
scanf("%d",&a[i]);
for(i=0;i<size;i++)
for(j=i+1;j<size;j++)
if(a[i]>a[j])
temp=a[i];
a[i]=a[j];
a[j]=temp;
printf("\nSorted Array");
for(i=0;i<size;i++)
printf("%d ",a[i]);
getch();
Output
Sorted Array 1 2 3 4 5
Algorithm
Step 3: Read the two matrices a and b of size rows x columns each
Program
#include<stdio.h>
#include<conio.h>
void main()
int a[3][3],b[3][3],c[3][3],i,j,row,col;
clrscr();
scanf("%d%d",&row,&col);
for(i=0;i<row;i++)
for(j=0;j<col;j++)
scanf("%d",&a[i][j]);
for(i=0;i<row;i++)
for(j=0;j<col;j++)
scanf("%d",&b[i][j]);
for(i=0;i<row;i++)
for(j=0;j<col;j++)
c[i][j]=a[i][j]+b[i][j];
for(i=0;i<row;i++){
for(j=0;j<col;j++){
printf("%d\t",c[i][j]);
printf("\n");
getch();
Output
2 3
4 5
1 5
2 9
The sum is
3 8
6 14
Algorithm
Step 2: Read the size of two matrices : row1,col1, row2 and col2
Program
#include<stdio.h>
#include<conio.h>
void main()
int a[3][3],b[3][3],c[3][3],i,j,k,row1,col1,row2,col2;
clrscr();
scanf("%d%d",&row1,&col1);
scanf("%d%d",&row2,&col2);
if(col1!=row2){
getch();
exit(0);}
for(i=0;i<row1;i++)
for(j=0;j<col1;j++)
scanf("%d",&a[i][j]);
for(i=0;i<row2;i++)
for(j=0;j<col2;j++)
scanf("%d",&b[i][j]);
for(i=0;i<row1;i++)
for(j=0;j<col2;j++){
c[i][j]=0;
for(k=0;k<col1;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
for(i=0;i<row1;i++){
for(j=0;j<col2;j++){
printf("%d\t",c[i][j]);
printf("\n");
getch();
Output
1 2
1 0
3 3
1 1 2
2 0 -1
5 1 0
1 1 1
9 3 3
Algorithm
For i0 to rowB do
For j 0 to colB do
Program
#include<stdio.h>
#include<conio.h>
void main()
int a[3][3],b[3][3],i,j,row,col,trow,tcol;
clrscr();
scanf("%d%d",&row,&col);
for(i=0;i<row;i++)
for(j=0;j<col;j++)
scanf("%d",&a[i][j]);
trow=col;
tcol=row;
for(i=0;i<trow;i++)
for(j=0;j<tcol;j++)
b[i][j]=a[j][i];
for(i=0;i<trow;i++){
for(j=0;j<tcol;j++){
printf("%d\t",b[i][j]);
printf("\n");
getch();
Output
2 3
1 2 3
4 5 6
1 2
3 4
5 6
Algorithm
Step 3: If choice is 1
If choice is 2
If choice is 3
If choice is 4
Print str2
If choice is 5
Program
#include<stdio.h>
#include<conio.h>
void main()
char str1[10],str2[10],original[10];
int choice,half;
clrscr();
scanf("%s",&str1);
strcpy(original,str1);
while(1)
strcpy(str1,original);
printf("\nMENU");
printf("\n6. Exit");
scanf("%d",&choice);
switch(choice)
case 1:
printf("Length of %s is %d ",str1,strlen(str1));
break;
case 2:
printf("Reverse of %s is %s",original,strrev(str1));
break;
case 3:
scanf("%s",&str2);
if(strcmp(str1,str2)==0)
else
break;
case 4:
half=strlen(str1)/2;
strncpy(str2,str1,half);
str2[half]='\0';
break;
case 5:
scanf("%s",str2);
strcat(str1,str2);
printf("After Concatenation:%s",str1);
break;
default:
exit(0);
Output
MENU
1. String Length
2. String Reverse
3. String Compare
4. String Copy
5. String Concate
6. Exit
Length of Hello is 5
Aim: To write a program to illustrate a function with arguments and with return values.
Algorithm:
Step 1: Start the program
Step 2: Enter the two numbers
Step 3: Call the function with two arguments passed to it
Step 4: Find GCD of two numbers in the calling function
Step 5:Return answer to the called function from the calling function.
Step 6: Print the gcd value in the main function
Step 7; Stop
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int ans,a,b;
clrscr();
printf("\nEnter value of a and b");
scanf("%d%d",&a,&b);
ans=gcd(a,b);
printf("\nGCD of %d, %d is %d",a,b,ans);
getch();
}
Algorithm
Step 1 : Start the program
Step 2 : Set a 10 and b 20
Step 3 : Call the function swap(a,b)
Step 3a: Start fuction
Step 3b: Assign t x
Step 3c: Assign x y
Step 3d: Assign y t
Step 3e: Print x and y
Step 3f: End function
Step 4: Stop the program
Program
#include<stdio.h>
#include<conio.h>
void swap(int , int); // Declaration of function
void main( )
{
int a = 10, b = 20 ;
printf(\nBefore swapping);
printf ( "\na = %d b = %d", a, b ) ;
swap(a,b);// call by value : a and b are actual parameters
getch();
}
void swap( int x, int y ) // x and y are formal parameters
{
int t ;
t=x;
x=y;
y=t;
printf(\nAfter swapping);
printf ( "\nx = %d y = %d", x, y ) ;
}
Output
Before swapping
a = 10 b=20
After swapping
x = 20 y = 10
Algorithm:
Program
#include<stdio.h>
#include<conio.h>
void swap(int* , int*); // Declaration of function
void main( )
{
int a = 10, b = 20 ;
printf("\nBefore swapping\n");
printf ( "\na = %d b = %d", a, b ) ;
swap(&a,&b);// call by reference
printf("\nAfter swapping\n");
printf ( "\na = %d b = %d", a, b ) ;
getch();
}
void swap( int *x, int *y )
{
int t ;
t = *x ;
*x = *y ;
*y = t ;
Aim: To write a program to find the factorial of the given number using recursion.
Algorithm:
Step 1: Start
Step 2: read num
Step 3: afact(num)
Step 4: print a
Step 5: Stop
Step 1: fact start
Step 2: Is no=1
T : return
F : return n * fact(n-1)
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int num,a;
printf("\nEnter the number");
scanf("%d",&num);
a=fact(num);
printf("\nThe factorial of the number %d is %d",num,a);
getch();
}
int fact(int n)
{
int f;
if(n==1)
return(1);
else
return n * fact(n-1);
}
Output
Enter the number 5
The factorial of the number 5 is 120
Aim: To write a program to assigning values to the structures variables and retrieving values.
Algorithm:
Step 1: Start the program
Step 2: Struct Std
Rno, Marks : integer
Name[10] :character
End
Step 3: Read S.rno, S.name,S.marks
Step 4: Print S.no,S.name,S.marks
Step 5: Stop
Source Code:
#include<stdio.h>
#include<conio.h>
struct std
{
int rno,marks;
char name[10];
}s;
void main()
{
clrscr();
printf(Enter Student Details:\n);
printf(Enter the Register No,Name and Mark\n);
scanf(%d%s%d,&s.rno,s.name,&s.marks);
printf(\n);
printf(Rollno\t\t Name\t\tMarks\n);
printf(%d\t\t%s\t\t%d,s.rno,s.name,s.marks);
getch();
}
Output:
Enter the student Details:
Enter the regNo, Name,Marks:
111 Ram 98
RollNo Name Marks
111 Ram 98
Aim To write a C program to read and display the details of n books using structure
Algorithm
Step 1: Start
Step 2: Declare a structure with variables : name,author,price and Quantity
Step 3: Read n number of books
for i1 to n
Read book[i].name, book[i].author, book[i].price and book[i].Quantity
Step 4: Display the details of n books
Step 5: Stop
#include<stdio.h>
#include<conio.h>
struct book
{
char name[25];
char author[25];
double price;
int Quantity;
}b[10];
void main()
{
int n,i;
printf("\nEnter the number of books\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter details of Book %d[Name,Author,Price,Quantity] ",i+1);
scanf("%s%s%ld%d",b[i].name,b[i].author,&b[i].price,&b[i].Quantity);
}
clrscr();
printf("\n-----------Book Details------------");
printf("\nBook Id\tName\tAuthor\Price\Quantity\n");
for(i=0;i<n;i++)
{
printf("\nBook %d \t%s\t%s\t%ld\t%d",i+1,b[i].name,b[i].author,b[i].price,b[i].Quantity);
}
getch();
}
Output
Enter the number of books
2
Enter details of Book 1 [Name,Author,Price,Quantity]
Computer
Babu
250.00
6
Enter details of Book 2 [Name,Author,Price,Quantity]
C++
Bala
450.00
15
------------Book Details--------------
Book Id Name Author Price Quantity
1 Computer Babu 250.0000 6
2 C++ Bala 450.0000 15
Algorithm
Step 1: Start
Step 2: Declare union with variables: metre & cm
Step 3: Check if choice is m
Read u1.metre and u2.metre value
Print sum : u1.metre + u2.metre
Step 4: Check if choice is c
Read u1.cm and u2.cm value
Print sum : u1.cm + u2.cm
Step 5: Stop the program
Algorithm
#include<stdio.h>
#include<conio.h>
union distance
{
float metre;
int cm;
}u1,u2;
void main()
{
int choice;
printf(\nThe size of union is:%d bytes,sizeof(u1));
printf("\nSelect your distance metric m/c?");
scanf("%c",&choice);
if(choice=='m'){
printf("\nEnter the distance:");
scanf("%f%f",&u1.metre,&u2.metre);
printf("Sum of distances:%f metres",u1.metre+u2.metre);
}
else
{
printf("\nEnter the distance:");
scanf("%d%d",&u1.cm,&u2.cm);
printf("Sum of distances:%d cm",u1.cm+u2.cm);
}
getch();
}
Output
The size of union is 4 bytes
Select your distance metric m/c?
c