Showing posts with label let us c programs and thier answers. Show all posts
Showing posts with label let us c programs and thier answers. Show all posts
Sunday, 24 July 2011
[chapter 2 part 3]let us c [SOLVED]
[J]([k]in 4th edition) Attempt the following:
(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.
click here for Answer!!!
(b) Write a program using conditional operators to determine whether a year entered through the keyboard is a leap year or not.
click here for Answer!!!
(c) Write a program to find the greatest of the three numbers entered through the keyboard using conditional operators.
click here for Answer!!!
Saturday, 23 July 2011
[chapter 1]let us c [SOLVED]
[H]write C programs for the following:
(a)Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.
click here for Answer!!!
Answer:
main()
{
float bs,gs;
printf("\nInput Basic Salary");
scanf("%f",&bs);
gs=bs*(16.0/10.0);
printf("\nGross Salary is %f",gs);
}
(b)The distance between two cities (in km.) is input through the keyboard. Write a program to convert and print this distance in meters, feet, inches and centimeters.
click here for Answer!!!
Answer :
main()
{
float distance,distancem,distancefeet,distanceinches,distancecm;
printf("\nInput distance in km");
scanf("%f",&distance);
distancem= distance*1000.0;
distancefeet= distancem*3.2808;
distanceinches= (distance*100000.0)/2.54;
distancecm = distance*100000.0;
printf("\n Distance in metres = %fm\n Distance in feet = %fft\n Distance in inches = %finches\n Distance in cm = %fcm",distancem,distancefeet,distanceinches,distancecm);
}
(c) If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.
click here for Answer!!!
main()
{
float a,b,c,d,e,t,am,pm;
printf("\nInput the 5 test marks followed by total obtainable marks");
scanf("%f%f%f%f%f%f",&a,&b,&c,&d,&e,&t);
am=(a+b+c+d+e)/5;
pm=(am/t)*100.0;
printf("\nThe aggregate marks is %f\nThe percentage marks is %f",am,pm);
}
(d)Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert this temperature into Centigrade degrees.
click here for Answer!!!
Answer:
main()
{
float c,f;
printf("\nInput the temperate(Fahrenheit)");
scanf("%f",&f);
c= (f-32)*(100.0/180.0);
printf("\nThe temperature in Celsius is %f",c);
}
(e) The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle.
click here for Answer!!!
void main()
{
float l,b,r,arear,perimeterr,areac,perimeterc;
printf("\nInput the length and breadth of rectangle and radius of circle respectively");
scanf("%f%f%f",&l,&b,&r);
arear=l*b;
perimeterr=2*l+2*b;
areac=3.141592654*r*r;
perimeterc=2*3.141592654*r;
printf("\nThe area of rectangle is %f\nThe perimeter of rectangle is %f\nThe area of circle is %f\nThe circumference of the circle is %f",arear,perimeterr,areac,perimeterc);
}
(f) Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D.
click here for Answer!!!
void main()
{
float c,d,e,f;
printf("\nInput values of C and D");
scanf("%f%f",&c,&d);
e=c;
f=d;
c=f;
d=e;
printf("\nNow C is %f\nD is %f",c,d);
}
(g) If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits.
(Hint: Use the modulus operator ‘%’)
click here for Answer!!!
Answer:
void main()
{
float number,a,b,c,d,e;
int a1,b1,c1,d1,e1,t;
printf("\nKey in a five digit number");
scanf("%f",&number);
a=number/10000.0;
a1=a/1;
b=(number-(a1*10000.0))/1000;
b1=b/1;
c=(number-(a1*10000.0)-(b1*1000))/100;
c1=c/1;
d=(number-(a1*10000.0)-(b1*1000)-(c1*100))/10;
d1=d/1;
e=(number-(a1*10000.0)-(b1*1000)-(c1*100)-(d1*10))/1;
e1=e/1;
t=a1+b1+c1+d1+e1;
printf("\nThe sum of the five digits is %d",t);
}
(h) If a five-digit number is input through the keyboard, write a program to reverse the number.
click here for Answer!!!
Answer:
void main()
{
float a,b,c,d,e,t,a2,b2,c2,d2,e2,s;
int a1,b1,c1,d1,e1;
printf("\nInput a 5 digit number");
scanf("%f",&t);
a=t/10000.0;
a1=a;
b=(t-(a1*10000.0))/1000;
b1=b;
c=(t-(a1*10000.0)-(b1*1000))/100;
c1=c;
d=(t-(a1*10000.0)-(b1*1000)-(c1*100))/10;
d1=d;
e=t-(a1*10000.0)-(b1*1000)-(c1*100)-(d1*10);
e1=e;
a2=e1*10000.0;
b2=d1*1000.0;
c2=c1*100.0;
d2=b1*10.0;
e2=a1*1.0;
s=a2+b2+c2+d2+e2;
printf("\nThe required result is %f",s);
}
(i) If a four-digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of this number.
click here for Answer!!!
Answer:
void main()
{
float a,d,t;
int a1,d1,t1,u;
printf("\nInput a 4 digit number");
scanf("%f",&t);
a=t/1000.0;
u=t;
a1=a;
d=u%10;
d1=d;
t1=a1+d1;
printf("\nThe Sum f %d",t1);
}
(k) A cashier has currency notes of denominations 10, 50 and 100. If the amount to be withdrawn is input through the keyboard in hundreds, find the total number of currency notes of each denomination the cashier will have to give to the withdrawer.
click here for Answer!!!
Answer:
Note: So if its $900 the input value is 9 and if its $1970 input is 19.7
void main()
{
float t,_10,_50,_100;
int _11,_51,_101;
printf("\nInput notes in hundreds");
scanf("%f",&t);
_100=t/100;
_101=_100;
_50=(t-_101*100.0)/50;
_51=_50;
_10=(t-(_101*100.0+_51*50.0))/10;
_11=_10;
printf("\n_100 is %f\n_101 is %d",_100,_101);
printf("\nThe no of $100 notes is %d\nThe no of $50 notes is %d\nThe no of $10 notes is %d",_101,_51,_11);
}
(l) If the total selling price of 15 items and the total profit earned on them is input through the keyboard, write a program to find the cost price of one item.
click here for Answer!!!
Answer:
void main()
{
float sp,tp,cp,cps;
printf("\nInput the total selling price of 15 itmes and total profit earned respectively");
scanf("%f%f",&sp,&tp);
cps=sp-tp;
printf("\nThe cost price of one item is %f",cp=cps/15.0);
}
(m) If a five-digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example if the number that is input is 12391 then the output should be displayed as 23402.
click here for Answer!!!
void main()
{
float s,t;
int a,b,c,d,e;
printf("\nInput a 5 digit number");
scanf("%f",&t);
a=t/10000.0;
b=(t-(a*10000.0))/1000;
c=(t-(a*10000.0)-(b*1000))/100;
d=(t-(a*10000.0)-(b*1000)-(c*100))/10;
e=(t-(a*10000.0)-(b*1000)-(c*100)-(d*10))/1;
a+=1;
b+=1;
c+=1;
d+=1;
e+=1;
if (a==10)
a=0;
if (b==10)
b=0;
if (c==10)
c=0;
if (d==10)
d=0;
if (e==10)
e=0;
s=(a*10000.0)+(b*1000.0)+(c*100.0)+(d*10.0)+(e);
printf("\nThe required result is %f",s);
}
Subscribe to:
Posts (Atom)