Let us c(by yashwant kanetkar) chapter 2 solution

rohit kumar
rohit kumarMechanical Enginnering Student at Indian Institute of Technology, PALAKKAD

this is the solution of let us c (5th edition ) chapter 2 Note:- I am not an expert. I am Engineering student. So my answer may have error or mistake

LET US C ( BY
YASHVANTKANETKAR) CHAPTER 2
SOLUTION
Exercise:-
if, if-else, Nested if-elses
[A]
(a).
garbage_value 200
(b).
300 200
(c).
Nothing is going to be print.
(d).
3
(e).
x & y are equal
(f).
10 10 0
(g).
0 50 0
(h).
C is WOW
(i).
15 15 0
(j).
0 20 1
[B]
(a).
We need to use == (equality operator ) instead of using = (assignment) inside if( )
statement.
(b).
There is written extra { } inside if( ) statement due to this it will not give any
output.
(c).
There is no error.
(d).
Here 'then' is written after if statement if we want to print value of x it will not print
because 'then' statement is written after if( ) statement.
(e).
There is no parenthases after if.
(f).
We need to use ==(equality operator) instead of using =(assignment) inside if( )
statement
(g).
There is no error.
(h).
Same as (d). part.
(i).
After if(a>b) ';' is written which is not allowed in c because if we write like this then
compiler understand that there is null statement written after if statement and if we
want to print someting after if( ) statement it will not print.
[C]
(a).
/*to find that seller has made profit or incurred loss & also find the value*/
#include<stdio.h>
void main()
{
float cp,sp,c,d;
printf("Enter the cost price & selling price of an itemn");
scanf("%f%f",&cp,&sp);
c=sp-cp;
d=-c;
if(c>0)
{
printf("seller has made profitn");
printf("profit=%fn",c);
}
else if(c<0)
{
printf("seller has incurred lossn");
printf("loss=%fn",d);
}
else
printf("seller has made neither profit nor lossn");
}
(b).
/*to find the entered integer is even or odd no.*/
#include<stdio.h>
void main()
{
int a,d;
printf("Enter the integern");
scanf("%d",&a);
d=a%2;
if(d==0)
printf("It is an even no.n");
else
printf("It is a odd no.n");
}
(c).
/*to justify entered year is leap year or not*/
#include<stdio.h>
void main()
{
int a,b;
printf("Enter the yearn");
scanf("%d",&a);
b=a%4;
if(b==0)
printf("The year you entered is a leap yearn");
else
printf("The year you entered is not a leap yearn");
}
(d).
/*what is the day on 1st january if monday was the day on 1st jan 1900*/
#include<stdio.h>
void main()
{
int yr,b,c,d,td,e;
printf("Enter the yearn");
scanf("%d",&yr);
b=(yr-1900-1);
c=b/4;
d=b-c;
td=((d*365)+(c*366)+1);
e=td%7;
if(e==0)
printf("the day is mondayn");
if(e==1)
printf("the day is tuesdayn");
if(e==2)
printf("the day is wednesdayn");
if(e==3)
printf("the day is thursdayn");
if(e==4)
printf("the day is fridayn");
if(e==5)
printf("the day is saturdayn");
if(e==6)
printf("the day is sundayn");
}
(e).
/*to evaluate the reverse of five digit no. & also find it is same as entered no. or not*/
#include<stdio.h>
void main()
{
int a,b,c,d,e,f,g,h,i;
printf("enter five digit no.n");
scanf("%d",&a);
b=a/10000;
c=((a%10)*10000);
d=(((a/1000)%10)*10);
e=(((a/100)%10)*100);
f=(((a/10)%10)*1000);
h=b/10;
i=b%10;
g=(b+c+d+e+f);
if((h==0)&&(i!=0))
{
if(a==g)
{
printf("reverse no.=%dn",g);
printf("and reverse no. is same as entered no.n");
}
else
{
printf("reverse no.=%dn",g);
printf("and the reverse no. is not same as entered no.n");
}
}
else
printf("Entered no. is not a 5 digit no.n");
}
(f).
/*out of three person who is the youngest one*/
#include<stdio.h>
void main()
{
int a,b,c;
printf("Enter the ages of ram,shyam & ajay respectivelyn");
scanf("%d%d%d",&a,&b,&c);
if(((a>=b)&&(b>c)) || ((b>=a)&&(a>c)))
printf("ajay is the youngest onen");
else if(((a>=c)&&(c>b)) || ((c>=a)&&(a>b)))
printf("shyam is the youngest onen");
else if(((c>=b)&&(b>a)) || ((b>=c)&&(c>a)))
printf("ram is the youngest onen");
else
printf("can't determine the youngestn");
}
(g).
/*to find the triangle is valid or not*/
#include<stdio.h>
void main()
{
float a1,a2,a3,sum;
printf("Enter three angles of a trianglen");
scanf("%f%f%f",&a1,&a2,&a3);
sum=a1+a2+a3;
if(sum==180)
printf("It is a valid trianglen");
else
printf("Not a valid trianglen");
}
(h).
/*to find the absolute value*/
#include<stdio.h>
void main()
{
int a,b;
printf("Enter a no.n");
scanf("%d",&a);
b= - a;
if(a>=0)
printf("absolute value=%dn",a);
if(a<0)
printf("absolute value=%dn",b);
}
(i).
/*compare the value of area & perimeter of a rectangle*/
#include<stdio.h>
void main()
{
float l,b,ar,p;
printf("Enter the length & breath of a rectanglen");
scanf("%f%f",&l,&b);
ar=(l*b);
p=(2*(l+b));
if(ar>p);
printf("the area of the rectangle is greater than the perimetern");
if(p>=ar)
printf("area of the rectangle is not greater than perimetern");
}
(j).
/*to find the three points are on the same line or not*/
#include<stdio.h>
void main()
{
float x1,y1,x2,y2,x3,y3,a,b,c,d,e,f;
printf("Enter the x1 & y1 of first pointn");
scanf("%f%f",&x1,&y1);
printf("Enter the x2 & y2 of second pointn");
scanf("%f%f",&x2,&y2);
printf("Enter the x3 & y3 of third pointn");
scanf("%f%f",&x3,&y3);
a=((x1-x2)/(y1-y2));
b=-a;
c=((x2-x3)/(y2-y3));
d=-c;
e=((x1-x3)/(y1-y3));
f=-e;
if((a>=0)&&(b>=0)&&(c>=0))
{
if((a==c)&&(c==e))
printf("all the points lie on the same linen");
else
printf("all the points are not on the same linen");
}
else
{
if((b==d)&&(d==f))
printf("all the points lie on the same linen");
else
printf("all the points are not on the same linen");
}
}
(k).
/*to find wheather the point lies inside,outside or on the circle*/
#include<stdio.h>
#include<math.h>
void main()
{
float x1,y1,x2,y2,r,a,dist;
printf("Enter the x coordinate of centre of the circlen");
scanf("%f",&x1);
printf("Enter the y coordinate of centre of circlen");
scanf("%f",&y1);
printf("Enter the x coordinate in the plane of circlen");
scanf("%f",&x2);
printf("Enter the y coordinate in the plane of circlen");
scanf("%f",&y2);
printf("Enter the redius of the circlen");
scanf("%f",&r);
a=(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)));
dist=sqrt(a);
if(dist<r)
printf("the point lies inside the circlen");
if(dist==r)
printf("the point lies on the circlen");
if(dist>r)
printf("the point lies outside the circlen");
}
(l).
/*To find wheather the point lies on the x-axis or at the origin*/
#include<stdio.h>
void main()
{
float x,y;
printf("Enter the x coordinatn");
scanf("%f",&x);
printf("Enter the y coordinaten");
scanf("%f",&y);
if((x==0)&&(y!=0))
printf("point lies on the y-axisn");
else if((x!=0)&&(y==0))
printf("point lies on the x-axisn");
else if((x==0)&&(y==0))
printf("point is at originn");
else
printf("point lies on the x-y plane but not on the x,y or originn");
}
logical operators
If a=10, b=12, c=0, find the values of the expression in the following table:-
Expression value
a!=6 && b>5
a==9 || b<3
! ( a<10 )
! ( a>5 && c )
5 && c != 8 || !c
1
0
1
0
1
[D]
(a).
Dean of student affairs
(b).
Let us c
(c).
W=1 x=0 y=1 z=1
(d).
Y=1 z=1
(e).
Bennarivo
(f).
a
(g).
Definitely C !
(h).
1 1
(i).
z is big
(j).
0 0
(k).
0
[E]
(a).
Incorrect comment:- /* This program
/* is an example of
/* using Logical operators */
correct comment:- /* This program
is an example of
using Logical operators*/
( Between /* and */ we use to write the comments, and comments can not be nested
we have to write only in /* and */) like
(b).
Incorrect statement:- if ( code == 1 & flag == 0)
correct statement :- if ( code == 1 && flag == 0)
In if ( ) statement we always use '&&'(logical operator ) but here only '&' used.
(c).
Incorrect statement:- if ( spy=='a' or password =='z' )
correct statement:- if ( spy=='a' || password =='z' )
Here 'or' is written in the if ( ) statement instead of using or operator( '||' ).
(d).
Incorrect statement :- If ( i=5) && if(j=10);
correct statement :- if((i==5)&&(j==10))
this statement is totally wrong
1.&& operator always use between the airthematic operation inside the if ( )
statement but here used between two if ( ) statement.
2. =(assignment) is used instead of using ==(relational operator)
complete statement is
(e).
Here 'and' used in if ( ) statement instead of using &&( and operator)
incorrect statement:- if(x>=2 and y<=50)
correct statement :- if(x>=2 && y<=50)
(f).
Incorrect statement:- if(a==1 & b==0)
correct statement ;- if(a==1 && b==0)
here also & (assignment ) used istead of && ( logical operator)
(g).
No error.
[F]
(a).
/*To find wheather the year you entered is leap year or not*/
#include<stdio.h>
void main()
{
int y,a,b,c;
printf("Enter the yearn");
scanf("%d",&y);
a=y%100;
b=y%400;
c=y%4;
if(((a==0)&&(b==0))||((a!=0)&&(c==0)))
printf("the year you entered is a leap yearn");
else
printf("the year you entered is not a leap yearn");
}
(b).
/*To find the charcter written by you is a capital letter or small letter or a digit or a
special symbol*/
#include<stdio.h>
void main()
{
char c;
printf("Enter any cahractern");
scanf("%c",&c);
if((c<=90)&&(c>=65))
printf("Entered character is capital lettern");
if((c<=122)&&(c>=97))
printf("Entered character is small case lettern");
if((c<=57)&&(c>=48))
printf("Entered character is a digitn");
if(((c<=47)&&(c>=0))||((c<=64)&&(c>=58))||((c<=96)&&(c>=91))||
((c<=127)&&(c>+123)))
printf("Entered character is an special symboln");
}
(c).
/*to find wheather the person is insured or not also find the premium rate and
maximum amount*/
#include<stdio.h>
void main()
{
int H,age,live,sex;
printf("write the person's health(write 1 if excellent and 0 if poor)n");
scanf("%d",&H);
printf("Enter the age of the personn");
scanf("%d",&age);
printf("write the person's living standard(write 1 if live in the city & 0 if live
in the village)n");
scanf("%d",&live);
printf("write the sex of the person(write 1 for male & 0 for femalen");
scanf("%d",&sex);
if((H==1)&&((age<=35)&&(age>=25))&&(live==1)&&(sex==1))
{
printf("the person should be insuredn");
printf("the premium rate=Rs. 4 per thousandn");
printf("maximum amount =Rs. 2 lakhsn");
}
else if((H==1)&&((age<=35)&&(age>=25))&&(live==1)&&(sex==0))
{
printf("the person should be insuredn");
printf("the premium rate=Rs. 3 per thousandn");
printf("maximum amount =Rs. 1 lakhsn");
}
else if((H==0)&&((age<=35)&&(age>=25))&&(live==0)&&(sex==1))
{
printf("the person should be insuredn");
printf("the premium rate=Rs. 6 per thousandn");
printf("maximum amount =Rs. 10000n");
}
else
printf("person should not be insuredn");
}
(d).
/*to find the grade of the steel*/
#include<stdio.h>
void main()
{
float hard,carbon,tens;
printf("Enter the value of hardness of the steeln");
scanf("%f",&hard);
printf("Enter the carbon content in the steeln");
scanf("%f",&carbon);
printf("enter the value of tensile strength of the steeln");
scanf("%f",&tens);
if((hard>50)&&(carbon<0.7)&&(tens>5600))
printf("grade of steel is 10n");
if((hard>50)&&(carbon<0.7)&&(tens<=5600))
printf("grade of sttel is 9n");
if((hard<50)&&(carbon<0.7)&&(tens>5600))
printf("grade of steel is 8n");
if((hard>50)&&(carbon>0.7)&&(tens>5600))
printf("grade of steel is 7n");
if(((hard>50)&&(carbon>0.7)&&(tens<5600))||
((hard<50)&&(carbon<0.7)&&(tens<5600))||
((hard<50)&&(carbon>0.7)&&(tens>5600)))
printf("grade of steel is 6n");
if((hard<50)&&(carbon>0.7)&&(tens<5600))
printf("grade of steel is 5n");
}
(e).
/*to find the library fine & also find the membership will be cancelled or not*/
#include<stdio.h>
void main()
{
int day;
printf("Enter the no. of days the member is late to return the bookn");
scanf("%d",&day);
if(day<=5)
{
printf("fine = 50 paisen");
printf("your membership will not be cancelledn");
}
else if(day<=10)
{
printf("fine = 1 rupeen");
printf("your membership will not be cancelledn");
}
else if(day<=30)
{
printf("fine = 5 rupeesn");
printf("your membership will not be cancelledn");
}
else if(day>30)
printf("your membership will be cancelledn");
}
(f).
/*write a program to find the triangle is valid or not*/
#include<stdio.h>
void main()
{
int s1,s2,s3;
printf("Enter the three sides of a trianglen");
scanf("%d%d%d",&s1,&s2,&s3);
if((s1>=s2 && s2>=s3)||(s1>=s3 && s3>=s2))
{
if(s2+s3>s1)
printf("triangle is validn");
else
printf("triangle is not validn");
}
if((s2>=s1 && s1>=s3)||(s2>=s3 && s3>=s1))
{
if(s1+s3>s2)
printf("triangle is validn");
else
printf("triangle is not validn");
}
if((s3>=s1 && s1>=s2)||(s3>=s2 && s2>=s1))
{
if(a+b>c)
printf("triangle is validn");
else
printf("triangle is not validn");
}
}
(g).
/*To find wheather the triangle is equilateral or isoscales or scalene or right angled
triangle*/
#include<stdio.h>
void main()
{
float a,b,c,d,e,f;
printf("Enter the three sides of the trianglen");
scanf("%f%f%f",&a,&b,&c);
d=((a*a)+(b*b)-(c*c));
e=((b*b)+(c*c)-(a*a));
f=((c*c)+(a*a)-(b*b));
if((a==b)&&(b==c))
printf("the triangle is an equilateral trianglen");
if(((a==b)&&(b!=c))||((b==c)&&(c!=a))||((c==a)&&(a!=b)))
printf("the triangle is an isoscales trianglen");
if((a!=b)&&(b!=c)&&(c!=a))
printf("the triangle is scalene trianglen");
if((d==0)||(e==0)||(f==0))
printf("the triangle is a right angled trianglen");
}
(h).
/*to find the efficiency of worker*/
#include<stdio.h>
void main()
{
float time;
printf("Enter the time taken by the workern");
scanf("%f",&time);
if((time>=2)&&(time<3))
printf("the worker is highly efficientn");
if((time>=3)&&(time<4))
printf("the worker is ordered to improve speedn");
if((time>=4)&&(time<5))
printf("the worker is given tranning to improve the speedn");
if(time>=5)
printf("the worker has to leave the companyn");
if(time<2)
printf("for any worker this is not possiblen");
}
(i).
/*to find the student is pass or fail*/
#include<stdio.h>
void main()
{
float A,B;
printf("Enter the percentage got by a student in main subject A & the
subsidiary subject Bn");
scanf("%f%f",&A,&B);
if((A>=55)&&(B>=45))
printf("the student has passedn");
else if((A<55)&&(B>=55)&&(A>=45))
printf("the student has passedn");
else if((B<45)&&(A>=65))
printf("To qualify the student is allowed to reappear in an
examinationn");
else
printf("the student is decleared to have failedn");
}
(j).
/*To find the goods will be supply or not*/
#include<stdio.h>
void main()
{
int a,b;
printf("write the credit of the customer wheather it is OK or not(1 for OK & 0
for NOT OKn");
scanf("%d",&a);
printf("write wheather the customer order is less than or equal to that in stock
(1 if it is in the stock & 0 if it is notn");
scanf("%d",&b);
if((a==1)&&(b==1))
printf("supply has requirementn");
else if(((a==0)&&(b==1))||((a==0)&&(b==0)))
printf("do not supplyn");
else if((a==1)&&(b==0))
printf("supply what is in the stock rest will supply latern");
}
Conditional operators
[G]
(a).
unpredictable : no. Not initialised
(b).
200
(c).
Welcome
[H]
(a).
Incorrect statement:- ( code > 1 ? printf(“nHello”) ? printf(“nHi”));
correct statement :- ( code > 1 ? printf(“nHello”) : printf(“nHi”));
in the conditional operator the format is
satement 1 ? statement 2 : statement 3;
but in this it is written like this
statement 1 ? statement 2 ? statement 3;
(b).
Format string written is wrong there is no character we had defined but then also we
have used in the printf function.
(c).
No error.
(d).
The format of conditional operator is
statement1 ? Statement2 : statement3
but here after statement2 ':' is not written so this statement is wrong.
(e).
Incorrect statement:- (n==9 ? printf(“You are correct”) ; : printf(“You are wrong”););
correct statement:- (n==9?printf(“You are correct”) : printf(“You are wrong”));
format of conditional operator is
statement1 ? Statement2 : statement3;
but here '; :' written instead of ':'
(f).
Variable name is wrong
in the variable name we always use to write alphabet,digits & underscore
and also we can't use the digit as the first symbol of name of variable.
(g).
No error
[I]
(a).
main()
{
int x,min,max;
scanf("n%d%d",&max,&x);
x>max?(max=x):(min=x);
}
(b).
main()
{
int code;
scanf("%d",&code);
code>1 ? printf("nJerusalem") : (code<1 ? printf("nEddie") : printf("nC
Brain"));
}
(c).
main()
{
float sal;
printf("Enter the salary");
scanf("%f",&sal);
sal<40000 && sal>25000 ? printf("Manager"):(sal<25000 && sal>15000 ?
printf("Accountant") : printf("Clerk"));
}
[J]
(a).
#include<stdio.h>
void main()
{
char c;
printf("Enter any charactern");
scanf("%c",&c);
c<=122&&c>=97 ? printf("Entered character is lower case alphabetn") :
printf("Entered character is not a lower case alphabetn");
c<=47&&c>=0||c>=58&&c<=64||c>=91&&c<=96||c>=123&&c<=127 ?
printf("Entered character is a special symboln") :
printf("Entered character is not a special symboln");
}
(b).
#include<stdio.h>
void main()
{
int year;
printf("Enter the yearn");
scanf("%d",&year);
year%4==0 ? printf("Entered year is a leap yearn") : printf("Entered year is
not a leap yearn");
}
(c).
#include<stdio.h>
void main()
{
int a,b,c;
printf("Enter three numbersn");
scanf("%d%d%d",&a,&b,&c);
a>b&&b>=c||a>c&&c>=b ? printf("greatest no. =%dn",a) : (b>c&&c>=a||
b>a&&a>=c ? printf("greatest no. = %dn",b):(c>b&&b>=a||
c>a&&a>=b ? printf("greatest no. = %dn",c) : printf("can't
find the greatest no.n")));
}
THANKS............
Let us c(by yashwant kanetkar) chapter 2 solution

Recomendados

Let us C (by yashvant Kanetkar) chapter 3 Solution por
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 SolutionHazrat Bilal
28.3K vistas14 diapositivas
Let us c chapter 4 solution por
Let us c chapter 4 solutionLet us c chapter 4 solution
Let us c chapter 4 solutionrohit kumar
14.4K vistas4 diapositivas
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1 por
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1rohit kumar
50.8K vistas16 diapositivas
Let us c (by yashvant kanetkar) chapter 1 solution por
Let us c (by yashvant kanetkar) chapter 1 solutionLet us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solutionHazrat Bilal
40.8K vistas20 diapositivas
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution por
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solutionLet us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solutionHazrat Bilal
4.4K vistas27 diapositivas
LET US C (5th EDITION) CHAPTER 2 ANSWERS por
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSKavyaSharma65
574 vistas22 diapositivas

Más contenido relacionado

La actualidad más candente

Chapter 3 : Balagurusamy Programming ANSI in C por
Chapter 3 : Balagurusamy Programming ANSI in C Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C BUBT
14K vistas13 diapositivas
Printing different pyramid patterns of numbers,alphabets and stars using C. por
Printing different pyramid patterns of numbers,alphabets and stars using C.Printing different pyramid patterns of numbers,alphabets and stars using C.
Printing different pyramid patterns of numbers,alphabets and stars using C.Hazrat Bilal
1.8K vistas7 diapositivas
Chapter 6 Balagurusamy Programming ANSI in c por
Chapter 6  Balagurusamy Programming ANSI  in cChapter 6  Balagurusamy Programming ANSI  in c
Chapter 6 Balagurusamy Programming ANSI in cBUBT
8.5K vistas43 diapositivas
Chapter 5 Balagurusamy Programming ANSI in c por
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in cBUBT
10.8K vistas36 diapositivas
Object Oriented Programming Using C++ Practical File por
Object Oriented Programming Using C++ Practical FileObject Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical FileHarjinder Singh
14.9K vistas130 diapositivas
Chapter 1 : Balagurusamy_ Programming ANsI in C por
Chapter 1  :  Balagurusamy_ Programming ANsI in C Chapter 1  :  Balagurusamy_ Programming ANsI in C
Chapter 1 : Balagurusamy_ Programming ANsI in C BUBT
6.5K vistas13 diapositivas

La actualidad más candente(20)

Chapter 3 : Balagurusamy Programming ANSI in C por BUBT
Chapter 3 : Balagurusamy Programming ANSI in C Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C
BUBT14K vistas
Printing different pyramid patterns of numbers,alphabets and stars using C. por Hazrat Bilal
Printing different pyramid patterns of numbers,alphabets and stars using C.Printing different pyramid patterns of numbers,alphabets and stars using C.
Printing different pyramid patterns of numbers,alphabets and stars using C.
Hazrat Bilal1.8K vistas
Chapter 6 Balagurusamy Programming ANSI in c por BUBT
Chapter 6  Balagurusamy Programming ANSI  in cChapter 6  Balagurusamy Programming ANSI  in c
Chapter 6 Balagurusamy Programming ANSI in c
BUBT8.5K vistas
Chapter 5 Balagurusamy Programming ANSI in c por BUBT
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in c
BUBT10.8K vistas
Object Oriented Programming Using C++ Practical File por Harjinder Singh
Object Oriented Programming Using C++ Practical FileObject Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical File
Harjinder Singh14.9K vistas
Chapter 1 : Balagurusamy_ Programming ANsI in C por BUBT
Chapter 1  :  Balagurusamy_ Programming ANsI in C Chapter 1  :  Balagurusamy_ Programming ANsI in C
Chapter 1 : Balagurusamy_ Programming ANsI in C
BUBT6.5K vistas
Array Of Pointers por Sharad Dubey
Array Of PointersArray Of Pointers
Array Of Pointers
Sharad Dubey2.6K vistas
LET US C (5th EDITION) CHAPTER 1 ANSWERS por KavyaSharma65
LET US C (5th EDITION) CHAPTER 1 ANSWERSLET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERS
KavyaSharma65502 vistas
Chapter 5 exercises Balagurusamy Programming ANSI in c por BUBT
Chapter 5 exercises Balagurusamy Programming ANSI  in cChapter 5 exercises Balagurusamy Programming ANSI  in c
Chapter 5 exercises Balagurusamy Programming ANSI in c
BUBT2.3K vistas
Infix to-postfix examples por mua99
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examples
mua9961.5K vistas
Chapter 2 : Balagurusamy_ Programming ANsI in C por BUBT
Chapter 2 :  Balagurusamy_ Programming ANsI in CChapter 2 :  Balagurusamy_ Programming ANsI in C
Chapter 2 : Balagurusamy_ Programming ANsI in C
BUBT5.5K vistas
Programming in C Basics por Bharat Kalia
Programming in C BasicsProgramming in C Basics
Programming in C Basics
Bharat Kalia5K vistas
Practical File of C Language por RAJWANT KAUR
Practical File of C LanguagePractical File of C Language
Practical File of C Language
RAJWANT KAUR33.5K vistas
Operator Overloading por Nilesh Dalvi
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi27.3K vistas
The solution manual of programming in ansi by Robin por Shariful Haque Robin
The solution manual of programming in ansi by RobinThe solution manual of programming in ansi by Robin
The solution manual of programming in ansi by Robin
Shariful Haque Robin9.5K vistas

Destacado

Let us c yashwant kanetkar(1) por
Let us c   yashwant kanetkar(1)Let us c   yashwant kanetkar(1)
Let us c yashwant kanetkar(1)OMWOMA JACKSON
9K vistas728 diapositivas
OpenGurukul : Language : Shell Scripting por
OpenGurukul : Language : Shell ScriptingOpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell ScriptingOpen Gurukul
3.6K vistas72 diapositivas
Intro to Linux Shell Scripting por
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scriptingvceder
6.9K vistas34 diapositivas
Unix Shell Scripting por
Unix Shell ScriptingUnix Shell Scripting
Unix Shell ScriptingMustafa Qasim
5.8K vistas88 diapositivas
Quick start bash script por
Quick start   bash scriptQuick start   bash script
Quick start bash scriptSimon Su
3.5K vistas36 diapositivas
Basic command ppt por
Basic command pptBasic command ppt
Basic command pptRohit Kumar
36.3K vistas12 diapositivas

Destacado(9)

OpenGurukul : Language : Shell Scripting por Open Gurukul
OpenGurukul : Language : Shell ScriptingOpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell Scripting
Open Gurukul3.6K vistas
Intro to Linux Shell Scripting por vceder
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scripting
vceder6.9K vistas
Unix Shell Scripting por Mustafa Qasim
Unix Shell ScriptingUnix Shell Scripting
Unix Shell Scripting
Mustafa Qasim5.8K vistas
Quick start bash script por Simon Su
Quick start   bash scriptQuick start   bash script
Quick start bash script
Simon Su3.5K vistas
Basic command ppt por Rohit Kumar
Basic command pptBasic command ppt
Basic command ppt
Rohit Kumar36.3K vistas
Unix Shell Scripting Basics por Dr.Ravi
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
Dr.Ravi11.9K vistas
Linux command ppt por kalyanineve
Linux command pptLinux command ppt
Linux command ppt
kalyanineve81K vistas
Linux ppt por lincy21
Linux pptLinux ppt
Linux ppt
lincy2141.2K vistas

Similar a Let us c(by yashwant kanetkar) chapter 2 solution

Basic c programs updated on 31.8.2020 por
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020vrgokila
147 vistas11 diapositivas
C programming BY Mazedur por
C programming BY MazedurC programming BY Mazedur
C programming BY MazedurMazedurr rahman
182 vistas13 diapositivas
lets play with "c"..!!! :):) por
lets play with "c"..!!! :):)lets play with "c"..!!! :):)
lets play with "c"..!!! :):)Rupendra Choudhary
594 vistas23 diapositivas
Simple C programs por
Simple C programsSimple C programs
Simple C programsab11cs001
3.1K vistas128 diapositivas
VTU Data Structures Lab Manual por
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab ManualNithin Kumar,VVCE, Mysuru
3.6K vistas32 diapositivas
Bti1022 lab sheet 8 por
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8alish sha
252 vistas4 diapositivas

Similar a Let us c(by yashwant kanetkar) chapter 2 solution(20)

Basic c programs updated on 31.8.2020 por vrgokila
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila147 vistas
Simple C programs por ab11cs001
Simple C programsSimple C programs
Simple C programs
ab11cs0013.1K vistas
Bti1022 lab sheet 8 por alish sha
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
alish sha252 vistas
Bti1022 lab sheet 8 por alish sha
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
alish sha319 vistas
Assignment on Numerical Method C Code por Syed Ahmed Zaki
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
Syed Ahmed Zaki7.6K vistas
C lab manaual por manoj11manu
C lab manaualC lab manaual
C lab manaual
manoj11manu1.9K vistas
Understand more about C por Yi-Hsiu Hsu
Understand more about CUnderstand more about C
Understand more about C
Yi-Hsiu Hsu3.9K vistas
C basics por MSc CST
C basicsC basics
C basics
MSc CST322 vistas
Data Structure using C por Bilal Mirza
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza914 vistas
Data Structure in C Programming Language por Arkadeep Dey
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
Arkadeep Dey1.3K vistas

Último

Collective Bargaining and Understanding a Teacher Contract(16793704.1).pptx por
Collective Bargaining and Understanding a Teacher Contract(16793704.1).pptxCollective Bargaining and Understanding a Teacher Contract(16793704.1).pptx
Collective Bargaining and Understanding a Teacher Contract(16793704.1).pptxCenter for Integrated Training & Education
94 vistas57 diapositivas
CUNY IT Picciano.pptx por
CUNY IT Picciano.pptxCUNY IT Picciano.pptx
CUNY IT Picciano.pptxapicciano
54 vistas17 diapositivas
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptx por
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptxGopal Chakraborty Memorial Quiz 2.0 Prelims.pptx
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptxDebapriya Chakraborty
684 vistas81 diapositivas
Ch. 8 Political Party and Party System.pptx por
Ch. 8 Political Party and Party System.pptxCh. 8 Political Party and Party System.pptx
Ch. 8 Political Party and Party System.pptxRommel Regala
53 vistas11 diapositivas
Recap of our Class por
Recap of our ClassRecap of our Class
Recap of our ClassCorinne Weisgerber
81 vistas15 diapositivas
Jibachha publishing Textbook.docx por
Jibachha publishing Textbook.docxJibachha publishing Textbook.docx
Jibachha publishing Textbook.docxDrJibachhaSahVetphys
47 vistas14 diapositivas

Último(20)

CUNY IT Picciano.pptx por apicciano
CUNY IT Picciano.pptxCUNY IT Picciano.pptx
CUNY IT Picciano.pptx
apicciano54 vistas
Ch. 8 Political Party and Party System.pptx por Rommel Regala
Ch. 8 Political Party and Party System.pptxCh. 8 Political Party and Party System.pptx
Ch. 8 Political Party and Party System.pptx
Rommel Regala53 vistas
Narration lesson plan por TARIQ KHAN
Narration lesson planNarration lesson plan
Narration lesson plan
TARIQ KHAN59 vistas
Relationship of psychology with other subjects. por palswagata2003
Relationship of psychology with other subjects.Relationship of psychology with other subjects.
Relationship of psychology with other subjects.
palswagata200348 vistas
Class 9 lesson plans por TARIQ KHAN
Class 9 lesson plansClass 9 lesson plans
Class 9 lesson plans
TARIQ KHAN47 vistas
Structure and Functions of Cell.pdf por Nithya Murugan
Structure and Functions of Cell.pdfStructure and Functions of Cell.pdf
Structure and Functions of Cell.pdf
Nithya Murugan701 vistas
Drama KS5 Breakdown por WestHatch
Drama KS5 BreakdownDrama KS5 Breakdown
Drama KS5 Breakdown
WestHatch87 vistas
The basics - information, data, technology and systems.pdf por JonathanCovena1
The basics - information, data, technology and systems.pdfThe basics - information, data, technology and systems.pdf
The basics - information, data, technology and systems.pdf
JonathanCovena1126 vistas
Ch. 7 Political Participation and Elections.pptx por Rommel Regala
Ch. 7 Political Participation and Elections.pptxCh. 7 Political Participation and Elections.pptx
Ch. 7 Political Participation and Elections.pptx
Rommel Regala105 vistas
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively por PECB
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks EffectivelyISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
PECB 598 vistas
Classification of crude drugs.pptx por GayatriPatra14
Classification of crude drugs.pptxClassification of crude drugs.pptx
Classification of crude drugs.pptx
GayatriPatra1492 vistas

Let us c(by yashwant kanetkar) chapter 2 solution

  • 1. LET US C ( BY YASHVANTKANETKAR) CHAPTER 2 SOLUTION Exercise:- if, if-else, Nested if-elses [A] (a). garbage_value 200 (b). 300 200 (c). Nothing is going to be print. (d). 3
  • 2. (e). x & y are equal (f). 10 10 0 (g). 0 50 0 (h). C is WOW (i). 15 15 0 (j). 0 20 1 [B] (a). We need to use == (equality operator ) instead of using = (assignment) inside if( ) statement. (b). There is written extra { } inside if( ) statement due to this it will not give any output. (c). There is no error.
  • 3. (d). Here 'then' is written after if statement if we want to print value of x it will not print because 'then' statement is written after if( ) statement. (e). There is no parenthases after if. (f). We need to use ==(equality operator) instead of using =(assignment) inside if( ) statement (g). There is no error. (h). Same as (d). part. (i). After if(a>b) ';' is written which is not allowed in c because if we write like this then compiler understand that there is null statement written after if statement and if we want to print someting after if( ) statement it will not print. [C] (a). /*to find that seller has made profit or incurred loss & also find the value*/ #include<stdio.h> void main() { float cp,sp,c,d; printf("Enter the cost price & selling price of an itemn"); scanf("%f%f",&cp,&sp); c=sp-cp; d=-c; if(c>0) {
  • 4. printf("seller has made profitn"); printf("profit=%fn",c); } else if(c<0) { printf("seller has incurred lossn"); printf("loss=%fn",d); } else printf("seller has made neither profit nor lossn"); } (b). /*to find the entered integer is even or odd no.*/ #include<stdio.h> void main() { int a,d; printf("Enter the integern"); scanf("%d",&a); d=a%2; if(d==0) printf("It is an even no.n"); else printf("It is a odd no.n"); } (c). /*to justify entered year is leap year or not*/ #include<stdio.h> void main() {
  • 5. int a,b; printf("Enter the yearn"); scanf("%d",&a); b=a%4; if(b==0) printf("The year you entered is a leap yearn"); else printf("The year you entered is not a leap yearn"); } (d). /*what is the day on 1st january if monday was the day on 1st jan 1900*/ #include<stdio.h> void main() { int yr,b,c,d,td,e; printf("Enter the yearn"); scanf("%d",&yr); b=(yr-1900-1); c=b/4; d=b-c; td=((d*365)+(c*366)+1); e=td%7; if(e==0) printf("the day is mondayn"); if(e==1) printf("the day is tuesdayn"); if(e==2) printf("the day is wednesdayn"); if(e==3) printf("the day is thursdayn");
  • 6. if(e==4) printf("the day is fridayn"); if(e==5) printf("the day is saturdayn"); if(e==6) printf("the day is sundayn"); } (e). /*to evaluate the reverse of five digit no. & also find it is same as entered no. or not*/ #include<stdio.h> void main() { int a,b,c,d,e,f,g,h,i; printf("enter five digit no.n"); scanf("%d",&a); b=a/10000; c=((a%10)*10000); d=(((a/1000)%10)*10); e=(((a/100)%10)*100); f=(((a/10)%10)*1000); h=b/10; i=b%10; g=(b+c+d+e+f); if((h==0)&&(i!=0)) { if(a==g) { printf("reverse no.=%dn",g); printf("and reverse no. is same as entered no.n"); }
  • 7. else { printf("reverse no.=%dn",g); printf("and the reverse no. is not same as entered no.n"); } } else printf("Entered no. is not a 5 digit no.n"); } (f). /*out of three person who is the youngest one*/ #include<stdio.h> void main() { int a,b,c; printf("Enter the ages of ram,shyam & ajay respectivelyn"); scanf("%d%d%d",&a,&b,&c); if(((a>=b)&&(b>c)) || ((b>=a)&&(a>c))) printf("ajay is the youngest onen"); else if(((a>=c)&&(c>b)) || ((c>=a)&&(a>b))) printf("shyam is the youngest onen"); else if(((c>=b)&&(b>a)) || ((b>=c)&&(c>a))) printf("ram is the youngest onen"); else printf("can't determine the youngestn"); } (g). /*to find the triangle is valid or not*/ #include<stdio.h> void main()
  • 8. { float a1,a2,a3,sum; printf("Enter three angles of a trianglen"); scanf("%f%f%f",&a1,&a2,&a3); sum=a1+a2+a3; if(sum==180) printf("It is a valid trianglen"); else printf("Not a valid trianglen"); } (h). /*to find the absolute value*/ #include<stdio.h> void main() { int a,b; printf("Enter a no.n"); scanf("%d",&a); b= - a; if(a>=0) printf("absolute value=%dn",a); if(a<0) printf("absolute value=%dn",b); } (i). /*compare the value of area & perimeter of a rectangle*/ #include<stdio.h> void main() { float l,b,ar,p;
  • 9. printf("Enter the length & breath of a rectanglen"); scanf("%f%f",&l,&b); ar=(l*b); p=(2*(l+b)); if(ar>p); printf("the area of the rectangle is greater than the perimetern"); if(p>=ar) printf("area of the rectangle is not greater than perimetern"); } (j). /*to find the three points are on the same line or not*/ #include<stdio.h> void main() { float x1,y1,x2,y2,x3,y3,a,b,c,d,e,f; printf("Enter the x1 & y1 of first pointn"); scanf("%f%f",&x1,&y1); printf("Enter the x2 & y2 of second pointn"); scanf("%f%f",&x2,&y2); printf("Enter the x3 & y3 of third pointn"); scanf("%f%f",&x3,&y3); a=((x1-x2)/(y1-y2)); b=-a; c=((x2-x3)/(y2-y3)); d=-c; e=((x1-x3)/(y1-y3)); f=-e; if((a>=0)&&(b>=0)&&(c>=0)) { if((a==c)&&(c==e))
  • 10. printf("all the points lie on the same linen"); else printf("all the points are not on the same linen"); } else { if((b==d)&&(d==f)) printf("all the points lie on the same linen"); else printf("all the points are not on the same linen"); } } (k). /*to find wheather the point lies inside,outside or on the circle*/ #include<stdio.h> #include<math.h> void main() { float x1,y1,x2,y2,r,a,dist; printf("Enter the x coordinate of centre of the circlen"); scanf("%f",&x1); printf("Enter the y coordinate of centre of circlen"); scanf("%f",&y1); printf("Enter the x coordinate in the plane of circlen"); scanf("%f",&x2); printf("Enter the y coordinate in the plane of circlen"); scanf("%f",&y2); printf("Enter the redius of the circlen"); scanf("%f",&r); a=(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)));
  • 11. dist=sqrt(a); if(dist<r) printf("the point lies inside the circlen"); if(dist==r) printf("the point lies on the circlen"); if(dist>r) printf("the point lies outside the circlen"); } (l). /*To find wheather the point lies on the x-axis or at the origin*/ #include<stdio.h> void main() { float x,y; printf("Enter the x coordinatn"); scanf("%f",&x); printf("Enter the y coordinaten"); scanf("%f",&y); if((x==0)&&(y!=0)) printf("point lies on the y-axisn"); else if((x!=0)&&(y==0)) printf("point lies on the x-axisn"); else if((x==0)&&(y==0)) printf("point is at originn"); else printf("point lies on the x-y plane but not on the x,y or originn"); } logical operators If a=10, b=12, c=0, find the values of the expression in the following table:-
  • 12. Expression value a!=6 && b>5 a==9 || b<3 ! ( a<10 ) ! ( a>5 && c ) 5 && c != 8 || !c 1 0 1 0 1 [D] (a). Dean of student affairs (b). Let us c (c). W=1 x=0 y=1 z=1 (d). Y=1 z=1 (e). Bennarivo (f). a
  • 13. (g). Definitely C ! (h). 1 1 (i). z is big (j). 0 0 (k). 0 [E] (a). Incorrect comment:- /* This program /* is an example of /* using Logical operators */ correct comment:- /* This program is an example of using Logical operators*/ ( Between /* and */ we use to write the comments, and comments can not be nested we have to write only in /* and */) like (b). Incorrect statement:- if ( code == 1 & flag == 0) correct statement :- if ( code == 1 && flag == 0) In if ( ) statement we always use '&&'(logical operator ) but here only '&' used.
  • 14. (c). Incorrect statement:- if ( spy=='a' or password =='z' ) correct statement:- if ( spy=='a' || password =='z' ) Here 'or' is written in the if ( ) statement instead of using or operator( '||' ). (d). Incorrect statement :- If ( i=5) && if(j=10); correct statement :- if((i==5)&&(j==10)) this statement is totally wrong 1.&& operator always use between the airthematic operation inside the if ( ) statement but here used between two if ( ) statement. 2. =(assignment) is used instead of using ==(relational operator) complete statement is (e). Here 'and' used in if ( ) statement instead of using &&( and operator) incorrect statement:- if(x>=2 and y<=50) correct statement :- if(x>=2 && y<=50) (f). Incorrect statement:- if(a==1 & b==0) correct statement ;- if(a==1 && b==0) here also & (assignment ) used istead of && ( logical operator) (g). No error. [F] (a). /*To find wheather the year you entered is leap year or not*/ #include<stdio.h>
  • 15. void main() { int y,a,b,c; printf("Enter the yearn"); scanf("%d",&y); a=y%100; b=y%400; c=y%4; if(((a==0)&&(b==0))||((a!=0)&&(c==0))) printf("the year you entered is a leap yearn"); else printf("the year you entered is not a leap yearn"); } (b). /*To find the charcter written by you is a capital letter or small letter or a digit or a special symbol*/ #include<stdio.h> void main() { char c; printf("Enter any cahractern"); scanf("%c",&c); if((c<=90)&&(c>=65)) printf("Entered character is capital lettern"); if((c<=122)&&(c>=97)) printf("Entered character is small case lettern"); if((c<=57)&&(c>=48)) printf("Entered character is a digitn"); if(((c<=47)&&(c>=0))||((c<=64)&&(c>=58))||((c<=96)&&(c>=91))|| ((c<=127)&&(c>+123))) printf("Entered character is an special symboln");
  • 16. } (c). /*to find wheather the person is insured or not also find the premium rate and maximum amount*/ #include<stdio.h> void main() { int H,age,live,sex; printf("write the person's health(write 1 if excellent and 0 if poor)n"); scanf("%d",&H); printf("Enter the age of the personn"); scanf("%d",&age); printf("write the person's living standard(write 1 if live in the city & 0 if live in the village)n"); scanf("%d",&live); printf("write the sex of the person(write 1 for male & 0 for femalen"); scanf("%d",&sex); if((H==1)&&((age<=35)&&(age>=25))&&(live==1)&&(sex==1)) { printf("the person should be insuredn"); printf("the premium rate=Rs. 4 per thousandn"); printf("maximum amount =Rs. 2 lakhsn"); } else if((H==1)&&((age<=35)&&(age>=25))&&(live==1)&&(sex==0)) { printf("the person should be insuredn"); printf("the premium rate=Rs. 3 per thousandn"); printf("maximum amount =Rs. 1 lakhsn"); } else if((H==0)&&((age<=35)&&(age>=25))&&(live==0)&&(sex==1)) {
  • 17. printf("the person should be insuredn"); printf("the premium rate=Rs. 6 per thousandn"); printf("maximum amount =Rs. 10000n"); } else printf("person should not be insuredn"); } (d). /*to find the grade of the steel*/ #include<stdio.h> void main() { float hard,carbon,tens; printf("Enter the value of hardness of the steeln"); scanf("%f",&hard); printf("Enter the carbon content in the steeln"); scanf("%f",&carbon); printf("enter the value of tensile strength of the steeln"); scanf("%f",&tens); if((hard>50)&&(carbon<0.7)&&(tens>5600)) printf("grade of steel is 10n"); if((hard>50)&&(carbon<0.7)&&(tens<=5600)) printf("grade of sttel is 9n"); if((hard<50)&&(carbon<0.7)&&(tens>5600)) printf("grade of steel is 8n"); if((hard>50)&&(carbon>0.7)&&(tens>5600)) printf("grade of steel is 7n"); if(((hard>50)&&(carbon>0.7)&&(tens<5600))|| ((hard<50)&&(carbon<0.7)&&(tens<5600))|| ((hard<50)&&(carbon>0.7)&&(tens>5600))) printf("grade of steel is 6n");
  • 18. if((hard<50)&&(carbon>0.7)&&(tens<5600)) printf("grade of steel is 5n"); } (e). /*to find the library fine & also find the membership will be cancelled or not*/ #include<stdio.h> void main() { int day; printf("Enter the no. of days the member is late to return the bookn"); scanf("%d",&day); if(day<=5) { printf("fine = 50 paisen"); printf("your membership will not be cancelledn"); } else if(day<=10) { printf("fine = 1 rupeen"); printf("your membership will not be cancelledn"); } else if(day<=30) { printf("fine = 5 rupeesn"); printf("your membership will not be cancelledn"); } else if(day>30) printf("your membership will be cancelledn"); }
  • 19. (f). /*write a program to find the triangle is valid or not*/ #include<stdio.h> void main() { int s1,s2,s3; printf("Enter the three sides of a trianglen"); scanf("%d%d%d",&s1,&s2,&s3); if((s1>=s2 && s2>=s3)||(s1>=s3 && s3>=s2)) { if(s2+s3>s1) printf("triangle is validn"); else printf("triangle is not validn"); } if((s2>=s1 && s1>=s3)||(s2>=s3 && s3>=s1)) { if(s1+s3>s2) printf("triangle is validn"); else printf("triangle is not validn"); } if((s3>=s1 && s1>=s2)||(s3>=s2 && s2>=s1)) { if(a+b>c) printf("triangle is validn"); else printf("triangle is not validn"); } }
  • 20. (g). /*To find wheather the triangle is equilateral or isoscales or scalene or right angled triangle*/ #include<stdio.h> void main() { float a,b,c,d,e,f; printf("Enter the three sides of the trianglen"); scanf("%f%f%f",&a,&b,&c); d=((a*a)+(b*b)-(c*c)); e=((b*b)+(c*c)-(a*a)); f=((c*c)+(a*a)-(b*b)); if((a==b)&&(b==c)) printf("the triangle is an equilateral trianglen"); if(((a==b)&&(b!=c))||((b==c)&&(c!=a))||((c==a)&&(a!=b))) printf("the triangle is an isoscales trianglen"); if((a!=b)&&(b!=c)&&(c!=a)) printf("the triangle is scalene trianglen"); if((d==0)||(e==0)||(f==0)) printf("the triangle is a right angled trianglen"); } (h). /*to find the efficiency of worker*/ #include<stdio.h> void main() { float time; printf("Enter the time taken by the workern"); scanf("%f",&time); if((time>=2)&&(time<3)) printf("the worker is highly efficientn");
  • 21. if((time>=3)&&(time<4)) printf("the worker is ordered to improve speedn"); if((time>=4)&&(time<5)) printf("the worker is given tranning to improve the speedn"); if(time>=5) printf("the worker has to leave the companyn"); if(time<2) printf("for any worker this is not possiblen"); } (i). /*to find the student is pass or fail*/ #include<stdio.h> void main() { float A,B; printf("Enter the percentage got by a student in main subject A & the subsidiary subject Bn"); scanf("%f%f",&A,&B); if((A>=55)&&(B>=45)) printf("the student has passedn"); else if((A<55)&&(B>=55)&&(A>=45)) printf("the student has passedn"); else if((B<45)&&(A>=65)) printf("To qualify the student is allowed to reappear in an examinationn"); else printf("the student is decleared to have failedn"); } (j). /*To find the goods will be supply or not*/ #include<stdio.h>
  • 22. void main() { int a,b; printf("write the credit of the customer wheather it is OK or not(1 for OK & 0 for NOT OKn"); scanf("%d",&a); printf("write wheather the customer order is less than or equal to that in stock (1 if it is in the stock & 0 if it is notn"); scanf("%d",&b); if((a==1)&&(b==1)) printf("supply has requirementn"); else if(((a==0)&&(b==1))||((a==0)&&(b==0))) printf("do not supplyn"); else if((a==1)&&(b==0)) printf("supply what is in the stock rest will supply latern"); } Conditional operators [G] (a). unpredictable : no. Not initialised (b). 200 (c). Welcome
  • 23. [H] (a). Incorrect statement:- ( code > 1 ? printf(“nHello”) ? printf(“nHi”)); correct statement :- ( code > 1 ? printf(“nHello”) : printf(“nHi”)); in the conditional operator the format is satement 1 ? statement 2 : statement 3; but in this it is written like this statement 1 ? statement 2 ? statement 3; (b). Format string written is wrong there is no character we had defined but then also we have used in the printf function. (c). No error. (d). The format of conditional operator is statement1 ? Statement2 : statement3 but here after statement2 ':' is not written so this statement is wrong. (e). Incorrect statement:- (n==9 ? printf(“You are correct”) ; : printf(“You are wrong”);); correct statement:- (n==9?printf(“You are correct”) : printf(“You are wrong”)); format of conditional operator is statement1 ? Statement2 : statement3; but here '; :' written instead of ':' (f). Variable name is wrong in the variable name we always use to write alphabet,digits & underscore and also we can't use the digit as the first symbol of name of variable.
  • 24. (g). No error [I] (a). main() { int x,min,max; scanf("n%d%d",&max,&x); x>max?(max=x):(min=x); } (b). main() { int code; scanf("%d",&code); code>1 ? printf("nJerusalem") : (code<1 ? printf("nEddie") : printf("nC Brain")); } (c). main() { float sal; printf("Enter the salary"); scanf("%f",&sal); sal<40000 && sal>25000 ? printf("Manager"):(sal<25000 && sal>15000 ? printf("Accountant") : printf("Clerk")); }
  • 25. [J] (a). #include<stdio.h> void main() { char c; printf("Enter any charactern"); scanf("%c",&c); c<=122&&c>=97 ? printf("Entered character is lower case alphabetn") : printf("Entered character is not a lower case alphabetn"); c<=47&&c>=0||c>=58&&c<=64||c>=91&&c<=96||c>=123&&c<=127 ? printf("Entered character is a special symboln") : printf("Entered character is not a special symboln"); } (b). #include<stdio.h> void main() { int year; printf("Enter the yearn"); scanf("%d",&year); year%4==0 ? printf("Entered year is a leap yearn") : printf("Entered year is not a leap yearn"); } (c). #include<stdio.h> void main() { int a,b,c; printf("Enter three numbersn");
  • 26. scanf("%d%d%d",&a,&b,&c); a>b&&b>=c||a>c&&c>=b ? printf("greatest no. =%dn",a) : (b>c&&c>=a|| b>a&&a>=c ? printf("greatest no. = %dn",b):(c>b&&b>=a|| c>a&&a>=b ? printf("greatest no. = %dn",c) : printf("can't find the greatest no.n"))); } THANKS............