1 条题解

  • 0
    @ 2023-6-11 12:16:29

    C :

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<ctype.h>
    #include<math.h>
    int main(){
    	int  a,b,n;
    	scanf("%d%d%d",&a,&b,&n);
    	printf("%d%s",a/b,".");
    	while(n!=0){
    		a = a%b*10;
    		printf("%d",a/b);
    		n--;
    	}
    	return 0;
    }
    
    

    C++ :

    #include <iostream>
    using namespace std;
     
    int main(){
        int a,b,k,n,i;
        cin>>a>>b>>n;
        cout<<a/b<<'.';
        k=a%b;
        for(i=0;i<n;i++){
            k=k*10;
            cout<<k/b;
            k=k%b;
        }
    }
    
    

    Python :

    sr=input().split()
    x1=int(sr[0])
    x2=int(sr[1])
    n=int(sr[2])
    zhensu=x1//x2
    s=str(zhensu)+"."
    yushu=x1%x2
    for i in range(n):
        div1=yushu*10
        s=s+str(div1//x2)
        yushu=div1%x2
    print(s)
    
    • 1

    信息

    ID
    2182
    时间
    1000ms
    内存
    16MiB
    难度
    10
    标签
    递交数
    2
    已通过
    0
    上传者