本文目录一览:
- 1、c语言小数除法
- 2、编程求出分数355/113的数值中小数点后的10001位数字是几
- 3、c语言编程计算355/113的值
- 4、两个C语言编程题,对C语言只有那么头疼了。教求高手的指点。
- 5、c语言 计算PI的近似分数
c语言小数除法
改为if(i4.0/3-0.01i4.0/3+0.01);
#include "stdio.h"
main()
{
float i;
scanf("%d",i);
if(i4.0/3-0.01i4.0/3+0.01);
printf("zheng que") ;
getch( );
}
编程求出分数355/113的数值中小数点后的10001位数字是几
c语言实现:
#includestdio.h
#define N 10001
int main()
{
int quotient,remainder;
int i = 0;
remainder = 355%133;
while(i=N)
{
remainder *= 10;
quotient = remainder/133;
remainder = remainder%133;
i++;
}
printf("the result is %d\n",quotient);
}
c语言编程计算355/113的值
#includestdio.h
int main(){
double a;
a=(double)355/113;
printf("%lf",a);
return 0;
}
两个C语言编程题,对C语言只有那么头疼了。教求高手的指点。
第一题:
int main()
{
unsigned int n,m,i,num;
num = 2;
scanf("%d", n);
for ( i = 1; i = n; ++i)
{
for ( m = 1; m = i; ++m, num+=2 ) printf("%d ", num);
printf("\n");
}
return 0;
}
第二题:
#include stdio.h
void div(int a, int b, int n, char* ans)
{
int last_d = 0;
if (( a 0 b 0 ) || ( a 0 b 0 ))
{
*(ans++) = '-';
}
a = a 0 ? a : -a;
b = b 0 ? b : -b;
// 1. Integer part
ans += sprintf(ans, "%d", a/b);
if ( n = 0 ) *(ans++) = '.';
// 2. Float part
while ( --n 0 )
{
a %= b; a *= 10;
if ( a b ) *(ans++)='0';
else ans += sprintf(ans, "%d", a/b);
}
// 3. Last digit is a special case
if ( n == 0 )
{
a %= b; a *= 10;
last_d = a/b;
a %= b; a *= 10;
last_d += ( a / b = 5 ) ? 1 : 0;
ans += sprintf(ans, "%d", last_d) ;
}
*ans = '\0';
}
int main()
{
char s[60];
int a, b;
scanf("%d,%d", a, b);
div(a, b, 30, s);
printf("%s\n", s);
return 0;
}
c语言 计算PI的近似分数
/*
计算PI的近似分数,要求比355/113精度更高
*/
#includestdio.h
#includemath.h
void main()
{
double a,b;
long i=10000,j;
printf("355/113 = %.16f\n",355/113.0);
for(;;i++)
{
for(j=i*3.141592;ji*3.141593;j++)
{
//pi=3.14159265358979323846264338327950288;
a=(double)j/i-3.1415926535897932;
b=355/113.0-3.1415926535897932;
if(fabs(a)fabs(b))
{
printf("%ld/%ld = %.16f\n",j,i,(float)j/i);
getch();
return;
}
}
}
}
/*
输出:
355/113 = 3.1415929203539825
52163/16604=3.1415923873765359
*/
精确到小数点后面第七位:
103283/32876=3.1415926511741086