完美解析C语言比较两个“小数”的大小

gcc

#include <stdio.h>
int main()
{
    
    
    double a,b;
    a = 2.5;
    b = 1.9;
    // printf("input a b\n");
    // scanf("%lf %lf",&a,&b);
    if (a > b) 
    printf("%lf > %lf",a,b);
    else if ( a < b) 
    printf("%lf < %lf",a,b);
    else 
    printf("%lf == %lf",a,b);
    return 0;
}

g++

#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
double a,b;
cin>>a>>b;
printf("你的输入是: A = %.3f \n B = %.3f \n",a,b);
if(a>b){
    
    
printf("A比B大\n");
}else if(a<b){
    
    
printf("B比A大\n");
}else{
    
    
printf("A与B相等\n");
}
return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_41194129/article/details/108348526