Anda di halaman 1dari 32

Chapter 2: [A] What would be the output of the following programs:

(a)

main( )
{
int a = 300, b, c ;
if ( a >= 400 )
b = 300 ;
c = 200 ;
printf ( "\n%d %d", b, c ) ;
}

output

garbage-value 200

(b)

main( )
{
int a = 500, b, c ;
if ( a >= 400 )
b = 300 ;
c = 200 ;
printf ( "\n%d %d", b, c ) ;
}

output

200 300

(c)

main( )
{
int x = 10, y = 20 ;
if ( x == y ) ;
printf ( "\n%d %d", x, y ) ;
}

output

10 20

(d)

main( )
{
int x = 3, y = 5 ;
if ( x == 3 )
printf ( "\n%d", x ) ;
else ;
printf ( "\n%d", y ) ;
}

output

3
5

(e)

main( )
{
int x = 3 ;
float y = 3.0 ;
if ( x == y )
printf ( "\nx and y are equal" ) ;
else
printf ( "\nx and y are not equal" ) ;
}

output

x and y are equal


(g)

main( )
{
int k = 35 ;
printf ( "\n%d %d %d", k == 35, k = 50, k > 40 ) ;
}

output

0 50 0

(h)

main( )
{
int i = 65 ;
char j = 'A' ;
if ( i == j )
printf ( C is WOW ) ;
else
printf( "C is a headache" ) ;
}

output

C is WOW

(i)

main( )
{
int a = 5, b, c ;
b = a = 15 ;
c = a < 15 ;
printf ( "\na = %d b = %d c = %d", a, b, c ) ;
}

output

a = 15 b = 15 c = 0

(j)

main( )
{
int x = 15 ;
printf ( "\n%d %d %d", x != 15, x = 20, x < 30 ) ;
}

output

1 20 1

Chapter 2: [B] Point out the errors, if any, in the following programs:

(a)

main( )
{
float a = 12.25, b = 12.52 ;
if ( a = b )
printf ( "\na and b are equal" ) ;
}

No syntax error however logical error can occur due to missing relational
operator == inside if condition.

(b)

main( )
{
int j = 10, k = 12 ;
if ( k >= j )
{
{
k=j;
j=k;
}
}
}

No Error

(c)

main( )
{
if ( 'X' < 'x' )
printf ( "\nascii value of X is smaller than that of x" ) ;
}

No Error

(d)

main( )
{
int x = 10 ;
if ( x >= 2 ) then
printf ( "\n%d", x ) ;
}

then is not a keyword in c

(e)

main( )
{
int x = 10 ;
if x >= 2
printf ( "\n%d", x ) ;
}

condition is not enclosed in braces

(f)

main( )
{
int x = 10, y = 15 ;
if ( x % 2 = y % 3 )
printf ( "\nCarpathians" ) ;
}

Relational operator (==) is missing inside condition.

(g)

main( )
{
int x = 30 , y = 40 ;
if ( x == y )
printf( "x is equal to y" ) ;
elseif ( x > y )
printf( "x is greater than y" ) ;
elseif ( x < y )
printf( "x is less than y" ) ;
}

There should be a space between else and if

(h)

main( )
{
int x = 10 ;
if ( x >= 2 ) then
printf ( "\n%d", x ) ;
}

then is not a keyword in c.

(i)

main( )
{
int a, b ;
scanf ( "%d %d",a, b ) ;
if ( a > b ) ;
printf ( "This is a game" ) ;
else
printf ( "You have to play it" ) ;
}

& missing inside scanf

(a) If cost price and selling price of an item is input through the keyboard,
write a program to determine whether the seller has made profit or incurred
loss. Also determine how much profit he made or loss he incurred.

Solution:

#include<stdio.h>
#include<conio.h>
main() {

int cp,sp,rslt;
clrscr();

printf("Please enter the cost p.\rice of the item: \n");


scanf("%d",&cp);

printf("Please enter the selling price of the item: \n");


scanf("%d",&sp);

if(cp>sp) {
rslt=cp-sp;
printf("\nSeller has incurred LOSS of %d rupees.\n",rslt);
}
if(cp<sp)
{
rslt=sp-cp;
printf("\nSeller has made PROFIT of %d rupees.\n",rslt);
}

getch();
return 0;

------------------------------------------------------------------------------------------------------------

(b) Any integer is input through the keyboard. Write a program to find out
whether it is an odd number or even number.

Solution:

#include<stdio.h>
#include<conio.h>

main() {

int i;
clrscr();

printf("Please enter the number: \n");


scanf("%d",&i);

if(i%2==
printf("\nThe number is EVEN.\n");

else
printf("\nThe number is ODD.\n");

getch();
return 0;

------------------------------------------------------------------------------------------------------------
(c) Any year is input through the keyboard. Write a program to determine
whether the year is a leap year or not
(Hint: Use the % (modulus) operator)

Solution:

#include<stdio.h>
#include<conio.h>

main() {

int yr;
clrscr();

printf("Please enter the year: \n");


scanf("%d",&yr);

if(yr%4==0)
printf("\nThe year is a LEAP YEAR.\n");

else
printf("\nThe Year is NOT A LEAP YEAR.\n");

getch();
return 0;

------------------------------------------------------------------------------------------------------------

(d) According to the Gregorian calendar, it was Monday on the date


01/01/1900. If any year is input through the keyboard write a program to find
out what is the day on 1st January of this year.
Solution:

#include<stdio.h>
#include<conio.h>

main() {

int month=1,year,a,day=1;

clrscr();
printf("Enter year: ");
scanf("%d",&year);

/* this is a general purpose formula to calculate first day */

a=(14-month)/12;
year=year-a;
month=month+12*a-2;

day=(day+year+(year/4)-(year/100)+(year/400)+((31*month)/12)) % 7;

/* determining the position to print the first day in the calender */

printf("\n\nFirst day is ");

if(day==0)
printf("Sunday");

else if(day==1)
printf("Monday");

else if(day==2)
printf("Tuesday");

else if(day==3)
printf("Wednesday");

else if(day==4)
printf("Thursday");

else if(day==5)
printf("Friday");

else if(day==6)
printf("Saturday");

getch();
return 0;

}
------------------------------------------------------------------------------------------------------------

(e) A five-digit number is entered through the keyboard. Write a program to


obtain the reversed number and to determine whether the original and
reversed numbers are equal or not.

Solution:

#include<stdio.h>
#include<conio.h>

main() {

long i,d1,d2,d3,d4,d5,a,b,c,d,n_num;
clrscr();

printf("Please enter a five digit number: \n");


scanf("%ld",&i);

d1=i/10000;
a=i%10000;

d2=a/1000;
b=a%1000;

d3=b/100;
c=b%100;

d4=c/10;
d=c%10;

d5=d/1;

n_num=(d5*10000)+(d4*1000)+(d3*100)+(d2*10)+(d1*1);

printf("\nThe REVERSED NUMBER is %ld \n",n_num);

if(n_num==i){
printf("\nboth numbers are SAME.\n");
}
else {
printf("\nboth number are NOT SAME.\n");
}
getch();
return 0;

------------------------------------------------------------------------------------------------------------

(f) If the ages of Ram, Shyam and Ajay are input through the keyboard, write a
program to determine the youngest of the three.

Solution:

#include<stdio.h>
#include<conio.h>

main() {

int ram,shyam,ajay;
clrscr();

printf("Please enter the age of RAM: ");


scanf("%d",&ram);

printf("\nPlease enter the age of SHYAM: ");


scanf("%d",&shyam);

printf("\nPlease enter the age or AJAY: ");


scanf("%d",&ajay);

if(ram<shyam)
{
if(ram<ajay) {
printf("\nRam is the YOUNGEST.\n");
}
}
if(shyam<ram)
{
if(shyam<ajay) {
printf("\nShyam is the YOUNGEST.\n");
}
}
if(ajay<ram) {
if(ajay<shyam) {
printf("\nAjay is the YOUNGEST.\n");
}
}

getch();
return 0;

------------------------------------------------------------------------------------------------------------

(g)Write a program to check whether a triangle is valid or not, when the three
angles of the triangle are entered through the keyboard. A triangle is valid if
the sum of all the three angles is equal to 180 degrees.

Solution:

#include<stdio.h>
#include<conio.h>
main() {

int a1,a2,a3;
clrscr();

printf("Please enter the first angle: \n");


scanf("%d",&a1);

printf("\nPlease enter the second angle: \n");


scanf("%d",&a2);

printf("\nPlease enter the third angle: \n");


scanf("%d",&a3);

if(a1+a2+a3==180) {
printf("\nThe triangle is VALID.\n");
}

else {
printf("\nThe triangle is NOT VALID.\n");
}
getch();
return 0;

------------------------------------------------------------------------------------------------------------

(h) Find the absolute value of a number entered through the keyboard.

Solution:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main() {

int i,av;
clrscr();

printf("Please enter any number: ");


scanf("%d",&i);

av=abs(i);

/* abs(); is a standard function to calculate absolute value.\


this function has been defined in <stdlib.h> library. */

printf("Absolute value = %d",av);

getch();
return 0;

------------------------------------------------------------------------------------------------------------

(i) Given the length and breadth of a rectangle, write a program to find
whether the area of the rectangle is greater than its perimeter. For example,
the area of the rectangle with length = 5 and breadth = 4 is greater than its
perimeter.
Solution:

#include<stdio.h>
#include<conio.h>
main() {

int l,b,area,peri;
clrscr();

printf("Please enter the length and bredth of a rectangle: \n");


scanf("%d%d",&l,&b);

area=l*b;
peri=2*(l+b);

if(area>peri) {
printf("\nThe Area of Rectangle is GREATER then it's perimeter.\n");
}

else {
printf("\nThe area of Rectangle is NOT GREATER then it's perimeter.\n");
}

getch();
return 0;

------------------------------------------------------------------------------------------------------------

(j) Given three points (x1, y1), (x2, y2) and (x3, y3), write a program to check
if all the three points fall on one straight line.

Solution:

#include<stdio.h>
#include<conio.h>
main() {

int x1,y1,x2,y2,x3,y3,curve1,curve2;
clrscr();

printf("Please enter the values of Three points: ");


printf("\n(x1,y1):\n");
scanf("%d%d",&x1,&y1);
printf("\n(x2,y2):\n");
scanf("%d%d",&x2,&y2);
printf("\n(x3,y3):\n");
scanf("%d%d",&x3,&y3);

curve1=(x2-x1)/(y2-y1);
curve2=(x3-x2)/(y3-y2);

if(curve1==curve2)
printf("\nAll three points fall on one straight line.\n");
else
printf("\nThese three points do not fall on one straight line.\n");

getch();
return 0;

------------------------------------------------------------------------------------------------------------

(k) Given the coordinates (x, y) of a center of a circle and its radius, write a
program which will determine whether a point lies inside the circle, on the
circle or outside the circle.
(Hint: Use sqrt( ) and pow( ) functions)

Solution:

#include<stdio.h>
#include<conio.h>
#include<math.h>
main() {

int x,y,x_,y_,r,point;
clrscr();

printf("Please enter the coordinates of center: \n");


printf("(x,y): ");
scanf("%d%d",&x,&y);
printf("\nPlease enter the radius of circle: \n");
scanf("%d",&r);
printf("\nPlease enter the point to check: \n");
printf("(x`,y`): ");
scanf("%d%d",&x_,&y_);

point=pow(x_,2)+pow(y_,2)+pow(x,2)+pow(y,2)-(2*x_*x)-(2*y_*y)-pow(r,2);

if(point<0)
printf("\nThe point lies inside the circle.\n");

if(point>0)
printf("\nThe point lies outside the circle.\n");

if(point==0)
printf("\nThe point lies on the circle.\n");

getch();
return 0;

------------------------------------------------------------------------------------------------------------

(l) Given a point (x, y), write a program to find out if it lies on the x-axis, y-
axis or at the origin, viz. (0, 0).

Solution:

#include<stdio.h>
#include<conio.h>
main() {

int x,y;
clrscr();

printf("Please enter points\n");


printf("(x,y): \n");
scanf("%d%d",&x,&y);

if(x==0&&y!=0) {
printf("\nThe point lies on Y AXIS.\n");
}

else if(x!=0&&y==0) {
printf("\nThe point lies on X AXIS.\n");
}

else if(x==0&&y==0) {
printf("\nThe point lies at the origin.\n");
}

else {
printf("\nThe point doesn't lie on any axis or at origin.\n");
}

getch();
return 0;

___________________________________________________________________

Exercise [F]

(a) Any year is entered through the keyboard, write a program to determine
whether the year is leap or not. Use the logical operators && and ||.

Solution:

#include<stdio.h>
#include<conio.h>
main() {

int yr;
clrscr();

printf("Please enter the year: ");


scanf("%d",&yr);

if(yr%4==0 || !((yr%4)>0) )
printf("\nThe is a LEAP YEAR.\n");

else
printf("\nThis is NOT A LEAP YEAR.\n");
getch();
return 0;

------------------------------------------------------------------------------------------------------------

(b) Any character is entered through the keyboard, write a program to


determine whether the character entered is a capital letter, a small case
letter, a digit or a special symbol.
The following table shows the range of ASCII values for various characters.

The following table shows the range of ASCII values for various characters.
Characters

Characters ASCII values

AZ 65 - 90
az 97 - 122
09 48 - 57
special symbols 0 - 47, 58 - 64, 91 - 96, 123 - 127

Solution:

#include<stdio.h>
#include<conio.h>
main() {

char ch;
clrscr();

printf("Please enter any character:");


scanf("%c",&ch);

if(ch>=65&&ch<=90)
printf("\nThe character you entered is a CAPITAL LETTER.\n");

if(ch>=97&&ch<=122)
printf("\nThe character you entered is a SMALL LETTER.\n");

if(ch>=48&&ch<=57)
printf("\nThe character you entered is a DIGIT.\n");
if(ch>=0&&ch<=47 || ch>=58&&ch<=64 || ch>=91&&ch<=96 ||
ch>=123&&ch<=127)
printf("\nThe character you entered is a SPECIAL SYMBOL.\n");

getch();

return 0;

------------------------------------------------------------------------------------------------------------

(c) An Insurance company follows following rules to calculate premium.


(1) If a persons health is excellent and the person is between 25 and 35
years of age and lives in a city and is a male then the premium is Rs. 4 per
thousand and his policy amount cannot exceed Rs. 2 lakhs.
(2) If a person satisfies all the above conditions except that the sex is female
then the premium is Rs. 3 per thousand and her policy amount cannot exceed
Rs. 1 lakh.
(3) If a persons health is poor and the person is between 25 and 35 years of
age and lives in a village and is a male then the premium is Rs. 6 per
thousand and his policy cannot exceed Rs. 10,000.
(4) In all other cases the person is not insured.

Write a program to output whether the person should be insured or not,


his/her premium rate and maximum amoun t for which he/she can be insured.

Solution:

#include<stdio.h>
#include<conio.h>
main() {

int age,premium,p_a,hlt,rsdnc,sex;
long amount;
clrscr();

printf("Please tell the HEALTH of the person\n(1 for excellent or 2 for poor)
:\n");
scanf("%d",&hlt);

printf("Please tell the AGE of the person: \n");


scanf("%d",&age);

printf("Please tell the residence\n(1 for city or 2 for village) : \n");


scanf("%d",&rsdnc);

printf("Please tell you sex\n(1 for male or 2 for female) : \n");


scanf("%d",&sex);

if(hlt==1 && age>=25&&age<=35 && rsdnc==1 && sex==1) {


premium=4;
amount=200000;

printf("\nThis person is insured.\n");


printf("Premium rate = %d rupees per thousand.\n",premium);
printf("Person can be insured for maximum amount of %ld
rupees.\n",amount);
}

else if(hlt==1||hlt==2 && age>=25&&age<=35 && rsdnc==1||rsdnc==2 &&


sex==2) {
premium=3;
amount=100000;

printf("\nThis person is insured.\n");


printf("Premium rate = %d rupees per thousand.\n",premium);
printf("Person can be insured for maximum amount of %ld
rupees.\n",amount);
}

else if(hlt==2 && age>=25&&age<=35 && rsdnc==2 && sex==1) {


premium=6;
amount=10000;

printf("\nThis person is insured.\n");


printf("Premium rate is = %d rupees per thousand.\n",premium);
printf("Person can be insured for maximum amount of %ld
rupees.\n",amount);
}

else {
printf("\nThis person cannot be insured.\n");
}
getch();
return 0;

------------------------------------------------------------------------------------------------------------

(d) A certain grade of steel is graded according to the following conditions:


(i) Hardness must be greater than 50
(ii) Carbon content must be less than 0.7
(iii) Tensile strength must be greater than 5600

The grades are as follows:

Grade is 10 if all three conditions are met


Grade is 9 if conditions (i) and (ii) are met
Grade is 8 if conditions (ii) and (iii) are met
Grade is 7 if conditions (i) and (iii) are met
Grade is 6 if only one condition is met
Grade is 5 if none of the conditions are met

Write a program, which will require the user to give values of hardness,
carbon content and tensile strength of the steel under consideration and
output the grade of the steel.

Solution:

#include<stdio.h>
#include<conio.h>
main() {

int hdn,tnsl,hardness=50,tensile_strength=5600;

float c,carbon_content=0.7;

clrscr();

printf("Please enter the Hardness: \n");


scanf("%d",&hdn);

printf("\nPlease enter the Carbon content: \n");


scanf("%f",&c);
printf("\nPlease enter the Tensile Strength: \n");
scanf("%d",&tnsl);

if(hdn>hardness && c<carbon_content && tnsl>tensile_strength)


printf("\nThe steel has been Graded 10.\n");

else if(hdn>hardness && c<carbon_content)


printf("\nThe steel has been Graded 9.\n");

else if(c<carbon_content && tnsl>tensile_strength)


printf("\nThe steel has been Graded 8.\n");

else if(hdn>hardness && tnsl>tensile_strength)


printf("\nThe steel has been Graded 7.\n");

else if(hdn>hardness || c<carbon_content || tnsl>tensile_strength)


printf("\nThe steel has been Graded 6.\n");

else
printf("\nThe steel has been Graded 5.\n");

getch();

return 0;

------------------------------------------------------------------------------------------------------------

(e) A library charges a fine for every book returned late. For first 5 days the
fine is 50 paise, for 6-10 days fine is one rupee and above 10 days fine is 5
rupees. If you return the book after 30 days your membership will be
cancelled. Write a program to accept the number of days the member is late
to return the book and display the fine or the appropriate message.

Solution:

#include<stdio.h>
#include<conio.h>
main() {
int days;
clrscr();

printf("Please enter the days of being late in returning the book:\n");


scanf("%d",&days);

if(days<=5)
printf("\nYou have been fined for 50 paise.\n");

if(days>=6&&days<=10)
printf("\nYou have been fined for 1 rupee.\n");

if(days>10&&days<30)
printf("\nYou have been fined for 5 rupee.\n");

if(days>=30)
printf("\nYour membership has been cancelled.\n");

getch();
return 0;

------------------------------------------------------------------------------------------------------------

(f) If the three sides of a triangle are entered through the keyboard, write a
program to check whether the triangle is valid or not. The triangle is valid if
the sum of two sides is greater than the largest of the three sides.

Solution:

#include<stdio.h>
#include<conio.h>
main() {

int s1,s2,s3,ls,ss1,ss2;
clrscr();

printf("Please enter the three sides of a triangle: \n");


scanf("%d%d%d",&s1,&s2,&s3);

if(s1>s2&&s1>s3){
ls=s1;
ss1=s2;
ss2=s3;
}
if(s2>s1&&s2>s3) {
ls=s2;
ss1=s1;
ss2=s3;
}
if(s3>s1&&s3>s2) {
ls=s3;
ss1=s1;
ss2=s2;
}

if((ss1+ss2)>ls) {
printf("\nThe Triangle is VALID.\n");
}
else {
printf("The triangle is NOT VALID.\n");
}

getch();
return 0;

------------------------------------------------------------------------------------------------------------

(g) If the three sides of a triangle are entered through the keyboard, write a
program to check whether the triangle is isosceles, equilateral, scalene or
right angled triangle.

Solution:

#include<stdio.h>
#include<conio.h>

main() {

int s1,s2,s3,largest,s_1,s_2;
clrscr();

printf("Please enter the three sides of a triangle: \n");


scanf("%d %d %d",&s1,&s2,&s3);
if(s1==s2&&s1!=s3||s1==s3&&s1!=s2 || s2==s3&&s2!=s1||s2==s1&&s2!=s3 ||
s3==s1&&s3!=s2||s3==s2&&s3!=s1){
printf("The Triangle is ISOSCELES.\n");
}

if(s1==s2&&s2==s3 || s2==s1&&s2==s3 || s3==s1&&s3==s2){


printf("The Triangle is EQUILATERAL.\n");
}

if(s1!=s2&&s2!=s3 || s2!=s1&&s1!=s3 || s3!=s1&&s1!=s2){


printf("The Triangle is SCALENE.\n");
}

if(s1>s2&&s1>s3){
largest=s1;
s_1=s2;
s2=s3;
}

if(s2>s1&&s2>s3){
largest=s2;
s_1=s1;
s_2=s3;
}

if(s3>s1&&s3>s2){
largest=s3;
s_1=s1;
s_2=s2;
}

if(pow(largest,2)==pow(s_1,2)+pow(s_2,2))
printf("The Triangle is RIGHT ANGLED.\n");

getch();
return 0;
}

------------------------------------------------------------------------------------------------------------

(h) In a company, worker efficiency is determined on the basis of the time


required for a worker to complete a particular job. If the time taken by the
worker is between 2 3 hours, then the worker is said to be highly efficient. If
the time required by the worker is between 3 4 hours, then the worker is
ordered to improve speed. If the time taken is between 4 5 hours, the
worker is given training to improve his speed, and if the time taken by the
worker is more than 5 hours, then the worker has to leave the company. If the
time taken by the worker is input through the keyboard, find the efficiency of
the worker.

Solution:

#include<stdio.h>
#include<conio.h>
main() {

int hrs;
clrscr();

printf("Please enter the hours of completing job: ");


scanf("%d",&hrs);

if(hrs>=2 && hrs<=3)


printf("\nThe worker is HIGHLY EFFICIENT.\n");

if(hrs>=3 && hrs<=4)


printf("\nThe worker is ordered to IMPROVE SPEED.\n");

if(hrs>=4 && hrs<= 5)


printf("\nThe worker should be given TRAINING TO IMPROVE SPEED.\n");

if(hrs>5)
printf("\nThe worker should be asked to leave the company.\n");

else
printf("The worker is HIGHLY EFFICIENT.\n");

getch();
return 0;

------------------------------------------------------------------------------------------------------------
(i) A university has the following rules for a student to qualify for a degree
with A as the main subject and B as the subsidiary subject:
(a) He should get 55 percent or more in A and 45 percent or more in B.
(b) If he gets than 55 percent in A he should get 55 percent or more in B.
However, he should get at least 45 percent in A.
(c) If he gets less than 45 percent in B and 65 percent or more in A he is
allowed to reappear in an examination in B to qualify.
(d) In all other cases he is declared to have failed.

Write a program to receive marks in A and B and Output whether the student
has passed, failed or is allowed to reappear in B.

Solution:

#include<stdio.h>
#include<conio.h>
main() {

int a,b;
clrscr();

printf("Please enter the marks in subject A: \n");


scanf("%d",&a);

printf("\nPlease enter the marks in subject B: \n");


scanf("%d",&b);

if(a>=55 && b>=45) {


printf("Student is qualified for the degree.\n");
}

else if(a==55 && b>=55 || a==55 && b>=45) {


printf("Student is qualified for the degree.\n");
}

else if(a>=65 && b<45) {


printf("Student is allowed to reappear in the exam of B to qualify.\n");
}

else {
printf("Student has failed.\n");
}
getch();
return 0;

------------------------------------------------------------------------------------------------------------

(j) The policy followed by a company to process customer orders is given by


the following rules:

(a) If a customer order is less than or equal to that in stock and has credit is
OK, supply has requirement.
(b) If has credit is not OK do not supply. Send him intimation.
(c) If has credit is Ok but the item in stock is less than has order, supply what
is in stock. Intimate to him data the balance will be shipped.

Write a C program to implement the company policy.

Solution:

#include<stdio.h>
#include<conio.h>
main() {

int stock,credit,order;
clrscr();

printf("Please enter the stock available: ");


scanf("%d",&stock);
printf("\nPlease enter the order: ");
scanf("%d",&order);
printf("\nPlease enter the credit: ");
scanf("%d",&credit);

if(credit!=0&&order<=stock) {
printf("\nSupply\n");
}

else if(credit!=0&&order>stock) {
printf("\nAvailable items will be supplied.\n");
}
else {
printf("\nNo supply.\n");
}

getch();
return 0;

}
______________________________________________________________________

Exercise [J]

(a) Using conditional operators determine:

(1) Whether the character entered through the keyboard is a lower case
alphabet or not.
(2) Whether a character entered through the keyboard is a special symbol or
not.

Solution:

#include<stdio.h>
#include<conio.h>

char main() {

char ch;
clrscr();

printf("Please enter a character: \n");


scanf("%c",&ch);

if(ch>=97 && ch<=122) {


printf("\n[A] This character is a SMALL CASE alphabet.\n");
}

else {
printf("\n[A] This character is NOT A SMALL CASE alphabet.\n");
}
if(ch>=0&&ch<=47||ch>=58&&ch<=64||ch>=91&&ch<=96||ch>=123&&ch<=127)
{
printf("\n[B] This character is a SPECIAL SYMBOL.\n");
}

else{
printf("\n[B] This character is NOT A SPECIAL SYMBOL.\n");
}

getch();
return 0;

------------------------------------------------------------------------------------------------------------

(b) Write a program using conditional operators to determine whether a year


entered through the keyboard is a leap year or not.

Solution:

#include<stdio.h>
#include<conio.h>
main () {

int yr;
clrscr();

printf("Please enter the year: \n");


scanf("%d",&yr);

if(yr%4!=0)
printf("\nThis is NOT A LEAP YEAR.\n");

else
printf("\nThis is a LEAP YEAR.\n");

getch();
return 0;
}

------------------------------------------------------------------------------------------------------------

(c) Write a program to find the greatest of the three numbers entered through
the keyboard using conditional operators.

Solution:

#include<stdio.h>
#include<conio.h>

main() {

int n1,n2,n3;
clrscr();

printf("\nPlease enter 3 numbers: \n");


scanf("%d %d %d",&n1,&n2,&n3);

if(n1>n2 && n1>n3) {


printf("\n%d is the greatest number of the three numbers.\n",n1);
}

else if(n2>n1 && n2>n3) {


printf("\n%d is the greatest number of the three numbers.\n",n2);
}

else if(n3>n2 && n3>n1) {


printf("\n%d is the greatest number of the three numbers.\n",n3);
}

else {
printf("\nwrong input!\n");
}

getch();
return 0;