64,652
社区成员
发帖
与我相关
我的任务
分享
# include <cstdio>
# include <cmath>
using namespace std;
int main()
{
int n, result; //声明整型变量n(小数点后第几位)和result(小数点后第n位小数)
double a, b, number; //生命双精度浮点型变量a(被除数)、b(除数)和number(商(没有余数))
scanf("%lf %lf %d", &a, &b, &n); //用户输入被除数a、除数b和要求的小数点后第几位位数n
number = a / b; //求出商(没有余数)
result = (int)(number / (1.0 / pow(10, n))) % 10;
//number / (1.0 / pow(10, n))求出number里有几个10的-n次方,然后求出个位数即使题目所求,存入整形变量result
printf("%d", result); //输出result
return 0; //结束程序
}
# include <cstdio>
# include <cmath>
using namespace std;
int main()
{
int n, result; //声明整型变量n(小数点后第几位)和result(小数点后第n位小数)
double a, b, number; //生命双精度浮点型变量a(被除数)、b(除数)和number(商(没有余数))
scanf("%lf %lf %d", &a, &b, &n); //用户输入被除数a、除数b和要求的小数点后第几位位数n
number = a / b; //求出商(没有余数)
result = (int)(number / (1.0 / pow(10, n))) % 10;
//number / (1.0 / pow(10, n))求出number里有几个10的-n次方,然后求出个位数即使题目所求,存入整形变量result
printf("%lf\n", (number / (1.0 / pow(10, n)))); //错误之后添加的测试行,提交时没有,本行输出number里有几个10的-n次方
printf("%d\n", (int)(number / (1.0 / pow(10, n)))); //错误之后添加的测试行,提交时没有,本行输出对上一行结果进行int的结果
printf("%d", result); //输出result
return 0; //结束程序
}
# include <cstdio>
using namespace std;
int main()
{
double a = 12.000000;
printf("%d\n", (int)a);
return 0;
}
#include <stdio.h>
int main()
{
double a = 6. / 5.;
printf("%lf\n%.22lf\n", a, a);
return 0;
}
//【输入】
//三个正整数a,b,n,相邻两个数之间用单个空格隔开。0<a<b<100,1<=n<=10000。
//【输出】
//一个数字。
//【输入样例】
//1 2 1
//【输出样例】
//5
//例如:13/97=0.13402061855670103092783505154639;
# include <stdio.h>
# include <math.h>
using namespace std;
int main()
{
int n, result,a, b;
scanf("%d %d %d", &a, &b, &n);
result = (int)(a*1.0 / b*1.0/(1.0 / pow(10, n))) % 10;
printf("%d", result); //输出result
return 0; //结束程序
}
//6 5 1
//2请按任意键继续. . .
//13 97 32
//0请按任意键继续. . .
//13 97 10000
//pow: OVERFLOW error 溢出报错
模拟除法的写法,供参考://模拟除法过程
//例如:13/97=0.13402061855670103092783505154639;
#include <stdio.h>
using namespace std;
int main()
{
int a,b,n,c;
scanf("%d %d %d",&a,&b,&n);
if(a > b) a = a % b;
for(int i = 1;i <= n;i ++){
c = 10 * a / b;
a = 10 * a - b * c;
}
printf("%d\n",c);
return 0;
}
//6 5 1
//2
//请按任意键继续. . .
//13 97 32
//9
//请按任意键继续. . .
//13 97 79
//6
//请按任意键继续. . .
//13 97 10000
//0
//请按任意键继续. . .