You are on page 1of 12

qwertyuiopasdfghjklzxcvbnmqwertyuio

pasdfghjklzxcvbnmqwertyuiopasdfghjkl
zxcvbnmqwertyuiopasdfghjklzxcvbnmq
wertyuiopasdfghjklzxcvbnmqwertyuiop
Assignment 5

asdfghjklzxcvbnmqwertyuiopasdfghjklzx
NAME: Jeet Ariwala

cvbnmqwertyuiopasdfghjklzxcvbnmqwe
Rollno.: A-69

rtyuiopasdfghjklzxcvbnmqwertyuiopasd
fghjklzxcvbnmqwertyuiopasdfghjklzxcvb
nmqwertyuiopasdfghjklzxcvbnmqwerty
uiopasdfghjklzxcvbnmqwertyuiopasdfgh
jklzxcvbnmqwertyuiopasdfghjklzxcvbnm
qwertyuiopasdfghjklzxcvbnmqwertyuio
pasdfghjklzxcvbnmqwertyuiopasdfghjkl
zxcvbnmrtyuiopasdfghjklzxcvbnmqwert
yuiopasdfghjklzxcvbnmqwertyuiopasdfg
hjklzxcvbnmqwertyuiopasdfghjklzxcvbn
mqwertyuiopasdfghjklzxcvbnmqwertyui
Q-1A function f is defined as follows
F(x) = ax3–bx2 + cx –d if x > k
=0 if x = k
= - ax3 + bx2 –cx + d if x < k
Write a program to accept a, b, c, d, k and x. and display
the value of f(x).

Source Code:
#include<math.h>
#include<stdio.h>
intmain()
{
inta,b,c,d,k,x,ans;
printf("Enter value of a:");
scanf("%d",&a);
printf("\nEnter value of b:");
scanf("%d",&b);
printf("\nEnter value of c:");
scanf("%d",&c);
printf("\nEnter value of d:");
scanf("%d",&d);
printf("\nEnter value of k:");
scanf("%d",&k);
printf("\nEnter value of x:");
scanf("%d",&x);

if(x>k)
{
printf("\nFunction f(x)=ax^3-bx^2+cx-d");
ans=((a*x*x*x)-(b*x*x)+(c*x)-d);
printf("\nValue of f(x):%d",ans);
}
else if(x<k)
{
printf("\nFunction f(x)=-ax^3+bx^2-cx+d");
ans=((-(a*x*x*x))+(b*x*x)-(c*x)+d);
printf("\nValue of f(x):%d",ans);
}
else
{
printf("\nValue of f(x): 0");
}

Output:

Q-2 Write a program to read marks from the keyboard


and display equivalent grade.
(Use if-else if ladder)
Marks Grade

100 –80 Distinction


60 –79 First Class
35 –59 Second Class
0 –35 Fail

Program:

#include<stdio.h>
intmain()
{
int a;
printf("ENTER YOUR MARKS OUT OF 100:");
scanf("%d",&a);

if(a>=80)
{
printf("Your grade is Distinction.");
}
else if(a>=60)
{
printf("Your grade is First Class.");
}
else if(a>=35)
{
printf("Your grade is Second Class.");
}

else
{
printf("You are fail");
}
}

Output:

Q-3Write programs for the following:


i)Take two numbers of float and divide the first number
by second and show the result as integer number.

Program:

#include<stdio.h>
intmain()
{
float a,b,x;
intans;
printf("Enter value of a:");
scanf("%f",&a);
printf("\nEnter value of b:");
scanf("%f",&b);
x=(a/b);
ans=int(x);
printf("\nResult is:%d",ans);
}

Output:

ii)Take the first number as -VE integer and second as


+VE float, divide the first by secondand display output as
integer number.

Program:

#include<stdio.h>
intmain()
{
float b,x;
inta,ans;
printf("Enter value of a:"); //negative integer
scanf("%d",&a);
printf("\nEnter value of b:"); //positive float
scanf("%f",&b);

x=(a/b);
ans=int(x);
printf("\nResult is:%d",ans);
}
Output:

iii)Take the first number as +VE float and second number


as -VE integer, divide the first
number by second and display output in the float.
Program:

#include<stdio.h>
intmain()
{ float a,c;
int b;
printf("enter the value of a : "); //positive float
scanf("%f",&a);
printf("enter the value of b : "); //negative integer
scanf("%d",&b);
c= a/b;
printf("ANS IS %f",c); //float number
return 0;
}

Output:
Q-4A cloth showroom has announced the following
seasonal discount on the purchase of items.
Purchase Discount
Amount
Mill Cloth Handloom Items

0 –100 - 5.0 %
101 –200 5.0 % 7.5%

201 –300 7.5% 10.0%

Above 300 10.0 % 15.0%

Write a program to compute the net amount to be paid by


a customer.
Program:

#include<stdio.h>
intmain()
{

float a,b,m,h;
printf("enter the value of m : ");
scanf("%f",&m);
printf("enter the value of h : ");
scanf("%f",&h);
a=m+h;

if (a>300)
{
b=m-(m/10)+h-(h*15/100);
printf("YOUR NET BILL IS %f",b);
}
else if (a>200)
{
b=m-(m*7.5/100)+h-(h*10/100);
printf("YOUR NET BILL IS %f",b);
}
else if (a>100)
{
b=m-(m*5/100)+h-(h*7.5/100);
printf("YOUR NET BILL IS %f",b);
}
else
{
b=m-(m*0/100)+h-(h*5/100);
printf("YOUR NET BILL IS %f",b);
}
return 0;
}

Output:

Q-6The commission a life insurance sales woman earns on


insurance policy sold is as follows:
Policy Amount (Rs.) Commission

Less or Equal to 10000 0.5 % of Policy Amount

Between 10000 and Rs 50 + 0.6 % of the


25000 amount in excess
of Rs 10000
Greater or Equal to Rs 140 + 0.75 % of the
25000 amount in
excess of Rs 25000
Write a program that reads the amount of insurance sold
and output the commission due to thesales woman.

Program:

#include<stdio.h>

intmain()
{ //c is the amount of commission
float x,c; //x is amount of insuarance
printf("enter the value of x: ");
scanf("%f",&x);

if (x>=25000)
{
c=((x-25000)*0.75/100)+140;
printf("THE COMMISSION IS %.2f",c);
}
else if (x>=10000)
{
c=(x*0.6/100)+50;
printf("the commission is %.2f",c);
}
else
{
c=(x*0.5/100);
printf("YOUR COMMISION IS %.2f",c);
}
return 0;
}

Output:

You might also like