Test-1 solutions: 1Q(a). One day early morning I found a person in a play ground. He started walking from the center of the play ground and reached the edge of the playground after x meters walking. Later he started running to surround the playground. Totally he completed y rounds. Develop an algorithm to find totally how many meters he runs. 1Ans: 1. Start 2. Read X and Y values 3. T Y * 2*3.14*X 4. Display T value 5. Stop 1Q(b). There are three fruit boxes. We know that one box contains only apples, another box contains only oranges and another box contains both apples and oranges but all these boxes are labeled incorrectly. Write an algorithm to pick out only one fruit from any one box and then correct all labels. 1(b)Ans. 1. Start 2. Pick out a fruit from a box which is having incorrect label A and O 3. if it is Apple fruit then do a. change incorrect label A and O with A. b. change incorrect label O with label A and O c. change incorrect label A with label O else a. change incorrect label A and O with O. b. change incorrect label A with label A and O c. change incorrect label O with label A 4. Stop 1Q(c). In an oil shop, shopkeeper having 3ltr and 5ltr measuring jugs. If he wants to sale 4 litterers oil then how he can measure without using another jug of any size. Develop an algorithm to measure 4ltr oil. 1(c)Ans. 1. Start 2. Take 5 liters oil into 5ltr jug. 3. Pour oil into 3ltr jug from 5ltr jug to fill 3ltr jug. 4. Make empty 3ltr jug. 5. Pour remaining 2ltr oil from 5ltr jug into 3ltr jug. 6. Take 5 liters oil into 5ltr jug second time. 7. Pour oil from 5ltr jug to 3ltr jug to fill the remaining empty place in 3ltr jug. 8. Now you have 4ltr oil in 5ltr jug. 9. Stop (OR) 1Q(d). The distance between two cities (in KM) is input through the keyboard. Write an algorithm to convert and print his distance in meters and centimeters.
1(d)Ans. 1. Start 2. Read X values 3. M X/1000. 4. CM M/100 5. Display M and CM values 5. Stop 1Q(e). The policy followed by a company to process customer orders is given by the following rules. i. If a customer order is less than or equal to that in stock and his credit is OK, supply his requirement. ii. If his credit is not OK do not supply. Send him intimation. iii. If the credit is OK but the item in stock is less than his order, supply what is in stack. Draw the flow chart to implement the company policy. start Read available stock in company Read customer order Order<=stoc Is credit OK? Is credit OK? Supply customer requirement Do not Supply send information Supply available stock to customer Do not Supply send information stop
1Q(f). A particular type of carpet costs Rs.17.45 per square feet. How much will the carpeting cost for two connecting rooms? One room is 16 feet by 24 feet, and the other room is 12 feet by 14 feet. Draw the flow chart for this problem. 1(f)Ans: start Total_cost = (16*24 + 12*14) * 17.45 Display Total_cost stop 2Q(a). Write logical expressions that tests whether a given character variable c is lower case letter, upper case letter, letter digit and white space. 2(a)Ans: logical expression to test lower case letters -- c>= a && c<= z logical expression to test upper case letters -- c>= A && c<= Z logical expression to test digit letters -- c>= 0 && c<= 9 logical expression to test white space letters -- c== \n c== \t c == 2Q(b). Write a statement using conditional operator that will give the smallest of three numbers. 2(b)Ans: small = (a<b)?( (a<c)?(a):(c) ):( (b<c)?(b):(c) ); 2Q(c). 2(c)Ans: int p,q,r; p=3; q = 4; r = 0; r = (p++,q *= p); What are the values of p,q,r after execution of above code segment? p = 4 q = 16 r = 16 (OR) 2Q(d). Find out all possible errors in the following C program and then explain each error why those errors are coming and then correct this program by eliminating those errors so that, to get the expected output. Program to find the area of a triangle:-
int 1st_input_base, _2nd_input_height, Area; printf( /n/t enter 2 input values ); scanf( %d%d,&1st_input_base, &_2nd_input_height) Area == ½*1st_input_base * _2nd_input_height; printf( /nresult = %o,area); 2(d)Ans: Program to find the area of a triangle:- float first_input_base, _2nd_input_height, Area; printf( \n\t enter 2 input values ); scanf( %f%f,&first_input_base, &_2nd_input_height); Area = 0.5*first_input_base * _2nd_input_height; printf( \nresult = %f,area); - Red-colored things are syntax errors. They are corrected in the above program. Compare it with program given in question. - Yellow colored things are not syntax errors. But instead of \n and \t he given /n and /t. but we will not get error. - Brown colored things are run time errors. We will not get expected output because of integer division. 2Q(e). Identify the output of the following C program and then write reason. int a,b,c; a = 034; b = 345; c = a+b; printf("%d",c); c = b-a; printf("%x",c); 2(e)Ans: 373, 13d 2Q(f) Add arithmetic operators(plus, minus, multiply, divide) to make the following expression true: 3 1 3 6 = 8. You can use any parentheses you d like. 2(f)Ans: 3-1%3+6 = 8 3Q(a). Develop an algorithm and program to find the total bill amount in shopping mall by reading total amount for purchased grocery. Service taxes and discounts are calculated as shown below. S.No Bill amount(rs) Service Tax Discount 1 If bill_amount <= 500 5% 1% 2 If bill_amount <= 1500 10% tax for excess of 500 5% discount for excess of 500 3 If bill_amount <=2000 15% tax for excess of 1500 10% discount for excess of 1500 4 If bill_amount <= 2500 20% tax for excess of 2000 15% discount for excess of 2000
5 Else 25% tax for excess of 2500 20% discount for excess of 2500 3(a)Ans: Algorithm: 1. Start 2. Read bill_amount 3. If bill_amount <= 500 then do a. Service_tax = bill_amount/100*5.0 b. Discount = bill_amount/100*1.0 Else if bill_amount <=1500 then do a. Service_tax = 25+(bill_amount-500)/100*10.0 b. Discount = 5 + (bill_amount-500)/100*5.0 Else if bill_amount <=2000 then do a. Service_tax = 125+(bill_amount-1500)/100*15.0 b. Discount = 55+(bill_amount-1500)/100*10.0 Else if bill_amount <=2500 then do a. Service_tax = 200+(bill_amount-2000)/100*20.0 b. Discount = 105+ (bill_amount-2000)/100*15.0 Else if bill_amount > 2500 then do a. Service_tax = 300+(bill_amount-2500)/100*25.0 b. Discount = 180+ (bill_amount-2500)/100*20.0 4. Display total_bill _amount value 5. Stop. Program: float bill_amount,total_bill_amount,service_tax,discount; printf("\n enter bill amount"); scanf("%f",&bill_amount); if(bill_amount<=500.0) service_tax = bill_amount/100*5.0; discount = bill_amount/100*1.0; else if(bill_amount<=1500.0) service_tax = 25.0 + (bill_amount-500)/100*10.0; discount = 5.0 + (bill_amount-500)/100*5.0;
else if(bill_amount<=2000.0) service_tax = 125.0 + (bill_amount-1500)/100*15.0; discount = 55.0 + (bill_amount-1500)/100*10.0; else if(bill_amount<=2500.0) service_tax = 200.0 + (bill_amount-2000)/100*20.0; discount =105.0 + (bill_amount-2000)/100*15.0; else if(bill_amount>2500.0) service_tax = 300.0 + (bill_amount-2500)/100*25.0; discount = 180.0 + (bill_amount-2500)/100*20.0; printf("\ntotal bill amount : %f",total_bill_amount); 3Q(b). If a five digit integer number is input through the keyboard, write a program to calculate the sum of its individual digits. int n,sum=0,d; printf( \n enter 5-digit number ); scanf( %d,&n); n = n/10; n = n/10; n = n/10; n = n/10; printf( %d,sum); 3.c) If the marks obtained by a student in 5 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. #include<conio.h> Void main()
int s1,s2,s3,s4,s5; float avg,total,percetage; printf( enter 5 subject marks ); scanf( %d%d%d%d%d,&s1,&s2,&s3,&s4,&s5); total=(s1+s2+s3+s4+s5); avg=total/5.0; percentage=(total/500)*100; printf( average marks=%f,avg); printf( percentage=%f,percentage); (OR) 3. d) Write a program that reads a positive integer and then counts the number of even digits and odd digits. #include<conio.h> int n,r,ecount,ocount; clrscr(); printf( enter an integer number ); scanf( %d,&n); ecount=ocount=0; while(n!=0) r=n%10; if(r%2==0) ecount++; else ocunt++; n=n/10; printf( \nnumber of even digits are %d,ecount); printf( \n number of odd digits are %d,ocount); e) A survey of the computer market shows that personal computers are sold at varying cost by the vendors. The following is the list of costs(in thousands) quoted by some vendors. 35.00, 40.50, 25.00, 31.25, 68.15, 47.00,26.65, 29.00, 53.45, 62.50 Write a program to determine the average cost and the range of values. #include<conio.h> Void main() Float a,b,c,d,e,f,g,h,i,j,avg; a=35.00; b= 40.50;
c= 25.00; d= 31.25; e= 68.15; f= 47.00; g=26.65; h=29.00; i= 53.45; j= 62.50; avg=(a+b+c+d+e+f+g+h)/10.00; printf( \n Average=%f,avg); printf( \n Range of values is 25.00 to 68.15 ); 3Q(f). Analyze outputs of the following two computer programs for all possible inputs and then find out whether these two are generating same outputs for the given all inputs or not. If not explain why they are not same with example. If yes, then create a proper problem statement for the following two programs. int a,b,t; printf( \n enter two numbers ); scanf( %d%d,&a,&b); t = a; a = b; b = t; printf( \na = %d \t b = %d,a,b); int a,b; printf( \n enter two numbers ); scanf( %d%d,&a,&b); a = a*b; b = a/b; a = a/b; printf( \na = %d \t b = %d,a,b); 3f.Ans: Both program will not give same output in all cases. For example if a = 10 and b = 0 in this case first program swap the values of a and b variables. But 2 nd program gives runtime error-divide by zero error.
Problem statement: program to swap the given two variable numbers.