当前位置:网站首页>第一章:求所有阶乘和数,大奖赛现场统分程序设计,三位阶乘和数,图形点扫描,递归求n的阶乘n!,求n的阶乘n!,舍罕王失算
第一章:求所有阶乘和数,大奖赛现场统分程序设计,三位阶乘和数,图形点扫描,递归求n的阶乘n!,求n的阶乘n!,舍罕王失算
2022-07-03 19:16:00 【股_四】
//求所有阶乘和数
long fac3 (int x)
{
int i;
long p=1;
for (i=1 ;i<=x;i++)
p*=i;
return (p);
}
int main()
{
int a, b, c, d, e, f, g;
long m1, m2, m3, m4, m5, m6, n1, n2, n3, n4, n5, n6;
printf(" 所有阶乘和数有: ");
for (a = 1; a <9;a++)
{
if (a == fac3(a))
printf("%d", a);
for (b=0;b <= 9;b++)
{
m1 = a * 10 + b;
n1=fac3 (a) + fac3 (b);
if(m1 == n1)
printf("%ld ", m1);
for (c=0;c<=9; c++)
{
m2 = m1 * 10 + c;
n2 = n1 + fac3(c);
if(m2 == n2)
printf("%ld", m2);
for (d=0; d <= 9; d++)
{
m3 = m2 * 10 + d;
n3 = n2 +fa3c(d);
if (m3==n3) printf("%ld" , m3);
for(e=0; e <= 9; e++)
{
m4 = m3 * 10 + e;
n4 = n3 + fac3 (e);
if(m4==n4)
printf("%ld", m4) ;
for(f = 0; f <= 9; f++)
{
m5 = m4 * 10 + f;
n5 = n4 + fac3(f);
if( m5 == n5)
printf("%ld",m5);
for( g = 0; g <= 9; g++)
{
m6 = m5 * 10 + g;
n6 = n5 + fac3(g);
if( m6 == n6)
printf("%ld",m6);
}
}
}
}
}
}
}
return 0;
}
结果:
//大奖赛现场统分程序设计
int main()
{
int i, j, n, m, u, sh[40], ph[20];
double a,b, c, max, min, uf, sf[40], pf[20],z[40], f[40][20];
printf("请输入选手个数 (1<n<40): ");
scanf ("%d", &n);
printf("请输入评委个数 (2<m<20):");
scanf ("%d", &m);
for (j=1; j <= m; j++)
ph[j] = j;
for(i = 1; i <= n; i++) // 现场为选手评分,统分
{
printf ("\n 第%d 个上场选手编号为: ",i);
scanf("%d",&sh[i]);// 输入第i个上场选手编号
sf[i]=0;
max=0;
min=100;
for(j=1; j <= m; j++)
{
printf(" 第%d个评委评分为:",j);
scanf("%lf",&f[i][j]);
sf[i] += f[i][j];
if (max < f[i][j])
max = f[i][j]; //输入第j个评委为第i个选手的评分 //统计最高分与最低分
if (min > f[i][j])
min = f[i][j];
}
printf("\n 去掉一个最高分:%.3f",max);
printf("\n 去掉一个最低分:%.3f",min);
sf[i]= (sf[i]-max-min) / (m-2); // 第i个选手的最后得分
a = max-sf[i];
b = sf[i]-min;
z[i] = (a>b) ?a:b;
printf ("\n 编号为%d号选手",sh[i]);
printf(" 最后得分为:%.3f",sf[i]); // 宜布第 i个选手的得分
}
for (c=0, i=1; i <= n;i++)
c += z[i] * z[i];
c = sqrt (c/n); //给评委评分
for(j=1; j <= m; j++)
{
pf[j]=0;
for (i=1; i <=n; i++)
pf[j]+=(f[i][j]-sf[i]) * (f[i][j]-sf[i]);
pf[j] = 10.0 - sqrt(pf[j]/n) /c*5;
printf("\n 第%d 号评委得分为:%.3f",j,pf[j]);
}
for(i = 1; i <= n; i++)
for(j = i +1; j <= n; j++)
if(sf[i] < sf[j])
{
uf = sf[i];
sf[i] = sf[j];
sf[j] = uf;
u = sh[i];
sh[i] = sh[j];
sh[j] = u;
}
printf ("\n 参賽选手得分名次表");
printf("\n 选手编号 得分 名次");
for (i=1; i <= n; i++)
printf ("\n %d %.3f %d", sh[i], sf[i], i) ;
printf("\n");
for(j = 1;j <= m-1;j++) // 评委得分从高到低排序 数
for (i = j+1;i <= m;i++)
if (pf[j] < pf[i])
{
uf = pf[j];
pf[j] = pf[i];
pf[i] = uf;
u = ph[j];
ph[j] = ph[i];
ph[i] = u;
}
printf("\n 评委得分名次表");
printf ("\n 评委编号 得分 名次");
for(j=1;j <= m; j++)
printf ("\n %d %.3f %d", ph[j], pf [j], j) ;
printf ("\n 竞赛现场统分结束,谢谢!\n");
return 0;
}
结果:

//三位阶乘和数
long fac2 (int x)
{
int i;
long p=1;
for (i=1;i<=x;i++)
p*=i;
return (p);
}
int main()
{
int a, b, c, m,n;
printf(" 三位阶乘和数有:");
for (a = 1; a <= 6; a++)
for (b = 0; b <= 6; b++)
for (c=0; c <= 6; c++)
{
m = a * 100 + b * 10 + c;
n = fac2(a) + fac2(b) + fac2(c);
if (m==n) printf ("%d \n", m) ;
}
}
结果:
//图形点扫描 求地图面积
int main()
{
FILE *fp;
char fname[50]; //文件名长度在此约定不大于 50
int i, j, x, y, k, s, w, t, a[12] [12] ;
printf (" \n input file name: ");
gets (fname);
if ( (fp=fopen (fname, "r")) == NULL)
{
printf( "The file was not opened n" ) ;
return 0;
}
x = 11;
y = 11;
for (i=0; i <=y; ++i)
{
printf("\n ");
for(j=0; j<=x;++j)
{
fscanf(fp, "%d", &a[i][j]); //,从文件读数据到二维a数组
printf("%d ",a[i][j]);
}
}
for(i = 0; i <= x ;++i)
{
if(a[0][i] == 0)
a[0][i] = 2;
if(a[y][i] == 0)
a[y][i] = 2;
}
for(i = 1; i <= y ;++i)
{
if(a[i][0] == 0)
a[i][0] = 2;
if(a[i][x] == 0)
a[i][x] = 2;
}
t = x * y;
for (k=1;k<t; ++k)
{
w = 0;
for (i = 1; i < y; ++i)
for( j = 1; j < x; ++j)
if((a[i][j-1] == 2 || a[i][j+1] == 2 || a[i-1][j] == 2 || a[i+ 1][j] == 2) && a[i][j] == 0)
{
a[i][j] = 2;
w = 1;
}
}
s = 0;
printf("\n ");
for(i = 0; i <= y; ++i)
{
printf("\n ");
for(j = 0; j <= x; ++j)
{
if(a[i][j] == 0) s += 1;
printf("%d", a[i][j]);
}
}
printf("\n s = %d\n", s);
fclose(fp);
return 0;
}
结果:
文件路径:
文件内容:
PS:没有空格会乱码
//递归求n的阶乘n!
long fac1(int n)
{
long f;
if (n == 1) f = 1;
else f = n * fac1(n - 1);
return (f);
}
int main()
{
int n;
long y;
printf(" 请输入n(n < 13):");
scanf("%d", &n);
if (n > 12)
{
printf(" 输入的n超出上限12,请重新输入n。\n");
return 0;
}
y = fac1(n);
printf(" %d! = %ld\n", n, y);
return 0;
}
结果:
//求n的阶乘n!
int main()
{
int k, n;
long t;
printf(" 请输入n (n < 3)", &n);
scanf("%d", &n);
t = 1;
for (k = 1; k <= n; k++)
t = t * k;
printf(" %d != %ld\n", n, t);
return 0;
}
结果:
//舍罕王失算
int main()
{
double t, s, v, p;
int i, n;
printf(" 请输入格数n:");
scanf("%d", &n);
t = 1;
s = 1;
for (i = 2; i <= n; i++)
{
t = t * 2;
s += t;
}
v = s / 2.4e7;
p = v / 2.48e9;
if (n <= 40) printf(" 总麦粒数为:%.0f\n", s);
else printf(" 总麦粒数为:%.3e\n", s);
printf(" 小麦重量约为:%f吨\n", v);
printf(" 约相当于世界粮食年总产量的%.0f倍\n", p);
return 0;
}
结果:
边栏推荐
- 【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁
- Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]. StandardContext
- The way to treat feelings
- Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement
- Php based campus lost and found platform (automatic matching push)
- Floating source code comment (38) parallel job processor
- 變化是永恒的主題
- Dart JSON编码器和解码器剖析
- How does if ($variable) work? [repeat] - how exactly does if ($variable) work? [duplicate]
- flask 生成swagger文档
猜你喜欢

During MySQL installation, the download interface is empty, and the components to be downloaded are not displayed. MySQL installer 8.0.28.0 download interface is empty solution

东数西算拉动千亿产业,敢啃“硬骨头”的存储厂商才更有机会

Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement

User identity used by startup script and login script in group policy

Integrated easy to pay secondary domain name distribution system
![[optics] vortex generation based on MATLAB [including Matlab source code 1927]](/img/9b/b7f462e2ecbff0cee35e7de5c80cf7.jpg)
[optics] vortex generation based on MATLAB [including Matlab source code 1927]

OSPF - detailed explanation of stub area and full stub area

Valentine's Day - make an exclusive digital collection for your lover

FBI warning: some people use AI to disguise themselves as others for remote interview
![[optics] dielectric constant calculation based on MATLAB [including Matlab source code 1926]](/img/cb/ee696d5a7d6bef96fe0db89e8478ed.jpg)
[optics] dielectric constant calculation based on MATLAB [including Matlab source code 1926]
随机推荐
Free year-end report summary template Welfare Collection
application
Free sharing | linefriends hand account inner page | horizontal grid | not for sale
High concurrency architecture cache
How to build an efficient information warehouse
I didn't cancel
Flutter network and data storage framework construction-b1
Pecan — Overview
EGO Planner代码解析bspline_optimizer部分(1)
Simple solution of physical backup and restore of Damon database
Which do MySQL and Oracle learn?
235. The nearest common ancestor of the binary search tree [LCA template + same search path]
Day_ 18 IO stream system
The way to treat feelings
Compared with 4G, what are the advantages of 5g to meet the technical requirements of industry 4.0
Ctrip will implement a 3+2 work system in March, with 3 days on duty and 2 days at home every week
Succession of flutter
【光学】基于matlab涡旋光产生【含Matlab源码 1927期】
Why should the gradient be manually cleared before back propagation in pytorch?
SSM整合-前后台协议联调(列表功能、添加功能、添加功能状态处理、修改功能、删除功能)