Philips Interview Question for Junior programmers
- 0of 0 votes
Create a text file called calc.c that contains the following C program:- stimulation101 March 04, 2017 in England
float add (float x, float y)
return x + y;
float a, b, r;
printf("number op number? ");
scanf(" %f %c %f", &a, &op, &b);
case '+' : r = add(a,b);
case 'q' : break;
default : op='?';
else if (op=='q')
printf("%f %c %f = %f\n", a, op, b, r);
while (op != 'q');
The program behaves like a calculator asking the user to type in binary expressions (like 2.5 + 3.7) and printing out the results. If the user enters 'q' for the operator (e.g. 0 q 0) then this is taken as a signal to stop the program.
Add a new function to the program that multiplies its two arguments together and returns their product. Then modify the switch statement so that the operator '*' causes this new product function to be called. Test the program by using a mixture of '+' and '*' calculations.
Add operators for subtraction ('-') and division ('/') and test your program again.
We introduce some special operators. Write functions to implement each of these (adding one at a time and testing after each new operator is incorporated into your calculator).
Symbol Description Example
m Minimum 2.3 m 1.7 = 1.7
M Maximum 2.3 M 1.7 = 2.3
| Report Duplicate | Flag | PURGE
Philips Junior programmer Programmin in c
Open Chat in New Window