Pop Lab Manual
Pop Lab Manual
LABORATORY
[BPOPS103]
(CHOICE BASED CREDIT SYSTEM)
PROGRAM OUTCOMES
PO's PO Description
Engineering knowledge: Apply the knowledge of mathematics, science, engineering
PO1 fundamentals, and an engineering specialization to the solution of complex engineering
problems.
Problem analysis: Identify, formulate, review research literature, and analyze complex
PO2 engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
Design/development of solutions: Design solutions for complex engineering problems
PO3 and design system components or processes that meet the specified needs with
appropriate consideration for the public health and safety, and the cultural, societal, and
environmental considerations.
Conduct investigations of complex problems: Use research-based knowledge and
PO4 research methods including design of experiments, analysis and interpretation of data,
and synthesis of the information to provide valid conclusions.
The engineer and society: Apply reasoning informed by the contextual knowledge
PO6 to assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
Environment and sustainability: Understand the impact of the professional
PO7 engineering solutions in societal and environmental contexts, and demonstrate the
knowledge of, and need for sustainable development.
Ethics: Apply ethical principles and commit to professional ethics and responsibilities
PO8
and norms of the engineering practice.
Individual and team work: Function effectively as an individual, and as a member or
PO9
leader in diverse teams, and in multidisciplinary settings.
2. Compute the roots of a quadratic equation by accepting the coefficients. Print appropriate messages.
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 Rs 1 per unit. All users are
charged a minimum of Rs. 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.
4. Write a C Program to display the following by reading the number of rows as input, 11 2 11 2 3 2 11
7. Compute sin(x)/cos(x) using Taylor series approximation. Compare your result with the built-in
library function. Print both the results with appropriate inferences.
9. Write functions to implement string operations such as compare, concatenate, and find string length.
Usethe parameter passing techniques.
10. Implement structures to read, write and compute average-marks ofthe students, list the students
scoring above and below the average marks for a class of N students.
11. Develop a program using pointers to compute the sum, mean and standard deviation of all
elements stored in an array of N real numbers.
12. Write a C program to copy a text file to another, read both the input file name and target file
name
Algorithm
Step 1: [Start]
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Remainder
Input a, b
Read op
• Case 1: Sum → a + b
o break
• Case 2: Difference → a - b
o break
• Case 3: Product → a * b
o break
• Case 4: Division → a / b
o break
• Case 5: Remainder → a % b
o break
• Default:
o Print "Enter Your Correct Choice."
Step 7: [Stop]
START
DISPLAY MENU
READ 2 VALUES
a, b
READ CHOICE
T
Case 1 Result = a + b
F
T
Case 2 Result = a - b
F
T
Case 3 Result = a * b
F
T
Case 4 Result = a / b
F
T
Case 5 Result = a % b
F
Default:
Print "Enter correct choice"
Print Result
STOP
#include <stdio.h>
int main(void)
{
int a, b, op;
printf(" 1.Addition\n 2.Subtraction\n 3.Multiplication\n 4.Division\n 5.Remainder\n");
printf("Enter the values of a & b: ");
scanf("%d %d",&a,&b);
printf("Enter your Choice : ");
scanf("%d",&op);
switch(op)
{
case 1 :
printf("Sum of %d and %d is : %d",a,b,a+b);
break;
case 2 :
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;
}
}
Algorithm
Step 1: [Start]
Step 2: [Read input values]
• Input a, b, c
Step 3: [Check for all-zero condition]
• If a = 0 and b = 0 and c = 0,
• Print “roots cannot be determined”
• Exit the program
Step 4: [Calculate the discriminant]
• disc = b * b - 4 * a * c
Step 5: [Check the discriminant and find roots]
1. If disc > 0:
• Compute
root1 = (-b + sqrt(disc))/2a, root2 = (-b - sqrt(disc))/2a
• Print “roots are real and distinct”
• Print the values of root1 and root2
2. Else if disc = 0:
• Compute
root1 = root2 = -b/2a
• Print “roots are equal”
• Print the values of root1 and root2
3. Else (i.e., disc < 0):
• Compute the real part and imaginary part:
realp = -b/2a, imagp = sqrt(|disc|)/(2|a|)
• Print “roots are complex”
• Print the complex roots as
root1 = realp + i * imagp, root2 = realp + i * imagp
Step 6: [Stop]
Read a,b,c
F
disc = b * b – 4 * a * c
T F
If disc > 0
F T
If disc == 0
root1 = (-b + sqrt(disc)/(2*a),
root1 = (-b - sqrt(disc)/(2*a)
root1 = -b/(2*a),
root1 = root2
If disc < 0
STOP
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
float a,b,c,disc;
float root1,root2,realp,imagp;
printf("enter values of a,b,c\n");
scanf("%f%f%f',&a,&b,&c);
if(a==0 && b==0 && c==0)
{
printf("roots cannot be determined\n");
exit(0);
}
else
{
disc=b*b-4*a*c;
if(disc>0)
{
root1=(-b+sqrt(disc))/(2*a);
root2=(-b-sqrt(disc))/(2*a);
printf("roots are real and distinct\n");
printf("root1=%f\n",root1);
printf("root2=%f\n",root2);
}
else if(disc==0)
{
root1=-b/(2*a);
root2=root1;
printf(“roots are equal\n”);
printf(“root1=%f\n”,root1);
printf(“root2=%f\n”,root2);
}
else if(disc<0)
{
realp=-b/(2*a);
imagp=sqrt(abs(disc)/(2*a));
printf("roots are complex\n");
printf("root1=%f+i%f\n",realp,imagp);
printf("root2=%f-i%f\n",realp,imagp);
}
Ouptut:
START
T
Units Units
F
consumed consumed
>=0&&<2 >=200&&
00 <300
STOP
Algorithm
Step 1: [Start]
• Set n = 5.
• For i = 1 to n do:
Step 3.1: [Print leading spaces]
• For k = n down to i :
• For j = 1 to i :
• Print j .
Step 3.3: [Print descending digits]
• For l = j - 2 down to 1:
• Print l .
Step 3.4: [Print newline]
Step 4: [Stop]
START
Initialize n =5
T
Next i?
F
For k = n down to i
Print Space
For j = 1 to i
Print j STOP
For l = i – 1 down to 1
Print l
Print newline
PROGRAM
#include <stdio.h>
main()
{
int i,j,k,l,n=5;
for(i=1;i<=n;i++)
{
for(k=n;k>=i;k--)
printf(“ “);
for(j=1;j<=i;j++)
printf(“%d”,j);
for(l=j-2;l>0;l--)
Output
Step 1: Start
Step 2: [Read the input]
Read the key number of names
Step 3: [Read the array]
for (i=0; i<n; i++) Read a[i]
Step 4: [Read key name]
Input key name
Step 5: [Initialize the result]
low =0 high = n-1
Step 6: [Compute result]
while (low <= high)
mid = (low +high)/2
If (strcmp (names [mid], key) ==0)
Print successful and print position
Else if (strcmp (name [mid], key >0))
high = mid-1
Else
low = mid+1
End of while
Step 7: [Print the result]
Print Unsuccessful
Step 8: [Finished]
Stop
START
Read n
F
for (i=0; i<n; i++)
T
T
Read a[i]
Read key
low = 0
high = n-1
while (low<=high)
F
if (strcmp if (strcmp
(a[mid],key F
(a[mid],key
)==0 )>0)
T
T
#include<stdio.h>
int main()
{
int a[100],i,n,found,mid,key,low,high;
printf("enter the number of elements\n");
scanf("%d",&n);
printf("enter the element in ascending order \n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter the key elements \n");
scanf("%d",&key);
low=0;
high=n-1;
while(low<=high)
{
mid=(low+high)/2;
if(key==a[mid])
{
found=1;
break;
}
else if(key<a[mid])
{
high=mid-1;
}
else
{
low=mid+1;
}
}
if(found==1)
{
printf("key=%d found at position %d \n",key,mid+1);
}
else
{
printf("key=%d not found \n",key);
}
}
Step 5: [Finished]
Stop
for (k=0;k<n;k++)
T
C[i][j] = c[i][j] + a[i][k] * b[k][j]
F
for (i=0; i<m; i++)
T
F
for (i=0; i<q; i++)
C[i][j]=0
STOP
printf("Enter the size of the second matrix (rows and columns): ");
scanf("%d%d", &p, &q);
Algorithm
Step 1: [Start]
• int i
• x = 3.1428 * (x / 180.0)
• t = x (term to be added)
• i=1
1. Increase i by 2 (i = i + 2)
• sum1 = sin(x)
Step 9: [Stop]
START
Read degree n
x = (degree * pi)/180
term = x
sum = term
F F
for (i=3;i<=n;i+=2)
Print sum
Sum1=sin(x)
T sin(y) = sum1
Print Using inbuild function
STOP
#include<stdio.h>
#include<math.h>
int main( )
{
int i;
float x,t,sum,sum1,y;
printf("Enter the angle\n");
scanf("%f",&x);
y=x;
x=3.1428*(x/180.0);
sum=x;
t=x;
i=1;
do
{
i=i+2;
t=(-t*x*x)/((i-1)*i);
sum = sum+t;
}
while(fabs(t)>0.00005);
printf("sin(%f) using taylor series=%f\n",y,sum);
sum1=sin(x);
printf("Using inbuilt function sin(%f)=%f",y,sum1);
}
Algorithm
Step 1: [start]
Step 5: [Finished]
Stop
Read n
T F
for (i=0;i<n;i++)
Read a[i]
F for (i=1;i<=n;i++)
for (j=0;i<n-i;j++)
F
T
temp =a[j]
a[j]=a[j+1]
a[j+1]=temp
F
for (i=0;i<n;i++)
STOP
#include<stdio.h>
int main()
{
int i,j,n,temp;
int a[20];
printf("enter the value of n");
scanf("%d",&n);
printf("Enter the numbers in unsorted order:\n");
for(i=0;i<n;i++)
scanf("%d", &a[i]);
// bubble sort logic
for(i=0;i<n;i++)
{
for(j=0;j<(n-i)-1;j++){
if( a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}}}
printf("The sorted array is\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}}
Algorithm:
Step 1: [Start]
• do
• Case 1: Compare
• Case 2: Concatenate
• Read digit
Step 6: [Stop]
START
Read choice
T F
If
result==
0
T F
Strings are If
equal result>0
T
While(str[i]!=’\0’ F
T
i++
STOP return (1)
Algorithm
Step 1: [Start]
• char usn[10]
• char name[10]
• float m1, m2, m3
• float avg, total
• If s[i].avg >= 35
• Else
Step 7: [Stop]
START
Read n
For (i=0;i<n;i++)
temp!=sqrt
Average = Average+s[i].marks
F
Average = Average/2
T
For (i=0;i<n;i++)
T
temp!=sqrt
Print name,usn,marks
STOP
If
st[i]marks
<average
Output
Enter the number of student=2
Enter the detail of 1 students
Enter USN=101
Enter Name=Ram
Enter the three subject score 10 21 15
Enter the detail of 2 students
Enter USN=102
Enter Name=Kumar
Enter the three subject score 11 9 10
Ram has scored above the average marks
Kumar has scored below the average marks
• int n, i
• float x[20], sum, mean, variance, deviation
• Initialize sum = 0
• For i from 0 to n-1, do sum = sum + x[i]
• mean = sum / n
• Re-initialize sum = 0
• For i from 0 to n-1:
o sum = sum + (x[i] - mean) * (x[i] - mean)
• variance = sum / n
• deviation = sqrt(variance)
sum = 0, sumstd = 0
Read n
F
for (i=0; i<n; i++)
T
Read a[i]
ptr = a
F
for (i=0; i<=n; i++)
T
sum = sum + *ptr ptr++
mean = sum/n
ptr = a
var = sumstd/n
std = sqrt(var)
STOP
PROGRAM
Output:
Enter the value of n 5
Algorithm
Step 1: [Start]
Step 9: [Stop]
T F
fptr1==NULL
T F
fptr2==NULL
While (c != EOF)
fputc(c, fptr2)
c = fgetc(fptr1)
fclose(fptr1)
Stop fclose(fptr2)
#include <stdio.h>
#include <stdlib.h> // For exit()
int main()
{
FILE *fptr1, *fptr2;
char filename[100], c;
Output:
Enter the filename to open for reading a.txt
Enter the filename to open for writing b.txt
Contents copied to b.txt