Problem Solving Techniques Lab Manual-1
Problem Solving Techniques Lab Manual-1
Lab Manual
Date:
M2: Establishing state-of-the-art facilities and adopt education 4.0 practices to analyse, develop,
test and deploy sustainable ethical IT solutions by involving multiple stakeholders.
PEO1: Be engaged with leading Global Software Services and Product development companies
handling projects in cutting edge technologies
PEO2: Engaged in technical or managerial roles at Government firms, Corporates, Start-ups or
contribute to the society as successful entrepreneurs.
Programme outcomes:
PSO1: Ability to work with emerging technologies in computing requisite to Industry 4.0
PSO2: Demonstrate Computing science Practice learned through industry internship to solve
live problems in various domains.
CO1: Identify appropriate algorithms and apply C language syntax for solving practical
problems
CO2: Convert problem solving strategies into C programs
CO3: Analyse result and interpret data.
CO4: Write C program and represent result
CO5: Execute C program and organize lab report
CO-PO mapping
COs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2
CO1 2 2 1
CO2 2 2 1
CO3 2 2 1
CO4 2 2 1
CO5 2 2 1
CO6 2 2 1
Evaluation Scheme:
Rubrics for Each Evaluation Scheme:
List of Programs:
2. Write a program to compute the addition, subtraction, product, quotient and remainder
of two given numbers.
4. Write a program to compute net amount from the given quantity purchased and
rate per quantity. Discount of 10 .is allowed if quantity purchased exceeds 100.
10. Write a program to determine and print the sum of the following harmonic series for a
given value of n =1 +1/2+1/3+1/4+……+1/n
1
23
456
12. Write a program to read three integer values from the keyboard and display the output
stating that they are the sides of right angled triangle.
13. Write a program to accept an year from the user and check whether the entered year is
a leap year or not.
15. Write a program to print the following pattern (take number of lines as input from the
user).
***
**
*
16. Write a program to find out the length of a given string without using the library
function strlen().
18. Write a program to check if a given string is palindrome or not. A string is said to
be palindrome if the reverse of the string is equal to the string.
25. Write a program to sort an array using Bubble Sort (using function).
26. Write a program to search a key number in an array using Sequential Search Method.
(use function)
27. Write a program to accept student details (name,Enroll No, address, phone no,
Email)and store them in a file and perform the following operations on it.
#include <stdio.h>
float tempchange(int c)
float f;
f=c*1.8+32;
return f;
int main()
int c;float f;
scanf("%d",&c);
f=tempchange(c);
printf("Fahrenheit:%5.2f",f);
return 0;
OUTPUT:-
Fahrenheit:98.60
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
printf("enter 2 numbers:");
int a,b,ch,c;
scanf("%d",&a);
scanf("%d",&b);
printf("1.Addition\n");
printf("2.Substraction\n");
printf("3.Multiplication\n");
printf("4.division\n");
printf("5.Power\n");
printf("6.Exit\n");
scanf("%d",&ch);
switch(ch)
case 1:c=a+b;
printf("%d+%d=%d",a,b,c);break;
case 2:c=a-b;
printf("%d-%d=%d",a,b,c);break;
case 3:c=a*b;
printf("%dX%d=%d",a,b,c);break;
case 4:c=a%b;
printf("%d/%d=%d",a,b,c);break;
case 5:c=pow(a,b);
case 6:break;
default:printf("invalid input");
}
getch();
OUTPUT:-
enter 2 numbers:23
43
2.Substraction
3.Multiplication
4.division
5.Power
6.Exit
23+43=66
#include <stdio.h>
#include <conio.h>
#include <math.h>
int c=a;
a=b;
b=c;
int main()
int a,b;
swap(a,b);
OUTPUT:-
45
PROGRAM 4:WRITE A PROGRAM TO COMPUTE NET AMOUNT FROM THE GIVEN QUENTITY
PURCHASED AND RATE PER QUANTITY. DISCOUNT OF 10 IS ALLOWED IF QUANTITY
PURCHASED AND RATE PER QUATITY PURCHASED EXCEEDS 100*/
#include <stdio.h>
int main()
int pa;
int d;
int na;
scanf("%d",&pa);
if(pa<100)
na=pa;
else
na=pa-10;
printf("net amount:%d",na);
OUTPUT:-
net amount:557
int main()
int n,b=0,t;
printf("enter a number:");
scanf("%d",&n);
while(n>0)
t=n%10;
b=b+t;
n=n/10;
printf("\nsum:-%d",b);
OUTPUT:-
enter a number:345
sum:-12
#include <stdio.h>
int c;
if(n>0)
c=a+b;
printf("%d,",c);
fibo(b,c,n-1);
main()
{
scanf("%d",&n);
printf("0,1,");
fibo(a,b,n-2);
OUTPUT:-
0,1,1,2,3,5,
#include <stdio.h>
#include <conio.h>
int prime(int a)
for(i=1;i<=a;i++)
if(a%i==0)
c++;
if(c==2)
return 1;
else
return 0;
int main()
int n,i;
for(i=1;i<=n;i++)
int t=prime(i);
if(t==1)
printf("%d\n",i);
OUTPUT:-
#include <stdio.h>
#include <conio.h>
void main()
int a;
printf("enter a number:");
scanf("%d",&a);
for(i=1;i<=a;i++)
if(a%i==0)
c++;
if(c==2)
printf("%d is a prime",a);
else
OUTPUT:-
enter a number:97
97 is a prime
#include<stdio.h>
#include<math.h>
int armstrong(int n)
int t,b;
while(n>0)
t=n%10;
b=b+pow(t,3);
n=n/10;
return b;
int main()
int n,n1;
printf("enter a number:");
scanf("%d",&n);
n1=armstrong(n);
if(n==n1)
else
return 0;
OUTPUT:-
enter a number:153
1+1/2+1/3+.........1/N */
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
scanf("%d",&n);
int i;
for(i=i;i<=n;i++)
printf("1/%d+",i);
a=(float)1/(float)i;
sum=sum+a;
printf("=%4.2f",sum);
}
OUTPUT:
1/1+1/2+1/3+1/4+1/5+1/6+1/7+1/8+1/9+1/10+1/11+1/12+=3.10
#include<stdio.h>
int main()
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=i;j++)
printf("%d",c++);
printf("\n");
OUTPUT:-
23
456
78910
#include<stdio.h>
int main()
if((a*a+b*b)==(c*c))
check=1;
if((b*b+c*c)==(a*a))
check=1;
if((a*a+c*c)==(b*b))
check=1;
if(check==1)
else
OUTPUT:-
PROGRAM 13:WRITE A PROGRAM TO ACCEPT AN YEAR FROM THE USER AND CHEACK
WHETHER THE ENTERED YEAR IS A LEAP YEAR OR NOT*/
#include <stdio.h>
int main()
int year;
scanf("%d",&year);
if(year%4 == 0)
if( year%100 == 0)
if ( year%400 == 0)
else
else
return 0;
OUTPUT:-
#include <stdio.h>
#include <conio.h>
#include <math.h.>
int octal(int d)
int i=0,b=0;
while(d!=0)
int r=d%2;
b=b+r*pow(10,i);
d=d/2;i++;
return b;
void main()
{
int n;
scanf("%d",&n);
int oct=octal(n);
printf("BINARY equivalent:%d\n",oct);
OUTPUT:
BINARY equivalent:111000
#include<stdio.h>
int main()
int n,i,j;
scanf("%d",&n);
for(i=n;i>=1;i--)
{ for(j=1;j<=i;j++)
printf("*");
printf("\n");}
OUTPUT:-
*******
******
*****
****
***
**
#include<stdio.h>
#include<string.h>
int i,c=0;
for(i=0;i<size;i++)
if(name[i] == '\0')
break;
return i;
void main()
int s;
char name[size];
gets(name);
s=sizecheck(name);
OUTPUT:-
gaLGOtias UNIVERSITY
#include<stdio.h>
#include<string.h>
int i;
for(i=0;i<l;i++)
printf("%c",name[i]);
char name1[l];
int i,c=0;
for(i=l-1;i>=0;i--)
name1[c++]=name[i];
output(name1,l);
int main()
{ int s,l;
char name[size];
printf("enter a string:");
gets(name);
l=strlen(name);
reverse(name,l);
OUTPUT:-
enter a string:ABHIMANYU
#include<stdio.h>
#include<string.h>
int i;
for(i=0;i<l;i++)
printf("%c",name[i]);
char name1[l];
int i,c=0;
for(i=l-1;i>=0;i--)
name1[c++]=name[i];
output(name1,l);
if(strcmp(name,name1)==0)
printf("\nPalindrome String");
int main()
{
int s,l;
char name[size];
printf("enter a string:");
gets(name);
l=strlen(name);
reverse(name,l);
OUTPUT:-
enter a string:madam
Palindrome String
#include<stdio.h>
#include<string.h>
for(i=0;i<l;i++)
c++;
return c;
void main()
{
int s,l,v;
char name[size];
printf("enter a string:");
gets(name);
l=strlen(name);
v=vowel(name,l);
OUTPUT:-
enter a string:abhimanyu
#include <stdio.h>
#include <conio.h>
int i,j;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",&a[i][j]);
int i,j;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
printf("%d\t",a[i][j]);
printf("\n");
int c1[size][size],i,j;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
c1[i][j]=a[i][j]+b[i][j];
printf("added matrix:\n");
display(c1,r,c);
int main()
int r,c,a[size][size],b[size][size];
scanf("%d",&r);
scanf("%d",&c);
display(a,r,c);
input(b,r,c);
display(b,r,c);
sum(a,b,r,c);
OUTPUT:-
34
44
55
23
44
55
65
23
53
34 44 55
23 44 55
65 23 53
65
98
99
44
44
55
66
22
33
65 98 99
44 44 55
66 22 33
added matrix:
99 142 154
67 88 110
131 45 86
#include <stdio.h>
#include <conio.h>
int i,j;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",&a[i][j]);
}
}
int i,j;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
printf("%d\t",a[i][j]);
printf("\n");
int c1[size][size],i,j;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
c1[i][j]=a[i][j]*b[i][j];
printf("Multiplied matrix:\n");
display(c1,r,c);
int main()
int r,c,a[size][size],b[size][size];
printf("enter the number of rows:");
scanf("%d",&r);
scanf("%d",&c);
input(a,r,c);
display(a,r,c);
input(b,r,c);
display(b,r,c);
multiply(a,b,r,c);
OUTPUT:-
22
33
54
56
76
45
22 33 54
56 76 45
33
44
55
66
111
22
33 44 55
66 111 22
added matrix:
#include <stdio.h>
#include <conio.h>
int fact(int n)
int b=1,i;
for(i=1;i<=n;i++)
b=b*i;
return b;
int main()
printf("enter a number:");
scanf("%d",&n);
fact1=fact(n);
printf("factorial=%d",fact1);
OUTPUT:-
enter a number:5
factorial=120
#include <stdio.h>
#include <conio.h>
#include <math.h>
int c=*a;
*a=*b;
*b=c;
int main()
int a,b;
scanf("%d%d",&a,&b);
swap(&a,&b);
OUTPUT:-
89
#include <stdio.h>
int fact(int n)
{
if(n>=1)
return n*fact(n-1);
else
return 1;
int main()
printf("enter a number:");
scanf("%d",&n);
fact1=fact(n);
printf("factorial=%d",fact1);
OUTPUT:-
enter a number5
factorial=120
#include <stdio.h>
#include <conio.h>
int i;
for(i=0;i<s;i++)
scanf("%d",&a[i]);
}
}
int i;
for(i=0;i<s;i++)
printf("%d\t",a[i]);
for(i=0;i<n;i++)
for(j=0;j<n-i-1;j++)
if(a[j]>a[j+1])
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
int main()
int n,a[size],b[size],c;
input(a,n);
display(a,n);
sort(a,n);
printf("\nSorted array:\n");
display(a,n);
OUTPUT:-
56
44
56
98
25
63
30
Sorted array:
#include <stdio.h>
#include <conio.h>
int i;
for(i=0;i<s;i++)
{
scanf("%d",&a[i]);
int i;
for(i=0;i<s;i++)
printf("%d\t",a[i]);
int i;
for(i=0;i<s;i++)
{ if(a[i]==c)
break;
void main()
{ int n,a[size],b[size],c;
scanf("%d",&n);
input(a,n);
display(a,n);
printf("\nEnter the element to search:-");
scanf("%d",&c);
search(a,n,c);
OUTPUT:-
23
11
56
77
34
#include<stdio.h>
#include<stdlib.h>
#define size 30
struct person
int enrollno;
char name[size];
char address[size];
int phoneno;
char email[size];
};
scanf("%d",&s1->enrollno);
printf("enter name.:");
scanf("%s",&s1->name);
printf("enter address:");
scanf("%s",&s1->address);
scanf("%d",&s1->phoneno);
printf("enter email:");
scanf("%s",&s1->email);
int main()
FILE *fp;
fp=fopen("f1.txt","w");
if(fp==NULL)
exit(1);
p p1;
input(&p1);
fwrite(&p2,sizeof(p),1,fp);
OUTPUT:-
enter name.:ABHI
enter address:ALPHA1