第二章 第六節 順序結構實例

習題評測地址:http://ybt.ssoier.cn:8088

1、計算浮點數相除的餘

【題目描述】

計算兩個雙精度浮點數a和b的相除的餘數,a和b都是正數的。這裏餘數(r)的定義是:a = k * b + r,其中 k是整數, 0 <= r < b。

【輸入】

輸入僅一行,包括兩個雙精度浮點數a和b。

【輸出】

輸出也僅一行,a÷b的餘數。

【輸入樣例】

73.263 0.9973

【輸出樣例】

0.4601

【參考代碼】

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    double a,b;
    cin>>a>>b;
    printf("%g",a-b*int(a/b));
    return 0;
}

2、計算球的體積

第二章 第六節 順序結構實例

參考代碼

#include<iostream> 
#include<cstdio> 
using namespace std;
int main(){
    const double PI = 3.14;
    double r;
    cin>>r;
    printf("%.2lf\n",4/3.0*PI*r*r*r);   
    return 0;
}

3、反向輸出一個三位數

第二章 第六節 順序結構實例

參考代碼

#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n; 
    int a,b,c;
    a=n/100;
    b=n%100/10;
    c=n%100%10;
    cout<<c<<b<<a<<endl;
    return 0;
}

4 大象喝水

#include <iostream>
#include <cmath>
using namespace std;
int main(){
    const double PI=3.1415926;
    int h,r;    // h深 r:半徑 
    int l = 20000;
    int s;  //輸出值
    cin>>h>>r;
    double v = PI*r*r*h;
    s=ceil(l/v);
    cout<<s<<endl;
    return 0;
}

5 計算線段長度

第二章 第六節 順序結構實例

參考代碼

#include <iostream>
#include <cmath>
using namespace std;
int main(){
    double xa,ya,xb,yb;
    cin>>xa>>ya>>xb>>yb;    
    printf("%.3lf",sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb)));  
    return 0;
}

6計算三角形面積

第二章 第六節 順序結構實例

參考代碼

#include <iostream>
#include <cmath> 
using namespace std;
int main(){
    double x1,y1,x2,y2,x3,y3,s,p,l1,l2,l3;
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    l1=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    l2=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
    l3=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
    p=(l1+l2+l3)/2.0;
    printf("%.2lf",sqrt(p*(p-l1)*(p-l2)*(p-l3)));
    return 0;
}

7 A*B問題

第二章 第六節 順序結構實例

參考代碼

#include <iostream>
using namespace std;
int main(){
    long long a,b,c;
    cin>>a>>b;
    c=a*b;
    cout<<c<<endl;
    return 0;
}

8 計算2的冪

第二章 第六節 順序結構實例

參考代碼

#include <iostream>
using namespace std;
int main(){
    long n;
    cin>>n;
    cout<<(1<<n)<<endl;
    return 0;
}

9 蘋果和蟲子

第二章 第六節 順序結構實例

參考代碼

#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int n;
    float x,y;
    cin>>n>>x>>y;
    cout<<n-ceil(y/x)<<endl;
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章