Solution: Letusc by Yashvantkenetkar

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Let us c

by yashvantkenetkar

solution

chapter 1

[A]

Valid variable name Invalid variable name


Basic-hra
BASICSALARY #MEAN
_basic group.
Mindovermatter 422
hELLO population in 2006
over time
FLOAT queue.
team'svictory
plot # 3
2015_Dday
(basic-hra)-(- is not valid in between two words)
#MEAN-(# is invalid in the name of variable)
group.-(. Is not applicable in the name of variable)
422-(variable name is the combination of letters & digit not only digit)
population in 2006--(there is the gap between the words there should not be any gap)
over time-(same as previous example)
queue.-(same as group.)
team'svictory-(' is not applicable in the name of variable)
plot # 3(there is the gap between (plot & # )&between(# & 3) that is not applicable)
2015_Dday-(variable name start with digit which is not applicable)
[B]
(a).
int=314.562*150;
int is the variable name of integer but the value of integer is not integer so in the int variable we
should define only the integer otherwise it will not take that value that you are giving to the
variable.
(b).
name='Ajay'
name is the character variable so in between '' there shopuld be only one character letter or digit or
special symbol.
Another error is inverted comma is not like that.
(c) .
varchar='3'
inverted comma is not like that.
(d).
3.14*r*r*h=vol_of_cyl;
vol_of_cyl is the name of variable and 3.14*r*r*h is the airthmatic expression so vol_of_cyl must
be on the left side of = & airthmatic expression should be on the rightside of =.
(e).
k=(a*b)(c+(2.5a+b)(d+e)
here there should be * between (2.5 & a) & ((a*b) & (c+(2.5a+b)) & ((c+(2.5a+b) & (d+e)) & also
one ')' between (c+(2.5a+b) & (d+e)
(f).
m_inst = rate of interest * amount in rs ;
variable name 'rate of interest & amount in rs' is not right because there is the gap between the
words of the variable name.
(g).
si = principal * rateofinterest * numberofyears/100;
if you write (principal * rateofinterest*numberofdays)/100 then this is better understandable
otherwise no error.
(h).
area=3.14*r ** 2;
there is no meaning of ** operation in c.
(i).
volume=3.14* r ^ 2 *h;
there is no meaning of r ^ 2 in c.
(j).
k=((a*b)+c)(2.5*a+b)
thre is one * is missing between ((a*b)+c) and (2.5a+b)
(k).
a=b=3=4;
for this expression we can't determine wheather (a=3 or a=4) or(b=3 or b=4)
(l).
count=count+1;
count will be incremented by 1 this is valid
(m).
date = '2Mar 04' ;
spaces between the variable name is not valid & character constant is of only one letter,digit or
special symbol.

[C]
(A).
g=big/2+big*4/big-big+abc/3;
(abc = 2.5,big = 2,assume g to be a float)
g=2/2+2*4/2-2+2.5/3;
step:1
* & / operator will apply first( according to airthmatic operator priority) then + & -
g=1+2*4/2-2+0.8;
step:2
division & multiplicity both have equal priority but by left associativity * should be preferred first.
g=1+4-2+0.8;
g=3.8;
(B).
on=ink*act/2+3/2*act+2+tig;
(ink=4,act=1,tig=3.2,assume on to be an int)
on=4*1/2+3/2+1+3.2;
step1:
* & / should be preferred first then + & -(according to aithmatic operation priority
on=2+1.5+1+3.2;
on=7.7;
but on is integer variable so its value = 7
(c).
s=qui * add / 4 – 6 / 2 + 2 / 3 * 6 / god
(qui = 4,add = 2,god = 2,assume s to be an int)
s=4 * 2 /4 – 6 / 2 + 2 / 3 * 6 / 2;
step 1:
* & / operation should preferred first than + & -(according airthmatic operation priority) but if * & /
both have same priority so from left associativity * should be preferred first.
S=8/4-6/2+0*6/2;
s=2-3;
so, s=-1;
(D).
s= 1 / 3 * a / 4 - 6 / 2 + 2 / 3 * 6 / g ;
(a=4,g=3,assume s to be an int)
s= 1 / 3 * 4 / 4 – 6 / 2 + 2 / 3 * 6 / 3 ;
s=0*4/4–3+0*6/3;
s= - 3;

[D]

(A).
g=10/5/2/1;
g=2/2/1;
g=1/1;
g=1;
(B).
b=3/2+5*4/3;
b=1+5*4/3;
b=1+20/3;
b=1+6;
b=7;
(C).
a=b=c=3+4;
a=b=c=7;

[E]

(a).
ans:- z= (8.8 * (a+b) * 2 / c – 0.5 + 2 * a / (q+r))/((a+b)*(1/m))
(b).
ans:- x=(-b+(b*b)+2*4*a*c)/(2*c)
(c).
ans:- R=(2*v+6.22*(c+d))/(g+v)
(d).
ans:-A=(7.7*b*(x*y+a)/c-0.8+2*b)/((x+a)*(1/y))

[F]

(a).
output:
0 2 0.00000 2.000000
(b).
output:
0 -6
(c).
output:
1
(d).
output:
nn

nn
nn /n/n nn/n
(e).
output:
a b
(f).
output:
p q

[G]

answers
(a). (2) Dennis Ritchir

(b). (4) All the above

(c). (2) A compiler

(d). (4) Both fractional and exponential forms

(e). (1) 1 character

(f). (1) the character Z

(g). (4) All the above

(h). (2) 32767

(i). (4) Both (2) & (3) above


(j). (4) 3 + a = b

(k). (4) / or * , - or +

(l). (1) 6.6/a

(m). (3) ( )

(n). (1) Each new C instruction has to be written on a separate line.

(p). (4) 0

(q). (1) 32768

(r). (2) 6

(s). (2) is used first

(t). (1) At least one digit

(u). (4) 1 character

(v). (4) All the above

(w). (1) Keywords can be used as variable names

(x). (3) variable names on right side of =

(y). (4) * / + -

(z). (2) 0.2857


[H]

(a).

/*To find ramesh's gross salary*/


#include<stdio.h>
void main()
{
float a,b,c,d;
printf("Enter the ramesh's basic salary\n");
scanf("%f",&a);
b=(40*a)/100;
c=(20*a)/100;
d=a-(b+c);
printf("Ramesh's gross salary=%f\n",d);
}

(b).

/*distance between two cities in different units*/


#include<stdio.h>
void main()
{
float a,b,c,d,e;
printf("enter the distance between two cities(in km)\n");
scanf("%f",&a);
b=a*1000;
c=(a*1000)/0.3048;
d=(12000*a)/0.3048;
e=a*100000;
printf("distance between two cities(in meters)=%f\n",b);
printf("distance between two cities(in feet)=%f\n",c);
printf("distance between two cities(in inches)=%f\n",d);
printf("distance between two cities(in centimeters)=%f\n",e);
}

(c).

/*to find aggregate & percentage marks*/


#include<stdio.h>
void main()
{
float a,b,c,d,e,sum,g;
printf("enter the marks obtained by the students in 5 subjects\n");
scanf("%f%f%f%f%f",&a,&b,&c,&d,&e);
sum=a+b+c+d+e;
g=(sum/500)*100;
if(sum<=500)
{
printf("aggregate marks=%f\n",sum);
printf("percentage marks=%f\n",g);
}
else
{
printf("invalid marks\n");
}
}

(d).

/*temperature converter from fahrenheit to celcius unit*/


#include<stdio.h>
void main()
{
float a,b;
printf("Enter the temperature of a city in fahrenheit degree\n");
scanf("%f",&a);
b=(5*(a-32))/9;
printf("the temperature of a city in celcius degree=%f\n",b);
}

(e).

/*to find area & perimeter of both rectangle & circle*/


#include<stdio.h>
void main()
{
float a,b,c,d,e,f,g;
printf("Enter the length,breath of rectangle & redius of a circle respectively\n");
scanf("%f%f%f",&a,&b,&c);
d=a*b;
e=2*(a+b);
f=3.14*c*c;
g=2*3.14*c;
printf("area of the rectangle =%f\n",d);
printf("perimeter of a rectangle =%f\n",e);
printf("area of circle=%f\n",f);
printf("perimeter of circle=%f\n",g);
}

(f).

/*interchange two numbers*/


#include<stdio.h>
void main()
{
int a,b,c,d;
printf("enter two numbers\n");
scanf("%d%d",&a,&b);
c=b;
d=a;
printf("value of c=%d\n",c);
printf("value of d=%d\n",d);
}

(g).

/*sum of each digit of five digit numbers*/


#include<stdio.h>
void main()
{
int a,b,c,d,e,f,g,h,i;
printf("Enter a five digit number\n");
scanf("%d",&a);
b=a/10000;
c=a%10;
d=(a%100)/10;
e=(a%1000)/100;
f=(a%10000)/1000;
h=b%10;
i=b/10;
g=b+c+d+e+f;
if((h!=0)&&(i==0))
{
printf("sum of 5 digit of a five digit no.=%d\n",g);
}
else
{
printf("Entered no. is not 5 digit no.\n");
}
}

(h).

/*reverse 5 digit no.*/


#include<stdio.h>
void main()
{
int a,b,c,d,e,f,g,h,i;
printf("Enter the 5 digit no.\n");
scanf("%d",&a);
b=a/10000;
c=((a%10000)/1000)*10;
d=((a%1000)/100)*100;
e=((a%100)/10)*1000;
f=(a%10)*10000;
h=b%10;
i=b/10;
g=b+c+d+e+f;
if((h!=0)&&(i==0))
{
printf("reverese of no.=%d\n",g);
}
else
{
printf("entered no. is not a 5 digit no.\n");
}
}

(i)

/*sum of first & last digit of 4 digit no.*/


#include<stdio.h>
void main()
{
int a,b,c,d,e,f;
printf("Enter the 4 digit no.\n");
scanf("%d",&a);
b=a/1000;
c=a%10;
e=b%10;
f=b/10;
d=b+c;
if((e!=0)&&(f==0))
{
printf("sum of first & last no. of 4 digit no.=%d\n",d);
}
else
{
printf("entered no. is not a 4 digit no.\n");
}
}

(j).

#include<stdio.h>
void main()
{
int a=80000,b,c,d,e,f,g;
b=(a*52)/100;
c=(a*48)/100;
d=(a*35)/100;
e=(a*13)/100;
f=b-d;
g=c-e;
printf("total no. of illiterate men=%d\n",f);
printf("total no. of illiterate women=%d\n",g);
}

(k).

/*Total no. of currency notes of 100,50 &10*/


#include<stdio.h>
void main()
{
int a,b,c,d,e,f,g,h;
printf("Enter the amout\n");
scanf("%d",&a);
b=a/100;
c=a%100;
d=c/50;
e=c/10;
h=(e-(5*d));
f=b/10;
g=b%10;
if((f==0)&&(g!=0))
{
printf("Total no. of currency note of 100=%d\n",b);
printf("total no. of currency note of 50=%d\n",d);
printf("Total no. of currency note of 10=%d\n",h);

}
else
{
printf("Entered no. is not in the order of 100\n");
}
}

(l).

/*to find the cost price*/


#include<stdio.h>
void main()
{
float a,b,c;
printf("Enter the total selling price & profit earned of 15 items\n");
scanf("%f%f",&a,&b);
c=a+b;
printf("cost price=%f\n",c);

(m).

/*add 1 to each digit of a 5 digit no.*/


#include<stdio.h>
void main()
{
int a,b,c,d,e,f,g,h,i,j;
printf("enter the five digit no.\n");
scanf("%d",&a);
h=a/10000;
b=((h+1)*10000);
c=((((a/1000)%10)+1)*1000);
d=((((a/100)%10)+1)*100);
e=((((a/10)%10)+1)*10);
f=((a%10)+1);
i=h%10;
j=h/10;
g=b+c+d+e+f;
if((i!=0)&&(j==0))
{
printf("Required no.=%d\n",g);
}
else
{
printf("Entered no. is not a 5 digit no.\n");
}
}

thanks......................

You might also like