[F]([G] in 4th edition ) Attempt the following:
(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 ||.
click here for Answer!!!
Answer:
void main()
{
int year;
printf("Enter year: ");
scanf("%d",&year);
if((year%4)==0&&(year%100)!=0||(year%400)==0)
printf("%d is leap year",year); // reason at Note:1
else
printf("%d is not leap year",year);
}
(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.
characters ascii values
A-Z 65 – 90
a-z 97 – 122
0-9 48 – 57
special symbols 0 - 47, 58 - 64, 91 - 96, 123 - 127
click here for Answer!!!
Answer:
Void main()
{
char ch;
printf("Enter any character ");
scanf("%c",&ch);
if(ch>=65&&ch<=90) printf("Character entered is Capital"); else if(ch>=97&&ch<=122) printf("Character entered is small"); else if(ch>=48&&ch<=57) printf("character is digit"); else printf("Character is special symbols"); }
(c) An Insurance company follows following rules to calculate premium.
(1) If a person’s 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 person’s 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 amount for which he/she can be insured.
click here for Answer!!!
Answer:
Void main()
{
char health,sex,area;
int age;
printf("Enter health condn(e/p),sex(m/f),area(c/v)&age\n");
scanf("%c %c %c %d",&health,&sex,&area,&age);
if(health=='e'&&sex=='m'&&area=='c'&&age>=25&&age<=35) { printf("\nInsured\n"); printf("\nPremium rate = Rs. 4 per 1,000\n"); printf("\nmaximum policy amount = Rs. 2,00,000"); } else if(health=='e'&&sex=='f'&&area=='c'&&age>=25&&age<=35) { printf("\nInsured"); printf("\nPremium Rate = Rs. 3 per 1000"); printf("\nMaximum policy amount = Rs. 1,00,000"); } else if(health=='p'&&sex=='m'&&area=='v'&&age>=25&&age<=35) { printf("\nInsured"); printf("\nPremium Rate = Rs. 6 per 1,000"); printf("\nMaximum policy amount = Rs. 10,000"); } else printf("\nYou cannot be insured\n"); }
(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.
click here for Answer!!!
Answer:
void main()
{
float hardness,carbon,tensile;
int grade;
printf("Enter hardness,carbon content & tensile strength:");
scanf("%f %f %f",&hardness,&carbon,&tensile);
if(hardness>0&&carbon>=0&&tensile>0)
{
if(!(hardness>50&&carbon<0.7&&tensile>5600))
grade=5;
if(hardness>50||carbon<0.7||tensile>5600)
grade=6;
if(hardness>50&&tensile>5600)
grade=7;
if(carbon<0.7&&tensile>5600)
grade=8;
if(hardness>50&&carbon<0.7) grade=9; if(hardness>50&&carbon<0.7&&tensile>5600)
grade=10;
printf("\nGrade = %d",grade);
}
else
printf("\nYour entry is invalid");
}
(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.
click here for Answer!!!
Answer:
void main()
{
int days;
float fine;
printf("Number of days late: ");
scanf("%d",&days);
if(days<=30) { if(days<=5) fine=0.5; else if(days>5&&days<=10) fine=1.0; else if(days>10&&days<=30) fine=5.0; printf("you have to pay fine of Rs %f",fine); } else printf("Your membership has been canceled"); }
(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.
click here for Answer!!!
Answer:
void main()
{
int side1,side2,side3;
printf("Enter 3 sides of triangle: ");
scanf("%d%d%d",&side1,&side2,&side3);
if(side1>side2&&side1>side3)//case for side1 greater
{
if(side1<(side2+side3))//long side is side1 { printf("\ntriangle is valid "); } else printf("\n triangle is invalid"); } if(side2>side1&&side2>side3) //case for side2 greater
{
if(side2<(side1+side3)) { printf("\ntriangle is valid "); } else printf("\n triangle is invalid"); } if(side3>side1&&side3>side2) //case for side3 greater
{
if(side3<(side1+side2)) { printf("\ntriangle is valid "); } else printf("\n triangle is invalid"); } }
(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.
click here for Answer!!!
Answer:
void main()
{
int side1,side2,side3,h;
printf("Enter 3 sides of triangle: ");
scanf("%d%d%d",&side1,&side2,&side3);
if(side1==side2&&side1==side3)//for equilateral
{
printf("\nEquilateral triangle ");
}
//for isosceles
else if(side1==side2||side2==side3||side1==side3)
{
printf("\ntriangle is isoscelses ");
}
//for scalene
else if(side1!=side2&&side2!=side3&&side1!=side3)
printf("\n triangle is scalene");
if(side1>side2&&side1>side3) //case for side1 greater
{
h=sqrt(side2*side2+side3*side3);
//note1: see about pythagoream theorem
if(side1==h)//Pythagoream Theorem condition check
printf("\ntriangle is right angled triangle");
else
printf("\ntriangle is not right angled triangle");
}
else if(side2>side1&&side2>side3) //case for side2 greater
{
h=sqrt(side1*side1+side3*side3);
if(side2==h)//Pythagoream Theorem condition check
printf("\ntriangle is right angled triangle");
else
printf("\ntriangle is not right angled triangle");
}
else if(side3>side1&&side3>side2) //case for side3 greater
{
h=sqrt(side1*side1+side2*side2);
if(side3==h)//Pythagoream Theorem condition check
printf("\ntriangle is right angled triangle");
else
printf("\ntriangle is not right angled triangle");
}
}
(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.
click here for Answer!!!
Answer:
void main()
{
float time;
printf("Enter time taken to complete work: ");
scanf("%f",&time);
if(time>=2&&time<=3) printf("\nWorker is highly efficient"); else if(time>3&&time<=4) printf("\nWorker is ordered to improve speed"); else if(time>4&&time<=5) printf("\nWorker has to given a training"); if(time>5)
printf("Worker has to leave the company");
}
(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 less 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.
click here for Answer!!!
Answer:
void main()
{
int pera,perb;
printf("Enter percent in A and B: ");
scanf("%d%d",&pera,&perb);
if(pera>=55&&perb>=45)
printf("\n Student is passed");
else if(pera>=45&&pera<55&&perb>=55)
printf("\n Student is passed");
else if(perb<45&&pera>=65)
printf("Student is allowed to reappear in an exam");
else
printf("Student is failed");
}
(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
click here for Answer!!!
Answer:
void main()
{
int stock=12,your_stk,word;
char credit;
printf("Enter the orders: ");
scanf("%d",&your_stk);
fflush(stdin);//to remove enter as buffer see note1
printf("\n Has credit or not (y/n)");
scanf("%c",&credit);
if(your_stk<=stock&&credit=='y') printf("\norder will be supplied"); else if(your_stk<=stock&&credit=='n') printf("\norder can't be supplied.credit required"); else if(your_stk>stock&&credit=='y')
printf("\n12 will be supplied remaining will be later");
}
exellent solutions are available
ReplyDeletereally helpful!
ReplyDeletethank you its very nice and too helpfull
ReplyDeleteWrite a program that can fill an array of type integer size 8 with numbers in Binary format and then generates the output in Decimal, i.e. If the input is 00001110 the out put will be 14.how i do this
ReplyDelete#include
Delete#include
#include
void main(void)
{clrscr();
int num,n=1,last_digit=0,sum=0;
cout<<"\nEnter Binary Number : ";
cin>>num;
while(num>0)
{last_digit=num%10;
sum=sum+last_digit*n;
num=num/10;
n=n*2;
}
cout<<"\nDecimal Number : "<<sum;
getch();
}
Programme 1 in JAVA============
ReplyDeletepublic class LeapuseOperater {
public static void main(String[] args)
{
int year = 1989;
if (year%400 == 0 || (year%100 != 0 && year%4 == 0))
{
System.out.println("This year is a leap year");
}
else
{
System.out.println("This is not a leap year");
}
}
}
Programe 2 in java===========
ReplyDeletepublic class DemoPrint {
public static void main(String[] args)
{
char ch = '7';
int position= ch;
if((ch>=0 && ch<=47) || (ch>=58 && ch<=64) ||(ch>=91 && ch<=96) || (ch>=123 && ch<=127))
{
System.out.print("Special Symbol: "+position);
}
if(ch>=48 && ch<=57)
{
System.out.print("Digit: "+position);
}
if(ch>=65 && ch<=90)
{
System.out.print("Capital: "+position);
}
if(ch>=97 && ch<=122)
{
System.out.print("Small: "+position);
}
}
}
your ans is wrong
DeletePrograme 3 in JAva........===========
ReplyDeletepublic class Insurence {
public static void main(String[] args)
{
int age = 25;
int premamt ,policyamt;
char loc = 'c';
char sex = 'f';
char health = 'g';
if((age>=25 && age<=35)&&(health=='g')&&(loc=='c')&&(sex=='m'))
{
premamt = 4;
policyamt = 2;
System.out.println("Person is Insured"+"\nPayble Premium: "+premamt+" /Thousands"+"\nPolicy Ammount is: "+policyamt+" Lakh");
}
else if((age>=25 && age<=35)&&(health=='g')&&(loc=='c')&&(sex=='f'))
{
premamt = 3;
policyamt = 1;
System.out.println("Person is Insured"+"\nPayble Premium: "+premamt+" /Thousands"+"\nPolicy Ammount is: "+policyamt+" Lakh");
}
else if((age>=25 && age<=35)&&(health=='b')&&(loc=='v')&&(sex=='m'))
{
premamt = 6;
policyamt = 10;
System.out.println("Person is Insured"+"\nPayble Premium: "+premamt+" /Thousands"+"\nPolicy Ammount is: "+policyamt+" Thousands");
}
else
System.out.println("Person is not Insured");
}
}
Programme 5 in java==
ReplyDeletepublic class LibraryDemo {
public static void main(String[] args)
{
int days = 21;
int late = days;
if(days>=1 && days<=5)
{
System.out.println("Your fine is: 50 paisa because you are late: "+late+" Days");
}
if(days>=6 && days<=10)
{
System.out.println("Your fine is: 1 Rs because you are late: "+late+" Days");
}
if(days>=11 && days<=30)
{
System.out.println("Your fine is: 5 Rs because you are late: "+late+" Days");
}
if(days>30)
{
System.out.println("Your membership cancled because you are late after 30 days and Your late days are: "+late+" Days");
}
}
}
Programe h in Java=======
ReplyDeletepublic class Worker {
public static void main(String[] args)
{
int hour = 1;
int takenhour = hour;
if(hour>=1 &&hour<=3)
{
System.out.println("This worker is highly Efficient,"+" Your taken Hour is: "+takenhour+"hr");
}
else if(hour>3 &&hour<=4)
{
System.out.println("This worker is ordered to improve Speed,"+" Your taken Hour is: "+takenhour+"hr");
}
else if(hour>4 &&hour<=5)
{
System.out.println("This worker is given training to improve Speed,"+" Your taken Hour is: "+takenhour+"hr");
}
else
System.out.println("This worker has to leave the company,"+" Your taken Hour is: "+takenhour+"hr");
}
}
excellent
ReplyDeleteimport java.io.*;
ReplyDeleteclass ch2_22
{
public static void main(String args[])
throws java.io.IOException
{
char ch;
ch=(char)System.in.read();
if(ch>=65 && ch<=90)
System.out.println("Character Is Capital" );
else if(ch>=97 && ch<=122)
System.out.println("Character Is small" );
else if(ch>=48 && ch<=57)
System.out.println("Character Is Digit" );
else
System.out.println("Character Is Special Symbols");
}
}
Excellent
ReplyDelete