All Practicals
All Practicals
Date:
Practical No: 1
C Program:
#include<stdio.h>
int main()
{
int a,b,c;
float d;
printf("Enter Number 1:");
scanf("%d",&a);
printf("Enter Number 2:");
scanf("%d",&b);
c=a+b;
printf("Addition:%d",c);
c=a-b;
printf("\nSubtaction:%d",c);
c=a*b;
printf("\nMultiplication:%d",c);
d=(float)a/b;
printf("\ndivison:%f",d);
return 0;
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 1
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 2
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No: 2
C Program:
#include<stdio.h>
int main()
{
float area,h,b;
printf("enter height:");
scanf("%f",&h);
printf("enter base:");
scanf("%f",&b);
area=0.5*h*b;
printf("Area of Triagnle:%f",area);
return 0;
}
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 3
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No: 3
C Program:
#include<stdio.h>
int main()
{
float i,p,r,n;
printf("ammount:");
scanf("%f",&p);
printf("enter rate:");
scanf("%f",&r);
printf("enter time:");
scanf("%f",&n);
i=p*r*n/100;
printf("Interest:%f",i);
return 0;
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 4
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 5
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No: 4
C Program:
#include<stdio.h>
int main()
{
float a,b,c;
printf("enter a:");
scanf("%f",&a);
printf("enter b:");
scanf("%f",&b);
printf("\nbefore swapping a:%f",a);
printf("\nbefore swapping b:%f",b);
c=a;
a=b;
b=c;
printf("\nafter swapping a:%f",a);
printf("\nafter swapping b:%f",b);
return 0;
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 6
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 7
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No: 5
C Program:
#include<stdio.h>
int main()
{
float distance,m,f,inch,cm;
printf("The distance in Kilometer:");
scanf("%f",&distance);
m=distance*1000;
f=distance*3280.8399;
inch=distance/0.0000254;
cm=distance*100000;
printf("\nThe distance in meter is %f",m);
printf("\nThe distance in feet is %f",f);
printf("\nThe distance in inch is %f",inch);
printf("\nThe distance in centimeter is %f",cm);
return 0;
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 8
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 9
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No: 6
C Program:
#include<stdio.h>
int main()
{
float F,C;
printf("Enter the Temperature in Centigrade=");
scanf("%f",&C);
F=1.8*C+32;
printf("The temperature in Fahrenheit is %f",F);
return 0;
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 10
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 11
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No: 7
C Program:
#include<stdio.h>
int main()
{
float d,u,a,t;
printf("Enter the velocity=");
scanf("%f",&u);
printf("Enter the accelration=");
scanf("%f",&a);
printf("Enter the time=");
scanf("%f",&t);
d=u*t+(a*t*t)/2;
printf("The distance is: %f",d);
return 0;
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 12
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Output:
Practical No: 8
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 13
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
#include<stdio.h>
int main()
{
float num;
printf("Enter the number:");
scanf("%f",&num);
if(num>0)
{
printf("The number is positive");
}
else if(num<0)
{
printf("The number is negative");
}
else
{
printf("The number is zero");
}
return 0;
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 14
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Output:
Practical No: 9
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 15
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
C Program:
#include<stdio.h>
int main()
{
float m;
printf("Enter the marks of subject:");
scanf("%f",&m);
if(m>36)
{
printf("You have passed");
}
else
{
printf("You are failed");
}
return 0;
}
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 16
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No: 10
AIM: Write a program to read three numbers from the keyboard and
find out the maximum out of these three. (nested if-else)
C Program:
#include<stdio.h>
int main()
{
float a,b,c;
printf("Enter the value of a,b,c:");
scanf("%f %f %f",&a,&b,&c);
if(a>b)
{
if(a>c)
{
printf("a is maximum and the value is %f",a);
}
else
{
printf("c is maximum and the value is %f",c);
}
}
else
{
if(b>c)
{
printf("b is maximum and the value is %f",b);
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 17
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
}
else
{
printf("c is maximum and the value is %f",c);
}
}
return 0;
}
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 18
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No: 11
C Program:
#include<stdio.h>
int main()
{
char ch;
printf("Enter the character: ");
scanf("%c",&ch);
if(ch>=65 && ch<=90)
{
printf("The characer is capial");
}
else if(ch>=97 && ch<=122)
{
printf("The character is small");
}
else if(ch>='0' && ch<='9')
{
printf("THe character is digit");
}
else
{
printf("The character is special character");
}
return 0;
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 19
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 20
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No: 12
AIM: Write a program to read marks from the keyboard and your
program should display an equivalent grade according to the
following table (if else ladder).
Marks Grade
100-80 Distinction
79-60 First Class
59-40 Second Class
< 40 Fail
C Program:
#include<stdio.h>
int main()
{
float marks;
printf("Enter the marks: ");
scanf("%f",&marks);
if(marks>=80 && marks<=100)
{
printf("Distinction");
}
else if(marks>=60 && marks<=79)
{
printf("First Class");
}
else if(marks>=40 && marks<=59)
{
printf("Second Class");
}
else if(marks<40)
{
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 21
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
printf("Fail");
}
else
{
printf("Invalid Marks");
}
return 0;
}
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 22
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No: 13
C Program:
#include<stdio.h>
int main()
{
float Da,Gross,basic,Hra,Ma,Nt,Pf;
printf("Enter basic ammount:");
scanf("%f",&basic);
Da=0.1*basic;
Hra=0.075*basic;
Ma=300;
Pf=0.125*basic;
Gross=basic+Da+Hra+Ma;
Nt=Gross-Pf;
printf("\nThe Gross is %f",Gross);
printf("\nThe Nt is %f",Nt);
return 0;
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 23
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 24
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No: 14
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 25
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
printf("Thursday");
break;
case 6:
printf("Friday");
break;
case 7:
printf("Saturday");
break;
default:
printf("Invalid No.");
break;
}
}
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 26
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No: 15
C Program:
#include<stdio.h>
#include<math.h>
int main()
{
int choice,a,b,sum,sub,mul,div,modu,sq,sqroot,powr,l;
printf("This is the Scientific Calculator");
printf("\nEnter your choice for (add, sub,mul, div, module, square, square root, power,
log): ");
scanf("%d",&choice);
printf("Enter value of a:");
scanf("%d",&a);
printf("Enter value of b:");
scanf("%d",&b);
switch (choice)
{
case 1:
sum=a+b;
printf("The sum is %d",sum);
break;
case 2:
sub=a-b;
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 27
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 28
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
l=log(a);
printf("The log is %d",l);
break;
default:
printf("Invalid choice");
break;
}
return 0;
}
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 29
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No: 17
C Program:
#include<stdio.h>
int main()
{
char choice;
printf("Vowel Check Program ");
printf("Enter character:");
scanf("%c",&choice);
switch (choice)
{
case 'a':
printf("Vowel");
break;
case 'e':
printf("Vowel");
break;
case 'i':
printf("Vowel");
break;
case 'o':
printf("Vowel");
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 30
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
break;
case 'u':
printf("Vowel");
break;
case 'A':
printf("Vowel");
break;
case 'E':
printf("Vowel");
break;
case 'I':
printf("Vowel");
break;
case 'O':
printf("Vowel");
break;
case 'U':
printf("Vowel");
break;
default:
printf("Character is not Vowel");
break;
}
return 0;
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 31
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 32
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:16
AIM:Write a program to print sum of first n integer numbers.
include<stdio.h>
void main()
{
int n,sum;
printf("Enter the number upto n sumation:");
scanf("%d",&n);
sum=(n*(n+1))/2;
printf("the sum is %d",sum);
}
P 16_2
#include<stdio.h>
void main()
{
int n,sum,i=1;
printf("Enter the number upto n sumation:");
scanf("%d",&n);
while(i<=n)
{
sum=sum+i;
}
// sum=(n*(n+1))/2;
printf("the sum is %d",sum);
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 33
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Output:
P16_2
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 34
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:18
Aim:Write a program to find out the Maximum and Minimum number from
given 10 numbers using
for, while loop.
#include<stdio.h>
int main()
{
int n=1,a,max_num,min_num;
while (n<=10)
{
printf("enter the num:");
scanf("%d",&a);
if(n==1)
{
max_num=min_num=a;
}
else
{
if(a>max_num)
{
max_num=a;
}
else if (a<min_num)
{
min_num=a;
}
}
n++;
}
printf("max:%d",max_num);
printf("\nmin:%d",min_num);
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 35
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 36
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:19
Aim:Write a program to input an integer number and check the last digit of
number is even or odd
using any looping structure.
#include <stdio.h>
int main() {
int num, last_digit;
if (last_digit % 2 == 0)
{
printf("The last digit of %d is even.\n", num);
} else {
printf("The last digit of %d is odd.\n", num);
}
return 0;
}
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 37
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:20
Aim:Write a program to print sum of individual digits of a given integer
using while statement. (Use
% operator)
#include<stdio.h>
int main()
{
int a,b,sum=0;
printf("Enter the number :");
scanf("%d",&a);
while(a>0)
{
b=a%10;
a=a/10;
sum=sum+b;
}
printf("sum of the given number's digit is: %d",sum);
}
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 38
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:51
Aim:To display the sum of two numbers.
a= input("a=")
b=input("b=")
a=int(a)
b=int(b)
#additin
print("sum=",a+b)
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 39
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:52
Aim:Calculate area of circle.
#area of circle
r=input("r=")
r=int(r)
print("area of circle",3.14*r*r)
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 40
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:53
Aim:Accept a number from keyboard and test whether the given number is
even or odd.
num = int(input("Enter a number: "))
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 41
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:21
Aim:Write a program to find out sum of first and last digit of a given
number.
#include<stdio.h>
int main()
{
int a,b;
printf("Enter the number :");
scanf("%d",&a);
b= a%10;
while(a>=10)
{
a=(a/10);
}
printf("\n first digit of the given number's digit is: %d",a);
printf("\n last digit of the given number's digit is: %d",b);
printf("\n the sum of first and last digit of the given
number's digit is: %d",(a+b));
}
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 42
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:22
Aim:Write a program to check whether the given number is prime or not.
#include<stdio.h>
int main()
{
int a;
int b=0;
int i;
printf("Enter the number :");
scanf("%d",&a);
if(a==1)
{
printf("the given number is not prime number.");
}
else if (a>1)
{
for ( i=2;i<a;i++)
{
if(a%i==0)
{b=1;
break;
}
}
if(b==1)
{
printf("%dthe number is not a prime");
}
else {
printf("%d is a prime number");
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 43
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
}
return 0;
}
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 44
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:23
Aim:Write a program to print first n prime numbers.
#include<stdio.h>
int main()
{
int n,count=0,num=2,i,is_prime;
printf("enter the number:");
scanf("%d", &n);
printf("the first %d prime number are:\n");
while(count<n)
{
is_prime=1;
for(i=2;i<num;i++){
if (num%i==0){
is_prime=0;
break;
}
}
if (is_prime){
printf("%d",num);
count++;
}
num++;
}
return 0;
}
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 45
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:24
Aim:Write a program to find factorial of a given number.
#include<stdio.h>
int main()
{
int a,i ;
long long int fac=1;
printf("enter the number to get its factorial:");
scanf("%d",&a);
for (i=1; i<=a; i++)
{
fac=fac*i;
}
if (a==0)
{
printf("the factorial of the given number is :1");
}
else
{
printf("the factorial of the given number is :%lld",fac);
}
}
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 46
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:25
#include<stdio.h>
int main()
{
int a,b=0,i,c=1;
printf("enter the number of terms want to see in fibonacci series");
scanf("%d",&a);
for(i=1 ;i<=a; i++)
{
if(i==1)
{
printf("%d \n",b);
b=b+c;
}
else
{
c=b-c;
printf("%d\n",b);
b=b+c;
}
}
}
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 47
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:26
Aim:Write a program that accept a string and count the number of space
character, tab character,
new line character, and any other characters.
(Hint: use getchar() to accept characters. Use combination of switch..case
and while loop).
#include <stdio.h>
int main() {
char ch;
int spaceCount = 0, tabCount = 0, newLineCount = 0, otherCount = 0;
switch (ch) {
case ' ':
spaceCount++;
break;
case '\t':
tabCount++;
break;
case '\n':
newLineCount++;
break;
default:
otherCount++;
}
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 48
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
printf("\nCharacter counts:\n");
printf("Space characters: %d\n", spaceCount);
printf("Tab characters: %d\n", tabCount);
printf("Newline characters: %d\n", newLineCount);
printf("Other characters: %d\n", otherCount);
return 0;
}
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 49
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:27
Aim:Write a program to find the sum and average of different numbers. The
user sould be able to
enter as many numbers as he wants.
#include<stdio.h>
int main()
{
int n,i;
float sum=0,avg=0;
printf("enter the number you want to add in the array:");
scanf("%d",&n);
float a[n];
for( i=0;i<n;i++)
{
printf("enter the number in the array at poition %d:",i+1);
scanf("%f",&a[i]);
sum=sum+a[i];
}
avg=sum/n;
printf("the sum is %f\n",sum);
printf("the avg is %f\n",avg);
}
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 50
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical NO:28
Aim:Write a program to accept start number and end number from the user
and print all the numbers
in the range.
#include<stdio.h>
int main()
{
int i,a,b;
printf("enter the start number :");
scanf("%d",&a);
printf("enter the end number :");
scanf("%d",&b);
for ( i=a; i<=b; i++)
{
printf("%d:",i);
}
}
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 51
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:29
Aim:Write a program to calculate average and total marks of 5 students for
3 subjects (use nested for
loops).
#include<stdio.h>
int main()
{
int j,i,a,sum=0,stu,sub;
for( i=1;i<=5;i++)
{
printf("enter the marks of student-%d:",i);
printf("\n");
sum=0;
for( j=1;j<=3;j++)
{
printf("enter the marks of subject-%d:",j);
scanf("%d",&a);
sum=sum+a;
}
}
printf(" sum ;%d",sum);
printf("\navg :%d",sum/3);
printf("\n");
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 52
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 53
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:30
Aim: Read five persons height and weight and count the number of person
having height greater than
170 and weight less than 50,
#include<stdio.h>
int main()
{
int person,height,weight,count=0;
for(person=0;person<5;person++ )
{
printf("\n Enter detail of person-%d",person+1);
printf("\n enter the height:");
scanf("%d",&height);
printf("\n enter the weight:");
scanf("%d",&weight);
if (height>170)
{
if (weight<50)
{
count++;
}
}
}
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 54
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 55
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Extra prac 1
a=input("a=") #a=int(input("a="))
b=input("b=") #b=int(input("b="))
a=int(a)
b=int(b)
print("Sum=",a+b) #addition
print("Difference=",a-b) #Subtraction
print("Multiplication=",a*b) #Multiplication
print("Division=",a/b) #Division
Output:
Extra prac 2
#area of triangle
h=input("h =")
b=input("b =")
h=int(h)
b=int(b)
print("area of triangle= ", h*b*0.5)
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 56
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Extar prac 3
p=input("p =")
r=input("r =")
n=input("n =")
p=int(p)
r=int(r)
n=int(n)
print("interest = ", p*r*n/100)
Output:
Extra prac 4
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 57
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
b=input("b =")
a=input("a =")
b=int(b)
a=int(a)
a+=b
b=a-b
a-=b
print("after swap a= ", a)
print("interest = b", b)
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 58
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Extra Prac 5
a=input("a =")
a=float(a)
print("in meter=",1000*a)
print("in feet=",3280.8399*a)
print("in inches=",39370.1*a)
print("in cm =",100000*a)
Output:
Extra prac 6
c=input("c=")
c=int(c)
print("f=",1.8*c+32)
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 59
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Extra prac 7
t=input("t =")
u=input("u =")
a=input("a =")
t=float(t)
u=float(u)
a=float(a)
print("distance= ",u*t+(a*t*t)/2)
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 60
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Extra prac 8
n=input("Enter No:")
n=int(n)
if (n>0):
print("Number is positive")
elif(n<0):
print("Number is Negative")
else:
print("Number is Zero")
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 61
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Extra prac 9
marks=input("Enter Marks:")
marks=int(marks)
if(marks>=36):
print("You have passed")
else:
print("You are failed")
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 62
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Extra Prac 10
Python Program:
a,b,c=input("Enter a:"),input("Enter b:"),input("Enter c:")
a,b,c=int(a),int(b),int(c)
if(a>b):
if(a>c):
print("a is maximum",a)
else:
print("c is maximum",c)
else:
if(b>c):
print("b is maximum",b)
else:
print("c is maximum",c)
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 63
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Extra prac 11
Python Program:
ch=input("Enter character:")
if(ch>='A' and ch<='Z'): #if ch.isupper():
print("Character is Capial")
elif(ch>='a' and ch<='z'): #elif ch.islower():
print("Character is small")
elif(ch>='0' and ch<='9'): #elif ch.isdigit():
print("Character is Number")
else:
print("Character is Special Character")
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 64
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Extra prac 12
marks=input("Enter marks:")
marks=int(marks)
if(marks>=80 and marks<=100):
print("Distinction")
elif(marks>=60 and marks<=79):
print("First Class")
elif(marks>=40 and marks<=59):
print("Second Class")
elif(marks<40):
print("Fail")
else:
print("Invalid Marks")
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 65
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Extra Prac 13
Python Program:
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 66
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Extra Prac 14
n=int(input('Enter a number '))
if n==1:
print('Sunday')
elif n==2:
print('Monday')
elif n==3:
print('Tuesday')
elif n==4:
print('Wednesday')
elif n==5:
print('Thursday')
elif n==6:
print('Friday')
elif n==7:
print('Saturday')
else:
print('Invalid number')
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 67
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 68
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical NO:31
Aim:Write a program to evaluate the series 1^2+2^2+3^2+......+n^2.
#include<stdio.h>
int main()
{
float i,sum=0,n;
printf("enter the number:\n");
scanf("%f",&n);
for(i=1;i<=n;i++)
{
sum=sum+(i*i);
}
printf("the series evalutation is=%f\n",sum);
return 0;
}
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 69
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical NO:32
Aim:Write a program to find 1+1/2+1/3+1/4+....+1/n.
#include<stdio.h>
int main()
{
float i,sum=0,n;
printf("enter the number:\n");
scanf("%f",&n);
for(i=1;i<=n;i++)
{
sum=sum+(1/i);
}
printf("the series evalutation is=%f\n",sum);
return 0;
}
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 70
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical NO:33
Aim:Write a program to find 1+1/2!+1/3!+1/4!+.....+1/n!.
#include<stdio.h>
int main()
{
float i,sum=0,n,fact=1;
printf("enter the number:");
scanf("%f",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
sum=sum+1/fact;
}
printf("the fact is=%f",sum);
}
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 71
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical NO:34
Aim:Write a program to evaluate the series
sum=1-x+x^2/2!-x^3/3!+x^4/4!......-x^9/9!.
#include<stdio.h>
#include<math.h>
int main()
{
int i,sum=1,x,fact=1;
printf("enter the number:\n");
scanf("%d",&x);
for(i=1;i<=x;i++)
{
fact=fact*i;
sum=sum+pow(-x,i)/fact;
}
printf("the series evalutation is = %d\n",sum);
}
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 72
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical NO:35
Aim:Write a program to print following patterns:
1) 2) 3)
*
**
***
****
*****
*
**
***
*****
*****
****
***
**
*
1
#include<stdio.h>
int main()
{
int n;
printf("ET24BTCL050");
printf("\nEnter no:");
scanf("%d",&n);
for(int i=1; i<=n; i++) //row
{
for(int j=1; j<=i; j++) //column
{
printf("* ");
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 73
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
}
printf("\n");
}
return 0;
}
2
#include<stdio.h>
int main()
{
int n;
printf("ET24BTCL050");
printf("\nEnter no:");
scanf("%d",&n);
for(int i=1; i<=n; i++) //row
{
for(int j=1; j<=n-i; j++) //space
{
printf(" ");
}
for(int k=1; k<=i; k++) //column
{
printf("* ");
}
printf("\n");
}
return 0;
3
#include<stdio.h>
int main()
{
int n;
printf("ET24BTCL050");
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 74
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
printf("\nEnter no:");
scanf("%d",&n);
for(int i=n; i>=1; i--) //row
{
for(int j=i; j>=1; j--) //column
{
printf("* ");
}
printf("\n");
}
return 0;
}
OUTPUT:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 75
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
PRACTICAL NO:36
1
#include<stdio.h>
int main()
{
int n;
printf("ET24BTCL050");
printf("\nEnter no:");
scanf("%d",&n);
for(int i=1; i<=n; i++) //row
{
for(int j=1; j<=i; j++) //column
{
printf("%d",j);
}
printf("\n");
}
return 0;
}
2
#include<stdio.h>
int main()
{
int n;
printf("ET24BTCL050");
printf("\nEnter no:");
scanf("%d",&n);
for(int i=n; i>=1; i--) //row
{
for(int j=1; j<=i; j++) //column
{
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 76
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
printf("%d",j);
}
printf("\n");
}
return 0;
}
3
#include <stdio.h>
int main()
{
int n;
printf("ET24BTCL050");
printf("\nEnter no:");
scanf("%d",&n);
for(int i=n; i>=1; i--) //row
{
for(int j=i; j>=1; j--) //column
{
printf("%d",i);
}
printf("\n");
}
return 0;
}
4
#include <stdio.h>
int main()
{
int n;
printf("ET24BTCL050");
printf("\nEnter no:");
scanf("%d",&n);
for(int i=1; i<=n; i++) //row
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 77
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
{
for(int j=1; j<=i; j++) //column
{
printf("%d",i);
}
printf("\n");
}
return 0;
}
OUTPUT:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 78
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
PRACTICAL NO:37
1
#include<stdio.h>
int main()
{
int n;
printf("ET24BTCL050");
printf("\nEnter no:");
scanf("%d",&n);
for(int i=1; i<=n; i++) //row
{
for(int j=1; j<=n-i; j++) //space
{
printf(" ");
}
for(int k=1; k<=2*i-1; k++) //column
{
printf("%d",k);
}
printf("\n");
}
return 0;
}
2
#include<stdio.h>
int main()
{
int n,coef;
printf("ET24BTCL050");
printf("\nEnter no:");
scanf("%d",&n);
for(int i=1; i<=n; i++) // row
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 79
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
{
for(int j=1; j<=n-i; j++)
{
printf(" ");
}
coef=1;
for(int k=1; k<=i; k++)
{
printf(" %d ",coef);
coef=coef*(i-k)/k;
}
printf("\n");
}
return 0;
3
#include<stdio.h>
int main()
{
int n;
printf("ET24BTCL050");
printf("\nEnter no:");
scanf("%d",&n);
for(int i=1; i<=n; i++) // row
{
for(int j=1; j<=n-i; j++) // space
{
printf(" ");
}
for(int k=1; k<=2*i-1; k++) // column
{
if (k==1 || k==2*i-1)
{
printf("* ");
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 80
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
}
else
{
printf("# ");
}
}
printf("\n");
}
return 0;
}
OUTPUT:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 81
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 82
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
PRACTICAL NO:38
1
#include<stdio.h>
int main()
{
int n;
char ch='A';
printf("ET24BTCL050");
printf("\nEnter no:");
scanf("%d",&n);
for(int i=1; i<=n; i++) //row
{
for(int j=0; j<i; j++) //column
{
printf("%c",ch+j);
}
printf("\n");
}
return 0;
}
2
#include<stdio.h>
int main()
{
int n;
char ch='A';
printf("ET24BTCL050");
printf("\nEnter no:");
scanf("%d",&n);
for(int i=n; i>=1; i--) //row
{
for(int j=i; j>=1; j--) //column
{
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 83
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
printf("%c",ch);
}
ch++;
printf("\n");
}
return 0;
}
OUTPUT:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 84
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
PRACTICAL NO:39
#include<stdio.h>
int main()
{
int arr[10];
int evencount=0,oddcount=0;
printf("ET24BTCL034");
printf("\nEnter 10 no:");
for (int i=0; i<10; i++)
{
scanf("%d",&arr[i]);
}
for (int i=0; i<10; i++)
{
if(arr[i]%2==0)
{
evencount++;
printf("\n%d is even number",arr[i]);
}
else if(arr[i]%2!=0)
{
oddcount++;
printf("\n%d is odd number",arr[i]);
}
}
printf("\nEven no. are:%d",evencount);
printf("\nOdd no. are:%d",oddcount);
return 0;
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 85
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
OUTPUT:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 86
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
PRACTICAL NO:57
B
AIM:
1
12
123
for i in range(1,4):
for j in range(1,i+1):
print(j,end='')
print('')
Output:
Aim:
*
**
***
n=3
for i in range(1,n+1):
for j in range(n-i):
print('',end='')
for k in range(i):
print('*',end='')
print()
Output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 87
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
D
n=3
for i in range(1, n+4):
for j in range(n-1):
print(' ', end='')
for k in range(i):
print(i,end='')
print()
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 88
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
Practical No:40
#include <stdio.h>
int main()
{
int i,students [2][2];
for( i=0; i<2; i++)
{
printf("enter the roll number of students %d :",i+1);
scanf("%d",&students[i][0]);
printf("enter the marks of students %d:",i+1);
scanf("%d",&students[i][1]);
}
for (i=0;i<2;i++)
{
printf("student %d :roll number 1: %d,marks :
%d\n",i+1,students[i][0],students[i][1]);
}
}
output:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 89
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
PRACTICAL NO:41
#include<stdio.h>
int main()
{
int arr[20],n;
int i,j,min_index,temp;
printf("ET24BTCL050");
printf("\nHow many values you want to enter:");
scanf("%d",&n);
for(i=0; i<n; i++)
scanf(" %d",&arr[i]);
printf("\nUnsorted Array:");
for(i=0; i<n; i++)
printf("%d ",arr[i]);
printf("\n");
for(i=0; i<n-1; i++)
{
min_index=i;
for(j=i+1; j<n; j++)
{
if(arr[j]<arr[min_index])
min_index=j;
}
temp=arr[min_index];
arr[min_index]=arr[i];
arr[i]=temp;
}
printf("Sorted Array:");
for(i=0; i<n; i++)
printf("%d ",arr[i]);
return 0;
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 90
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
OUTPUT:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 91
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
PRACTICAL NO:42
#include<stdio.h>
int main()
{
int i,j;
char str[]="Hello World!";
char old_char='o';
char new_char='x';
char char_to_delete='l';
printf("ET24BTCL050");
printf("\nOriginal string: %s",str);
for (i=0; str[i]!='\0'; i++)
{
if(str[i]==old_char)
str[i]=new_char;
}
printf("\nString after replacing '%c' with '%c':
%s",old_char,new_char,str);
for (i=0, j=0;str[i]!='\0'; i++)
{
if(str[i]!=char_to_delete)
{
str[j]=str[i];
j++;
}
}
str[j]='\0';
printf("\nString after deleting '%c': %s",char_to_delete,str);
return 0;
}
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 92
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
OUTPUT:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 93
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
PRACTICAL NO:43
#include<stdio.h>
#include<string.h>
int main()
{
char str[] = "ABCD";
printf("%s",strrev(str));
return 0;
}
OUTPUT:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 94
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
PRACTICAL NO:54
print("ET24BTCL050")
n=10
while(n<=10 and n>=1):
print(n)
n-=1 #n=n-1
OUTPUT:
PRACTICAL NO:55
print("ET24BTCL050")
X=int(input("Enter X="))
Y=int(input("Enter Y="))
print("Even no. in range")
if (X%2==0):
X+=2
while X<Y:
print(X)
X+=2
else:
X+=1
while X<Y:
print(X)
X+=2
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 95
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Date:
OUTPUT:
PRACTICAL NO:56
print("ET24BTCL050")
l=['1','a','$']
for a in l:
print(a,end=', ')
OUTPUT:
SCET/CL/2024-25/EVEN/B.TECH/SEM-2/DIV-J Page | 96