0

i don't have a clue what is wrong here....
the program is supposed to add, subtract, multiply and divide two real numbers.

#include<stdio.h>

float add(float x, float y);
float subtract(float x, float y);
float multiply(float x, float y);
float divide(float x, float y);

int main (void)
{

int choice;
float x, y;

while(1)
{
    printf("\nPress 1 to add two  numbers.\n");
    printf("Press 2 to subtract two numbers.\n");
    printf("Press 3 to multiply two numbers.\n");
    printf("Press 4 to divide two numbers.\n");
    printf("Press 5 to exit the program.\n");
    printf("\nEnter your choice:\n");
    scanf("%d",&choice);

    if(choice==5)
    {
        return 0;
    }

    if(choice >= 1 && choice <= 4)

    {
    printf("Please enter a real number:\n");
    scanf("%f", &x);

    printf("Please enter another real number:\n");
    scanf("%f", &y);

    if (choice==1)
    {    
    printf("The sum of both values inputted: % f\n", add(x, y));
    }

    float add(float x, float y)

    {
        return x+y;
    }

    else if (choice==2)
    {    
    printf("The difference of both values inputted: % f\n", subtract(x, y));
    }

    float subtract(float x, float y)

    {
        return x-y;
    }

    else if (choice==3)
        {    
    printf("The difference of both values inputted: % f\n", multiply(x, y));
    }

    float multiply(float x, float y)

    {
        return x*y;
    }

    else if (choice==4)
    {    
    printf("The difference of both values inputted: % f\n", divide(x, y));
    scanf("%f",x/y)
    }

    float divide(float x, float y)

    {
        return x/y;
    }

}
}
0
#include<stdio.h> 
#include<stdlib.h>

struct complex

{
  int real,imag;
};

int main()

{
int choice;
struct complex x, y, z;

{
    printf("Press 1 to add two complex numbers.\n");
    printf("Press 2 to subtract two complex numbers.\n");
    printf("Press 3 to multiply two complex numbers.\n");
    printf("Press 4 to divide two complex numbers.\n");
    printf("Enter your choice\n");
    scanf("%d",&choice);

    if(choice >= 1 && choice <= 4)

    {
        printf("Please enter the two real and imaginary complex numbers (a+jb) :\n");
        printf("\nReal Number:");
        scanf("%d", &x.real);
        printf("\nImaginary Number:");
        scanf("%d", &x.imag);

        printf("\nPlease enter the next two real and imaginary complex numbers (c+jd) :\n");
        printf("\nReal Number:");
        scanf("%d", &y.real);
        printf("\nImaginary Number:");
        scanf("%d", &y.imag);

        printf("\nFirst Complex Number:%d+j%d",x.real, x.imag);
        printf("\nSecond Complex Number:%d+j%d\n",y.real, y.imag);
    }

    if (choice==1)
    {    
        z.real=x.real+y.real;
        z.imag=x.imag+y.imag;
        printf("\nThe result of the addition of the two complex numbers:%d+j%d\n",z.real, z.imag);  
    }

    else if (choice==2)
    {
        z.real=x.real-y.real;
        z.imag=x.imag-y.imag;
        printf("\nThe result of the subtraction of the two complex numbers:%d+j%d\n",z.real, z.imag);  
    }

    else if (choice==3)
    {
        z.real=x.real*y.real-x.imag*y.imag;
        z.imag=x.imag*y.real+x.real*y.imag;
        printf("\nThe result of the multiplication of the two complex numbers:%d+j%d\n",z.real, z.imag);  
    }

    else if (choice==4)
    {   z.real=x.real/y.real-x.imag/y.imag;
        z.imag=x.imag/y.real+x.real/y.imag;
        printf("\nThe result of the division of the two complex numbers:%d+j%d\n",z.real, z.imag);  
    }

    else 
    {
        printf("Invalid Choice");
    }

76 };

the problem is it says 76: "expected declaration or statment at end of input"

0

Ok so now i have been able to write the code for adding and subtracting two complex numbers in rectangular form but now need to do the same for multiplication and division in polar form.

#include<stdio.h> 
#include<stdlib.h>

struct complex

{
  int real,imag;
};

int main()
{
     struct complex x, y, z;
    printf("Please enter the two real and imaginary complex numbers (a+jb) :\n");
    printf("\nReal Number:");
    scanf("%d", &x.real);
    printf("\nImaginary Number:");
    scanf("%d", &x.imag);

    printf("\nPlease enter the next two real and imaginary complex numbers (c+jd) :\n");
    printf("\nReal Number:");
    scanf("%d", &y.real);
    printf("\nImaginary Number:");
    scanf("%d", &y.imag);

    printf("\nFrist Complex Number:%d+j%d",x.real, x.imag);
    printf("\nSecond Complex Number:%d+j%d\n",y.real, y.imag);

    z.real=x.real+y.real;
    z.imag=x.imag+y.imag;

    printf("\nThe result of the addition of the two complex numbers:%d+j%d\n",z.real, z.imag);  

   return 0;
} 

The above is the code to add two complex numbers in rectangular form.

1

kind of... more like this?

#include<stdio.h> 
#include<stdlib.h>

struct complex

{
  int real,imag;
};

int main()
{
     struct complex x, y, z;
    printf("Please enter the two real and imaginary complex numbers (a+jb) :\n");
    printf("\nReal Number:");
    scanf("%d", &x.real);
    printf("\nImaginary Number:");
    scanf("%d", &x.imag);

    printf("\nPlease enter the next two real and imaginary complex numbers (c+jd) :\n");
    printf("\nReal Number:");
    scanf("%d", &y.real);
    printf("\nImaginary Number:");
    scanf("%d", &y.imag);

    printf("\nFrist Complex Number:%d+i%d",x.real, x.imag);
    printf("\nSecond Complex Number:%d+i%d\n",y.real, y.imag);

    z.real=x.real+y.real;
    z.imag=x.imag+y.imag;

    printf("\nThe result of the addition of the two complex numbers:\n",z.real, z.imag);  

   return 0;

i'm having difficulty showing the result though?

0

I have no idea hw to approach this... i need to end my program, shown below by the user pressing the letter Q on the keyboard. Help?

#include <stdio.h>
#include <stdlib.h>

float subtract(float x, float y);

int main (void)
{
    float x, y;

    printf("Please enter a real number:\n");
    scanf("%f", &x);

    printf("Please enter another real number:\n");
    scanf("%f", &y);

    printf("The difference of both values inputted: % f\n", subtract(x, y));       
}

float subtract (float x, float y)

{
    return x-y;    
}
0

I have an assignment in which i have to add, subtract, multiply and divide two complex numbers and i am very confused as to how to create the program.
This is what i have got so far..

#include <stdio.h>
#include <complex.h>

int main (void)

int real, imag;

{
    complex a, b, c, d;

    printf("Please enter the two real and imaginary complex numbers (a+jb) :\n")
    printf("a = \n");
    scanf("%d", &a.real);
    printf("b = \n");
    scanf("%d", &b.imag);

    printf("Please enter the next two real and imaginary complex numbers (c+jd) :\n")
    printf("c = \n");
    scanf("%d", &c.real);
    printf("d = \\n");
    scanf("%d", &d.imag);

}

obviously i don't know if this is right but i am hoping so, now i don't know how to write the expression for adding the two complex numbers or outputting the end value.