2.
Write a program that asks the user to enter two numbers,
obtains the two numbers from the user and prints the sum, product, difference, and quotient of the two numbers.
Number1 Number2
Case I int int
Case II float float
Case III double double
Case VI int float
Consider and discuss the results.- #include<stdio.h>
- int main(){
- int a,b;
- double c,d,e,f;
- printf("case1: input two numbers");
- printf("\nNo.1:");
- scanf(" %d",&a);
- printf("\nNo.2:");
- scanf(" %d",&b);
- c = a+b;
- d = a*b;
- e = a-b;
- f = a/b;
- printf("\nthe sum is %lf",c);
- printf("\nthe product is %lf",d);
- printf("\nthe difference is %lf",e);
- printf("\nthe quotient is %lf",f);
- float h,i;
- printf("\n\ncase2: input two numbers are float");
- printf("\nNo.1:");
- scanf(" %f",&h);
- printf("\nNo.2:");
- scanf(" %f",&i);
- c = h+i;
- d = h*i;
- e = h-i;
- f = h/i;
- printf("\nthe sum is %lf",c);
- printf("\nthe product is %lf",d);
- printf("\nthe difference is %lf",e);
- printf("\nthe quotient is %lf",f);
- double j,k;
- printf("\n\ncase2: input two numbers are double");
- printf("\nNo.1:");
- scanf(" %lf",&j);
- printf("\nNo.2:");
- scanf(" %lf",&k);
- c = j+k;
- d = j*k;
- e = j-k;
- f = j/k;
- printf("\nthe sum is %lf",c);
- printf("\nthe product is %lf",d);
- printf("\nthe difference is %lf",e);
- printf("\nthe quotient is %lf",f);
- int m;
- float m;
- printf("\n\ncase2: input two numbers are double");
- printf("\nNo.1:");
- scanf(" %d",&m);
- printf("\nNo.2:");
- scanf(" %f",&n);
- c = m+n;
- d = m*n;
- e = m-n;
- f = m/n;
- printf("\nthe sum is %lf",c);
- printf("\nthe product is %lf",d);
- printf("\nthe difference is %lf",e);
- printf("\nthe quotient is %lf",f);
- }
複製代碼 |