4. C
Co
om
mp
pu
ut
te
er
rP
Pr
ro
og
gr
ra
am
mm
mi
in
ng
gL
La
ab
bo
or
ra
at
to
or
ry
y2
21
1C
CP
PL
L2
27
7
S
Sr
ri
iS
Sa
ai
ir
ra
am
mC
Co
ol
ll
le
eg
ge
eo
of
fE
En
ng
gi
in
ne
ee
er
ri
in
ng
g,
,A
An
ne
ek
ka
al
l,
,B
Be
en
ng
ga
al
lu
ur
ru
u.
.
4
4|
|P
P a
a g
g e
e
printf("Difference of %d and %d is : %d",a,b,a-b);
break;
case 3 :
printf("Multiplication of %d and %d is : %d",a,b,a*b);
break;
case 4 :
printf("Division of Two Numbers is %d : ",a/b);
break;
case 5:
printf("Remainder of %d and %d is : %d",a,b,a%b);
break;
default :
printf(" Enter Your Correct Choice.");
break;
}
}
Output:
Enter the values of a & b:
5
5
Enter your choice
1
Sum of a and b is : 10
2. Develop a program to compute the roots of a quadratic equation by accepting
the coefficients. Print the appropriate messages
Algorithm
Step-1: [Read values of A, B, C]-Read A, B, C.
Step-2: [Check for Co-efficient]-If A=B=C=0 then roots are non-determinant
Step-3:[Compute the value Disc]- Disc=B*B-4*A*C;
Step-4:[Different roots are obtained depending on the value of disc]-
If Disc is lesser than 0 than goto step 5
If Disc is equals to 0 than goto step 6
If Disc is greater than 0 than goto step 7.
7. C
Co
om
mp
pu
ut
te
er
rP
Pr
ro
og
gr
ra
am
mm
mi
in
ng
gL
La
ab
bo
or
ra
at
to
or
ry
y2
21
1C
CP
PL
L2
27
7
S
Sr
ri
iS
Sa
ai
ir
ra
am
mC
Co
ol
ll
le
eg
ge
eo
of
fE
En
ng
gi
in
ne
ee
er
ri
in
ng
g,
,A
An
ne
ek
ka
al
l,
,B
Be
en
ng
ga
al
lu
ur
ru
u.
.
7
7|
|P
P a
a g
g e
e
printf("root1=%f+i%fn",realp,imagp);
printf("root2=%f-i%fn",realp,imagp);
}
}
}
Output:
3. An electricity board charges the following rates for the use of electricity: for
the first 200 units 80 paise per unit: for the next 100 units 90 paise per unit:
beyond 300 units rupees 1 per unit. All users are charged a minimum of
rupees 100 as meter charge. If the total amount is more than Rs 400, then
an additional Surcharge of 15% of total amount is charged. Write a program
to read the name of the user, number of units consumed and print out the
charges.
Algorithm:
Input: Customer name and unit consumed
Output: Customer name, units consumed and total amount to be paid
Step 1: Start
Step 2: Read the name of customer and the unit consumed by the customer.
Step 3: Check if the unit consumed is greater than 1 and less than 200,if true
goto step 4 else goto step 5.
Step 4: Compute: amt=100+(0.8*units).
Step 5: if unit is greater than 200 and less than 300,if true goto step 6 else
goto step7
Step 6: Compute amt=100+(200*0.8)+((units-200)*0.9)
Step 7:Compute amt=100+(200*0.8)+(100*0.9)+((units-300)*1), then goto
step 8
10. C
Co
om
mp
pu
ut
te
er
rP
Pr
ro
og
gr
ra
am
mm
mi
in
ng
gL
La
ab
bo
or
ra
at
to
or
ry
y2
21
1C
CP
PL
L2
27
7
S
Sr
ri
iS
Sa
ai
ir
ra
am
mC
Co
ol
ll
le
eg
ge
eo
of
fE
En
ng
gi
in
ne
ee
er
ri
in
ng
g,
,A
An
ne
ek
ka
al
l,
,B
Be
en
ng
ga
al
lu
ur
ru
u.
.
1
10
0|
|P
P a
a g
g e
e
Program:
#include<stdio.h>
#include<string.h>
void main()
{
int cust_no, unit_con;
float charge,surcharge=0, amt, total_amt;
char nm[25];
printf("Enter the customer IDNO :t");
scanf("%d",&cust_no);
printf("Enter the customer Name :t");
scanf("%s",nm);
printf("Enter the unit consumed by customer :t");
scanf("%d",&unit_con);
if (unit_con <200 )
charge = 0.80;
else if (unit_con>=200 && unit_con<300)
charge = 0.90;
else
charge = 1.00;
amt = unit_con*charge;
if (amt>400)
surcharge = amt*15/100.0;
total_amt = amt+surcharge;
printf("tttnElectricity Billnn");
printf("Customer IDNO :t%d",cust_no);
printf("nCustomer Name :t%s",nm);
printf("nunit Consumed :t%d",unit_con);
printf("nAmount Charges @Rs. %4.2f per unit :t%0.2f",charge,amt);
printf("nSurchage Amount :t%.2f",surcharge);
printf("nMinimum meter charge Rs :t%d",100);
printf("nNet Amount Paid By the Customer :t%.2f",total_amt+100);
}
25. C
Co
om
mp
pu
ut
te
er
rP
Pr
ro
og
gr
ra
am
mm
mi
in
ng
gL
La
ab
bo
or
ra
at
to
or
ry
y2
21
1C
CP
PL
L2
27
7
S
Sr
ri
iS
Sa
ai
ir
ra
am
mC
Co
ol
ll
le
eg
ge
eo
of
fE
En
ng
gi
in
ne
ee
er
ri
in
ng
g,
,A
An
ne
ek
ka
al
l,
,B
Be
en
ng
ga
al
lu
ur
ru
u.
.
2
25
5|
|P
P a
a g
g e
e
Output:
8. Write functions to implement string operations such as compare, concatenate,
string length. Convince the parameter passing techniques.
Step-1: Start
Step-2: Press 1 – Compare, 2 – Concatenate, 3-length of string, if press 1 than
goto step 3, if press step 2 then goto step 4, if press 3 then goto step 5
Step-3: Read the string1 and string2 and cojmparsion function by using strcmp
built in unction is used. If res = 0 then print both strings are equal, otherwise
print strints are not equal and than goto the step 4
Step-4: Read String1 and sring2 and find concatenation of two strings using
string handling function strcat() and display sring and return back to main
fuctions.
Step-5: Read string1 and call function to find the length of string by calling
function length ( *string)
Step-6: if digit=1 then gtoto step 2 else goto step 7
Step-7: Stop
29. C
Co
om
mp
pu
ut
te
er
rP
Pr
ro
og
gr
ra
am
mm
mi
in
ng
gL
La
ab
bo
or
ra
at
to
or
ry
y2
21
1C
CP
PL
L2
27
7
S
Sr
ri
iS
Sa
ai
ir
ra
am
mC
Co
ol
ll
le
eg
ge
eo
of
fE
En
ng
gi
in
ne
ee
er
ri
in
ng
g,
,A
An
ne
ek
ka
al
l,
,B
Be
en
ng
ga
al
lu
ur
ru
u.
.
2
29
9|
|P
P a
a g
g e
e
}
void length(char *str1[ ])
{
int len;
len=strlen(str1);
printf("the length of string=%d",len);
}
Output:
9.Implement structures to read, write and compute average- marks and the students scoring
above and below the average marks for a class of N students.
Algorithm:
Step-1: Start
Step-2: Read number of students
Step-3: For every student, read the student id, name , marks for all the subjects
Step-4: Calculate the avarage marks and store it in the avg field
Step-5: Print the results
Step-6: Initialise loop
Step-7: Read teh average of every student
Step-8: Check for if avg>35.00
Step-9: If yes than print the result else goto next interation
Step-10: Initialise the loop
Step-11: Read average of every student
Step-12: Check if avg<35.00
Step-13: If yes than print result else goto next iteration
Step-14: Stop
Flowchart: