Udit Pathak 19btrci031 PSP Assignment
Udit Pathak 19btrci031 PSP Assignment
13. WAP to use switch case to display days of week from Monday
to Sunday.
#include<stdio.h>
void main()
{
int n;
printf("Enter any number b/w 1 and 7:");
scanf("%d",&n);
switch(n)
{
case 1:
printf("Sunday is the first day of the week\n");
break;
case 2:
printf("Monday is the second day of the week\n");
break;
case 3:
printf("Tuesday is the third day of the week\n");
break;
case 4:
printf("Wednesday is the fourth day of the week\n");
break;
case 5:
printf("Thursday is the fifthe day of the week\n");
break;
case 6:
printf("Friday is the sixth day of the week\n");
break;
case 7:
printf("Saturday is the seventh day of the week\n");
break;
default:
printf("You have entered a wrong choice");
}
}
16. WAP to print the first 10 natural numbers and display their
sum.
#include <stdio.h>
void main()
{
int j, sum = 0;
#include<stdio.h>
void main()
{
int i,j;
for(i=1; i<=6; i++)
{
for(j=1; j<i; j++)
{
printf("*");
}
printf("\n");
}
}
#include<stdio.h>
void main()
{
int i, j, k;
for(i=5;i>=1;i--)
{
for(j=1;j<i;j++)
{
printf(" ");
}
for(k=5;k>=i;k--)
{
printf("*");
}
printf("\n");
}
}
while (exp != 0) {
result *= base;
--exp;}
printf("Answer = %lld", result);
return 0; }
30. WAP to use bitwise AND operator between the two integers.
#include<stdio.h>
void main()
{
int a,b,d=0;
printf("Enter any two integers:");
scanf("%d%d",&a,&b);
d=a&b;
printf("After using bitwise AND on %d and %d, the result is: %d",a,b,d);
}
for(int i=0;i<10;i++){
sum += array[i];
}
printf("%d",sum);
return 0;
}
for(int i=0;i<11;i++){
if(array[i]>max){
max = array[i];
}
}
printf("max number is %d",max);
return 0;
}
39. For the numbers 3, 14, 12, and 37, WAP to check whether
number is a multiple of 3 or a multiple
of 7. (Display 1 if condition is true else 0)
#include <stdio.h>
int main(void) {
int array[4] ={3,14,12,37};
for(int i=0;i<4;i++){
int state =0;
if(array[i]%3==0 || array[i]%7==0){
state =1;
}
printf("d \n",state);
}
}
40. WAP to check whether two given integer values are in the
range 20.....50 inclusive. Return true if one or other is in the said
range otherwise false. Range = (20, 84) (14, 50) (11,45) (25, 40).
#include <stdio.h>
int main(void) {
int array[4][2] ={{20,84},{14,50},{11,45},{25,40}};
for(int i=0;i<4;i++){
if(array[i][0]>19 || array[i][1]<51){
printf("true");
}
else{printf("false");}
printf("\n"); }
}
OUTPUT:
44. WAP to read an amount (integer value) and break the amount
into smallest possible number of bank notes. (The possible
banknotes are 100, 50, 20, 10, 5, 2 and 1)
#include <stdio.h>
int main() {
int amt, total;
printf("Input the amount: ");
scanf("%d",&amt);
total = (int)amt/100;
printf("There are: ");
printf("%d Note(s) of 100.00\n", total);
amt = amt-(total*100);
total = (int)amt/50;
printf("%d Note(s) of 50.00\n", total);
amt = amt-(total*50);
total = (int)amt/20;
printf("%d Note(s) of 20.00\n", total);
amt = amt-(total*20);
total = (int)amt/10;
printf("%d Note(s) of 10.00\n", total);
amt = amt-(total*10);
total = (int)amt/5;
printf("%d Note(s) of 5.00\n", total);
amt = amt-(total*5);
total = (int)amt/2;
printf("%d Note(s) of 2.00\n", total);
amt = amt-(total*2);
total = (int)amt/1;
printf("%d Note(s) of 1.00\n", total);
return 0;
}
OUTPUT:
45. WAP that reads three floating values and check if it is possible
to make a triangle with them. Also calculate the perimeter of the
triangle if the said values are valid.
#include <stdio.h>
int main() {
float x, y, z, P, A;
printf("Input the first number: ");
scanf("%f", &x);
printf("Input the second number: ");
scanf("%f", &y);
printf("Input the third number: ");
scanf("%f", &z);
OUTPUT:
START
X,Y,Z
P=X+Y+Z
P
STOP
while (x!=0)
{
printf("\nInput the password: Four digits");
scanf("%d",&passWORD);
if (passWORD==1812)
{
printf("Correct password");
x=0; }
else
{ printf("Wrong password, try another");
}
printf("\n"); }
return 0;
}
OUTPUT:
47. WAP to read the coordinate(x, y) (in Cartesian system) and find the quadrant to which it
belongs (Quadrant -I, Quadrant -II, Quadrant -III, Quadrant -IV). (A Cartesian coordinate system
is a coordinate system that specifies each point uniquely in a plane by a pair of numerical
coordinates. These are often numbered from 1st to 4th and denoted by Roman numerals: I (where
the signs of the (x, y) coordinates are I(+,+), II (−,+), III (−,−), and IV (+,−))
#include <stdio.h>
int main()
{
int x, y;
printf("Input the Coordinate(x,y): ");
printf("\nx: ");
scanf("%d", &x);
printf("y: ");
scanf("%d", &y);
if(x > 0 && y > 0)
{
printf("Quadrant-I(+,+)\n");
}
else if(x> 0 && y < 0)
{
printf("Quadrant-II(+,-)\n");
}
else if(x < 0 && y < 0)
{
printf("Quadrant-III(-,-)\n");
}
else if(x < 0 && y > 0) {
printf("Quadrant-IV(-,+)\n");
}
return 0;
}
OUTPUT:
48. WAP to print a number, it’s square and cube in a line, starting from 1 and print n lines.
Accept number of lines (n, integer) from the user.
#include <stdio.h>
int main() {
int a, i, j = 1, x = 0;
printf("Input number of lines: ");
scanf("%d", &a);
return 0;
}
OUTPUT:
49. WAP that accepts a distance in centimeters and prints the
corresponding value in inches.
#include <stdio.h>
int main()
{
double inch, cm,conversion_rate=2.54;
printf("Input the distance in cm:\n");
scanf("%lf", &cm);
inch = cm / conversion_rate;
printf("Distance of %0.2lf cms is = %0.2lf inches\n", cm, inch);
return 0;
}
OUTPUT:
FLOW CHART:
START
dist
inch = dist/2.54
inch STOP
50. WAP to calculate the Body Mass index (BMI). Display the
message for its fitness.
#include<stdio.h>
float BMI(float weight, float height) {
return weight/(height*height);
}
int main() {
float weight;
printf("Give weight in kg");
scanf("%f",&weight);
float height;
printf("Give height in m");
scanf("%f",&height);
float bmi = BMI(weight,height);
printf("BMI index is : %.2f ",bmi);
if(bmi<=18.5)
printf("\nUnderweight..... eat something you will die out of starvation");
else if(bmi>18.5&&bmi<=24.9)
printf("\nNormal.... fine but you have to maintain it ");
else
printf("\nOverWeight....Go to gym and work out");
return 0;
}
OUTPUT:
FLOW CHART:
START
weight
height
Bmi = weight/(height/height)
Bmi STOP