3-2 Please do the coding in C language! 3.2 Here is a calculator program. The pr
ID: 3814153 • Letter: 3
Question
3-2
Please do the coding in C language!
3.2 Here is a calculator program. The program gives a prompt and waits for user to enter a number, operator and another number and gives the output like this Type a number operator number separated by a space 12 34 12.00 34.00 46.00 Another run looks like this: Type a number operator number separated by a space 12 12 12.00 12.00 144.00 #include stdio.h int main() int firstN int second char op; printf("Type a number, operator number separated by a space scanf ("%d %C %d", &firstN;, &op;, &second; N);Explanation / Answer
#include <stdio.h>
#include <string.h>
int main()
{
double firstN, secondN;
char op;
char ch[20];
do{
printf(" Type a number, operator, number -- seperated by a space: ");
scanf("%lf %c %lf", &firstN,&op,&secondN);
if(op=='+'){
printf("%lf + %lf = %lf", firstN,secondN,(firstN + secondN) );
}
else if(op=='-'){
printf("%lf - %lf = %lf", firstN,secondN,(firstN - secondN) );
}
else if(op=='*'){
printf("%lf * %lf = %lf", firstN,secondN,(firstN * secondN) );
}
else if(op=='/'){
printf("%lf / %lf = %lf", firstN,secondN,(firstN / secondN) );
}
else
{
printf(" Unknown operator");
}
printf("Do you want to continue (Yes/No)");
scanf("%s",ch);
if(!(strcmp(ch, "Yes") ==0))
break;
}while(1==1);
printf(" ");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.