SlideShare a Scribd company logo
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

More Related Content

What's hot

Chapter 2 : Balagurusamy_ Programming ANsI in C
Chapter 2 :  Balagurusamy_ Programming ANsI in CChapter 2 :  Balagurusamy_ Programming ANsI in C
Chapter 2 : Balagurusamy_ Programming ANsI in C
BUBT
 
Chapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CChapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in C
BUBT
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
RAJWANT KAUR
 
Chapter 1 : Balagurusamy_ Programming ANsI in C
Chapter 1  :  Balagurusamy_ Programming ANsI in C Chapter 1  :  Balagurusamy_ Programming ANsI in C
Chapter 1 : Balagurusamy_ Programming ANsI in C
BUBT
 
Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C
BUBT
 
LET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERSLET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERS
KavyaSharma65
 
PPS Notes Unit 5.pdf
PPS Notes Unit 5.pdfPPS Notes Unit 5.pdf
PPS Notes Unit 5.pdf
Sreedhar Chowdam
 
Chapter 6 Balagurusamy Programming ANSI in c
Chapter 6  Balagurusamy Programming ANSI  in cChapter 6  Balagurusamy Programming ANSI  in c
Chapter 6 Balagurusamy Programming ANSI in c
BUBT
 
The solution manual of programming in ansi by 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 Robin
 
Call by value
Call by valueCall by value
Call by valueDharani G
 
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.
Printing different pyramid patterns of numbers,alphabets and stars using C.
Hazrat Bilal
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
 
String C Programming
String C ProgrammingString C Programming
String C Programming
Prionto Abdullah
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
programming9
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Jayanshu Gundaniya
 
String in c
String in cString in c
String in c
Suneel Dogra
 
pointers
pointerspointers
pointers
teach4uin
 
Storage class in c
Storage class in cStorage class in c
Storage class in c
kash95
 

What's hot (20)

Chapter 2 : Balagurusamy_ Programming ANsI in C
Chapter 2 :  Balagurusamy_ Programming ANsI in CChapter 2 :  Balagurusamy_ Programming ANsI in C
Chapter 2 : Balagurusamy_ Programming ANsI in C
 
Chapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CChapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in C
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
Chapter 1 : Balagurusamy_ Programming ANsI in C
Chapter 1  :  Balagurusamy_ Programming ANsI in C Chapter 1  :  Balagurusamy_ Programming ANsI in C
Chapter 1 : Balagurusamy_ Programming ANsI in C
 
Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C
 
LET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERSLET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERS
 
PPS Notes Unit 5.pdf
PPS Notes Unit 5.pdfPPS Notes Unit 5.pdf
PPS Notes Unit 5.pdf
 
Chapter 6 Balagurusamy Programming ANSI in c
Chapter 6  Balagurusamy Programming ANSI  in cChapter 6  Balagurusamy Programming ANSI  in c
Chapter 6 Balagurusamy Programming ANSI in c
 
The solution manual of programming in ansi by 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
 
Call by value
Call by valueCall by value
Call by value
 
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.
Printing different pyramid patterns of numbers,alphabets and stars using C.
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
String C Programming
String C ProgrammingString C Programming
String C Programming
 
Ansi c
Ansi cAnsi c
Ansi c
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
Function in C program
Function in C programFunction in C program
Function in C program
 
String in c
String in cString in c
String in c
 
pointers
pointerspointers
pointers
 
Storage class in c
Storage class in cStorage class in c
Storage class in c
 

Viewers also liked

Let us c yashwant kanetkar(1)
Let us c   yashwant kanetkar(1)Let us c   yashwant kanetkar(1)
Let us c yashwant kanetkar(1)OMWOMA JACKSON
 
OpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell ScriptingOpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell Scripting
Open Gurukul
 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scripting
vceder
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell ScriptingMustafa Qasim
 
Quick start bash script
Quick start   bash scriptQuick start   bash script
Quick start bash script
Simon Su
 
Basic command ppt
Basic command pptBasic command ppt
Basic command pptRohit Kumar
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting BasicsDr.Ravi
 
Linux command ppt
Linux command pptLinux command ppt
Linux command ppt
kalyanineve
 
Linux ppt
Linux pptLinux ppt
Linux ppt
lincy21
 

Viewers also liked (9)

Let us c yashwant kanetkar(1)
Let us c   yashwant kanetkar(1)Let us c   yashwant kanetkar(1)
Let us c yashwant kanetkar(1)
 
OpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell ScriptingOpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell Scripting
 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scripting
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell Scripting
 
Quick start bash script
Quick start   bash scriptQuick start   bash script
Quick start bash script
 
Basic command ppt
Basic command pptBasic command ppt
Basic command ppt
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
 
Linux command ppt
Linux command pptLinux command ppt
Linux command ppt
 
Linux ppt
Linux pptLinux ppt
Linux ppt
 

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

Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila
 
C programming BY Mazedur
C programming BY MazedurC programming BY Mazedur
C programming BY Mazedur
Mazedurr rahman
 
lets play with "c"..!!! :):)
lets play with "c"..!!! :):)lets play with "c"..!!! :):)
lets play with "c"..!!! :):)
Rupendra Choudhary
 
Simple C programs
Simple C programsSimple C programs
Simple C programs
ab11cs001
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
Nithin Kumar,VVCE, Mysuru
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8alish sha
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8alish sha
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
Syed Ahmed Zaki
 
Cpds lab
Cpds labCpds lab
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
Yi-Hsiu Hsu
 
C basics
C basicsC basics
C basicsMSc CST
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
Arkadeep Dey
 
Najmul
Najmul  Najmul
Najmul
Najmul Ashik
 
9.C Programming
9.C Programming9.C Programming
9.C Programming
Export Promotion Bureau
 
Cquestions
Cquestions Cquestions
Cquestions
mohamed sikander
 
Array Programs.pdf
Array Programs.pdfArray Programs.pdf
Array Programs.pdf
RajKamal557276
 
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTESUnit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
LeahRachael
 

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

Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
C programming BY Mazedur
C programming BY MazedurC programming BY Mazedur
C programming BY Mazedur
 
lets play with "c"..!!! :):)
lets play with "c"..!!! :):)lets play with "c"..!!! :):)
lets play with "c"..!!! :):)
 
Simple C programs
Simple C programsSimple C programs
Simple C programs
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
 
Revision1schema C programming
Revision1schema C programmingRevision1schema C programming
Revision1schema C programming
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
 
C basics
C basicsC basics
C basics
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
Najmul
Najmul  Najmul
Najmul
 
9.C Programming
9.C Programming9.C Programming
9.C Programming
 
Cquestions
Cquestions Cquestions
Cquestions
 
Array Programs.pdf
Array Programs.pdfArray Programs.pdf
Array Programs.pdf
 
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTESUnit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
 

Recently uploaded

The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 

Recently uploaded (20)

The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 

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............