0% found this document useful (0 votes)
27 views24 pages

Pps Practical File

This document is a practical file for the subject 'Programming for Problem Solving' submitted by a B.Tech student. It contains various programming assignments written in C, including tasks for calculating marks, interest, area, temperature conversion, and more. Each program includes code snippets, sample outputs, and explanations of their functionality.

Uploaded by

avnirajput480
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views24 pages

Pps Practical File

This document is a practical file for the subject 'Programming for Problem Solving' submitted by a B.Tech student. It contains various programming assignments written in C, including tasks for calculating marks, interest, area, temperature conversion, and more. Each program includes code snippets, sample outputs, and explanations of their functionality.

Uploaded by

avnirajput480
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

S.

D College of Engineering & Technology,


Muzaffarnagar.

(2023-2024)
(PRACTICAL FILE)
Subject- Programming for Problem Solving
(BCS-201)

Submitted by: Submitted to :


Avni Rajput Kanan mam
B.tech (CSE),2300830100021
First year (2nd semester)
1. WAP that accepts the marks of 5 subjects and find the
sum and percentage marks obtained.
#include<stdio.h>

#include<conio.h>

void main()

int s1,s2,s3,s4,s5,total=500,sum=0;

float per;

printf("Enter Marks of 5 Subjects: ");

scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5);

sum=s1+s2+s3+s4+s5;

printf("Sum of 5 Subjects is: %d\n",sum);

per=(sum*100)/total;

printf("Percentage is: %f",per);

getch();

Output:-
Enter Marks of 5 Subjects: 80 70 85 83 90
Sum of 5 Subjects is: 408
Percentage is: 81.000000
2. WAP to calculate the simple interest and compound
interest. The principal,amount,rate of interest and time are
entered through keyboard.
#include<stdio.h>
#include<conio.h>
#include<math.h>

int main(){
floatp, t, r, si, ci;
clrscr();
printf("Enter principal amount (p): ");
scanf("%f", &p);
printf("Enter time in year (t): ");
scanf("%f", &t);
printf("Enter rate in percent (r): ");
scanf("%f", &r);

/* Calculating simple interest */


si = (p * t * r)/100.0;

/* Calculating compound interest */


ci = p * (pow(1+r/100, t) - 1);

printf("Simple Interest = %0.3f\n", si);


printf("Compound Interest = %0.3f", ci);
getch();
return(0);
}
Output:-
Enter principal amount (p): 5000 ↲
Enter time in year (t): 2 ↲
Enter rate in percent (r): 18 ↲
Simple Interest = 1800.000
Compound Interest = 1962.000

Note: ↲ indicates ENTER is pressed.

3.WAP to calculate the area and circumference of a circle.


#include <stdio.h>
#define PI 3.14159
int main() {
double radius, area, circumference;
printf("Enter the radius of the circle: ");
scanf("%lf", &radius);
area = PI * radius * radius;
circumference = 2 * PI * radius;
printf("Area of the circle: %.2lf\n", area);
printf("Circumference of the circle: %.2lf\n", circumference);
return 0;
}
Output :-
Enter the radius of the circle :34
Area of the circle : 3631.68
Circumference of the circle : 213.63
4.WAP that accepts the temperature in centigrade and
converts into farenheit using the formula C/5=(F-32)/9.

#include<stdio.h>
#include<conio.h>

int main()
{
floatcelsius, fahr,;
clrscr();
printf("Enter temperature in celsius:
");
scanf("%f", &celsius);
fahr = 1.8 * celsius + 32.0;
printf("%0.2f Celsius = %0.2f
Fahrenheit\n", celsius, fahr);
return(0);
}

Output:-
Enter temperature in celsius: 47↲
47.00 Celsius = 116.60 Fahrenheit

Note: ↲ indicates ENTER is pressed.


5. WAP that swaps values of two variable using
a third variable.
#include<stdio.h>
#include<conio.h>

int main()
{
a, b, temp;
int
clrscr();
printf("Enter value of a: ");
scanf("%d", &a);
printf("Enter value of b: ");
scanf("%d", &b);
printf("Before swapping: a = %d and b =
%d\n", a, b);
temp = a;
a = b;
b = temp;
printf("After swapping: a = %d and b =
%d", a, b);
getch();
return(0);
}
Output:-
Enter value of a: 23 ↲
Enter value of b: 17 ↲
Before swapping: a = 23 and b = 17
After swapping: a = 17 and b = 23

Note: ↲ indicates ENTER is pressed.


6. WAP that checks weather two numbers added by the user are equal or
not.
#include <stdio.h>
void main()
{
int int1, int2;
printf("Input the values for Number1 and Number2 :
"); .
scanf("%d %d", &int1, &int2);
if (int1 == int2){
printf("Number1 and Number2 are equal\n");
}

else {
printf("Number1 and Number2 are not equal\n");
}
getch();
}

Output:-
Input the values for Number1 and Number2 : 15 15
Number1 and Number2 are equal
Input the values for Number1 and Number2 : 21 22
Number1 and Number2 are not equal

7. WAP to find the greatest of three numbers.


#include<stdio.h>
#include<conio.h>
int main()
{
float a,b,c,lg;
clrscr();
printf("Enter three numbers:\n");
scanf("%f%f%f",&a,&b,&c);
lg = a;
if(b>lg){
lg = b;
}

if(c>lg){
lg = c;
}
printf("Largest = %0.2f", lg);
return(0);
}
Output:-

Run 1:
------------

56 ↲
Enter thre numbers:

78 ↲
67 ↲
Largest = 78.00

Run 2:
------------

-89 ↲
Enter thre numbers:

-78 ↲
-67 ↲
Largest = -67.00

Note: ↲ indicates ENTER is pressed.


8.WAP that finds weather a given number is even or odd
#include<stdio.h>
int main()
{
int number;
printf("Enter number: ");
scanf("%d", &number);
if (number%2==0){
printf(“EVEN”);
}
else{
printf(“ODD”);
}
return 0;
}
Output:-

Run 1:
---------------
Enter number: 11
ODD.

Run 2:
---------------
Enter number: 24
EVEN
9.WAP that tells weather a given year is leap year or not.
#include<stdio.h>
#include<conio.h>

void main()
{
int y;
clrscr();
printf("Enter year: ");
scanf("%d", &y);
if( (y%400 == 0) || (y%4 == 0 && y%100 !=
0) )
{
printf("%d is a leap year.", y);
}
else
{
printf("%d is not a leap year.", y);
}
getch();
}
Output:-

Run 1:

Enter year: 3000 ↲


----------------

3000 is not a leap year.


Run 2:

Enter year: 2004 ↲


----------------

2004 is not a leap year.

Note: ↲ indicates ENTER is pressed.

10.WAP that accepts marks of five subjects and finds the percentage and
prints grades according to the following criteria:

Between 90-100%--------Print’A’

80-90%----------------------Print’B’

60-80%-----------------------Print’C’

Below 60%------------------Print’D’
#include<stdio.h>
void main()
{
int hindi, english, science,math,computer,sum ;
float per;
printf("Enter marks of Hindi=");
scanf("%d",&hindi);
printf("Enter marks of English=");
scanf("%d",&english);
printf("Enter marks of Science=");
scanf("%d",&science);
printf("Enter marks of Math=");
scanf("%d",&math);
printf("Enter marks of Computer=");
scanf("%d",&computer);

sum=hindi+english+science+math+computer;
printf("\nSum of marks=%d",sum);

per=(float)sum/5;
printf("\nPercentage of marks=%f",per);
if(per>=90&&per<=100)
{
printf("\nGrade A");
}
else if(per>=80&&per<90)
{
printf("\nGrade B");
}
else if(per>=60&&per<80)
{
printf("\nGrade C");
}
else if(per<60)
{
printf("\nGrade D");
}
getch();
}
Output:-
Enter marks of Hindi=45
Enter marks of English=65
Enter marks of Science=89
Enter marks of Math=78
Enter marks of Computer=65

Sum of marks=342
Percentage of marks=68.400002
Grade C

11. WAP that takes two operands and one operator from the user,
perform the operation, and prints the result by by using switch statement
#include <stdio.h>
#include <conio.h>
void main()
{
int a, b, c;

char ch;
clrscr() ;

printf("Enter your operator(+, -, /, *, %)\n")


;
scanf("%c", &ch);

printf("Enter the values of a and b\n");

scanf("%d%d", &a, &b);

switch(ch)
{
case '+': c = a + b;
printf("addition of two numbers is %d", c);
break;

case '-': c = a - b;
printf("substraction of two numbers is %d", c);
break;

case '*': c = a * b;
printf("multiplication of two numbers is %d", c);
break;

case '/': c = a / b;
printf("remainder of two numbers is %d", c);
break;

case '%': c = a % b;
printf("quotient of two numbers is %d", c);
break;

default: printf("Invalid operator");


break;
}
getch();
}
output:-

Enter you operator(+, -, /, *, %)


+
Enter the values of a and b

13

addition of two numbers is 4


12. WAP to print the sum of all numbers up to a given number.
#include<stdio.h>
#include<conio.h>

int main()
{
int n, i;
float num, sum = 0, avg;
clrscr();
printf("How many numbers?\n");
scanf("%d",&n);
i=1;
while(i<=n)
{
printf("Enter number-%d: ",i);
scanf("%f", &num);
sum = sum + num;
i++;
}
printf("\nSum = %0.2f", sum);
getch();
return(0);
}
Output:-

How many numbers?


4 ↲
Enter number-1: 67 ↲
Enter number-2: 89 ↲
Enter number-3: 99 ↲
Enter number-4: 56 ↲
Sum = 311.00

13.WAP to find the factorial of a given number.


#include<stdio.h>
#include<conio.h>
int main()
{
long int i,n, f=1;
clrscr();
printf("Enter any positive integer: ");
scanf("%ld", &n);
for(i=1;i<= n;i++)
{
f = f*i;
}
printf("%ld != %ld",n,f);
getch();
return(0);
}
Output:-

Enter any positive integer: 9 ↲


Note: ↲ indicates enter is pressed.
9 != 362880

14.WAP to print sum of even and odd numbers from 1to N numbers.
#include <stdio.h>

void main()
{
int i, num, odd_sum = 0, even_sum = 0;
printf("Enter the value of num\n");
scanf("%d", &num);
for (i = 1; i <= num; i++)
{
if (i % 2 == 0)
even_sum = even_sum + i;
else
odd_sum = odd_sum + i;
}
printf("Sum of all odd numbers = %d\n",
odd_sum);
printf("Sum of all even numbers = %d\n",
even_sum);
}
Output:-
Case 1:
Enter the value of num
10
Sum of all odd numbers = 25
Sum of all even numbers = 30

Case 2:
Enter the value of num
100
Sum of all odd numbers = 2500
Sum of all even numbers = 2550
15.WAP to print the Fibonacci series.
#include<stdio.h>
#include<conio.h>

int main()
{
int n, a=0, b=1, next, i;
clrscr();
printf("Enter how many terms? ");
scanf("%d", &n);

printf("First %d Fibonacci terms are: \


n", n);
for(i=1;i<=n;i++)
{
printf("%d\t", a);
next = a + b;
a = b;
b = next;
}
getch();
return(0);
}
Output:-

Enter how many terms? 8 ↲


First 8 Fibonacci terms are:
0 1 1 2 3 5 8 13
Note: ↲ indicates enter is pressed.

16. WAP to check weather the entered number is prime or not.


#include<stdio.h>
#include<conio.h>

int main()
{
int number, i, flag=0;
clrscr();
printf("Enter integer number: ");
scanf("%d", &number);
for(i=2;i<=number/2; i++)
{
if(number%i==0)
{
flag = 1;
break;
}
}
if(flag==0 && number>=2)
{
printf("%d is PRIME.", number);
}
else
{
printf("%d is NOT PRIME.", number);
}
return(0);
}
Output:-

Run 1:

Enter integer number: 13 ↲


-----------

13 is PRIME.

Run 2:

Enter integer number: 16 ↲


-----------

16 is NOT PRIME.

Run 3:

Enter integer number: 1 ↲


-----------

1 is NOT PRIME.

Run 4:

Enter integer number: 2 ↲


-----------

2 is PRIME.

Note: ↲ indicates enter is pressed.


17. WAP to find the sum of digits of the number entered.
#include <stdio.h>
int main()
{
int number, sum = 0;
printf("Enter the number ");
scanf("%d", &number);
printf("The number is = %d\n", number);
while (number != 0)
{
sum += number % 10;
number = number / 10;
}
printf("Sum: %d\n", sum);
return 0;
}

18. WAP to find the reverse of a number.

#include<stdio.h>
#include<conio.h>
int main()
{
long int number, reverse=0, rem,
original;
clrscr();
printf("Enter number: ");
scanf("%ld", &number);

original = number;

while(number!=0)
{
rem = number % 10;
reverse = reverse*10 + rem;
number = number/10;
}
printf("Reverse of %ld is %ld",
original, reverse);
getch();

return(0);
}
Output:-

Enter number: 67859 ↲


Reverse of 67859 is 95876

Note: ↲ indicates enter is pressed.


S.NO Program Remark

1 WAP that accepts the marks of 5 subjects and find the


sum and percentage marks obtained.

2 WAP to calculate the simple interest and compound


interest. The principal,amount,rate of interest and
time are entered through keyboard.

3 WAP to calculate the area and circumference of a


circle.

4 WAP that accepts the temperature in centigrade and


converts into farenheit using the formula C/5=(F-
32)/9

5 WAP that swaps values of two variable using a third


variable.

6 WAP that checks weather two numbers added by the


user are equal or not.

7 WAP to find the greatest of three numbers


8 WAP that finds weather a given number is even or
odd

9 WAP that tells weather a given year is leap year or


not.

10 WAP that accepts marks of five subjects and finds the


percentage and prints grades according to the
following criteria:

Between 90-100%--------Print’A’

80-90%----------------------Print’B’

60-80%-----------------------Print’C’

Below 60%------------------Print’D’

11 WAP that takes two operands and one operator from


the user, perform the operation, and prints the result
by by using switch statement

12 WAP to print the sum of all numbers up to a given


number.

13 WAP to find the factorial of a given number.

14 WAP to print sum of even and odd numbers from 1to


N numbers.
15 WAP to print the Fibonacci series.

16 WAP to check weather the entered number is prime


or not.

17 WAP to find the sum of digits of the number entered.

18 WAP to find the reverse of a number.

You might also like