4.1 State Whether The Following Statements Are True or False
4.1 State Whether The Following Statements Are True or False
3.4: Declared a as int and b as float, state whether the following statement are
true or false.
4.4 Declared a as int and b a float, state whether the following statements are
true or false.
a. The statement a=1/3+1/3+1/3;assigns the value 1 to a.
Ans :False
b. The statement b=1.0/3.0+1.0/3.0+1.0/3.0;assigns a value 1.0 to b.
Ans: True
c. The statement b=1.0/3.0*3.0 gives a value 1.0 to b.
Ans:True
d. The statement b=1.0/3.0+2.0/3.0 assigns a value 1.0 to b;
Ans: True
e. The statement a=15/10.0+3/2;assigns a value of 3 to a.
Ans: False
4.5
a. !(5+5>=10)
Ans: False
b.5+5 = =10 || 1+3 ==5;
Ans: True
c.5>10||10<20 &&3<5
Ans: True
d.10!=15 && !(10<20) ||15>30
Ans: False
4.6 Which of the following arithmetic expression are valid ? If valid, giving the
value of the expression.
a.25/3%2
Ans: Invalid
b.+9/4+5
Ans: Valid
c.7.5%3
Ans: Invalid
d.14%3 +7%2
Ans: Valid
e.-14%3
Ans: Valid
f.15.25+-5.2
Ans: Valid
g.(5/3)*3+5%3
Ans: Valid
h.21%(int)4.5
Ans: Valid
4.7 Writing C assignment statements to evaluate the following equations:
a.
#include<stdio.h>
int main()
{
int r,h;
float area;
printf(“r=”);
scanf(“%d ”,&r);
printf(“h=”);
scanf(“%d”,&h);
area=3.1416*r*r+2*3.1416*r*h;
printf(“Area= %f”,area);
return 0;
}
b.
#include<stdio.h>
int main()
{
int m1,m2;
float g,torque;
printf(“m1=”);
scanf(“%d ”,&m1);
printf(“m2=”);
scanf(“%d”,&m2);
printf(“g=”);
scanf(“%f”,&g);
torque=(2*m1*m2*g)/(m1+m2);
printf(“Torque=%f”,torque);
return 0;
}
c.
#include<stdio.h>
int main()
{
int a,b,p,q,r,n,x;
float side;
printf(“Enter the value of a,b,x\n”);
scanf(“%d%d%d”,&a,&b,&x);
p=(a*a+b*b);
r=(2*a*b);
n=cos(x);
side=sqrt(p-r*n);
printf(“%f”,side);
return 0;
d.
#include<stdio.h>
int main()
{
int mass,acceleration,height,velocity;
float energy;
printf(“mass=”);
scanf(“%d”,&mass);
printf(“acceleration=”);
scanf(“%d”,&acceleration);
printf(“height=”);
scanf(“%d”,&height);
printf(“velocity=”);
scanf(“%d”,&velocity);
energy=mass*(acceleration*height+pow(velocity,2)/2);
printf(“%f”,energy);
return 0;
}