Rajesh is appearing for techathon for the price money of 10K. They have a provided a platform where an incomplete code will appear, and they have to complete the full code. He got a program where he need to create a complex calculator. Can you please help Rajesh with this.
The first line consists of a choice which is an integer to choose from 1 to 3. Choice 1 represents addition of two complex numbers, 2 represents subtraction of two complex numbers and 3 represents the multiplication of two complex numbers.
Answers
Explanation:
#include<stdio.h>
int main()
{
int ch,number_1,number_2,add,sub,mul;
printf("Calculator\n");
printf("1 REPRESENTS ADDITION\n");
printf("2 REPRESENTS SUBTRACTION\n");
printf("3 REPRESENTS MULTIPLICATION\n\n");
printf("Enter a Choice=");
scanf("%d",&ch);
switch (ch)
{
case 1:
printf("Enter 2 Numbers you want to add:");
scanf("%d %d",&number_1,number_2);
add=number_1+number_2;
printf("The Sum of %d + %d = %d",number_1,number_2,add);
break;
case 2:
printf("Enter 2 Numbers you want to subtract:");
scanf("%d %d",&number_1,number_2);
sub=number_1-number_2;
printf("The Subtraction of %d - %d = %d",number_1,number_2,sub);
break;
case 3:
printf("Enter 2 Numbers you want to multiply:");
scanf("%d %d",&number_1,number_2);
mul=number_1*number_2;
printf("The Multiply of %d * %d = %d",number_1,number_2,mul);
break;
default:
printf("WRONG CHOICE");
}
return 0;
}
PLEASE MARK ME BRAINLIEST !!!!!
Answer:
#include<iostream>
using namespace std;
int main()
{
int a,b,c,d,n;
cin>>n>>a>>b>>c>>d;
switch(n)
{
case 1:
cout<<(a+c)<<"-"<<(b+d)<<"i";
break;
case 2:
cout<<(a-c)<<"+"<<(b-d)<<"i";
break;
case 3:
cout<<((a*c)-(b*d))<<((b*c)+(a*d))<<"i";
break;
default:cout<<"Invalid choice";
}
}
Explanation:
It will pass all the test cases. It is simple and helpful and easily understandable also.