当前位置:网站首页>第一章:三位阶乘和数,图形点扫描
第一章:三位阶乘和数,图形点扫描
2022-07-03 19:16:00 【股_四】
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:没有空格会乱码
边栏推荐
- Flume learning notes
- Dynamic planning -- expansion topics
- How does if ($variable) work? [repeat] - how exactly does if ($variable) work? [duplicate]
- Sqlalchemy - subquery in a where clause - Sqlalchemy - subquery in a where clause
- QT -- qfile file read / write operation
- [mathematical modeling] ship three degree of freedom MMG model based on MATLAB [including Matlab source code 1925]
- Day18 - basis of interface testing
- Sentinel source code analysis part I sentinel overview
- 235. 二叉搜索樹的最近公共祖先【lca模板 + 找路徑相同】
- Simulation scheduling problem of SystemVerilog (1)
猜你喜欢

【学术相关】顶级论文创新点怎么找?中国高校首次获CVPR最佳学生论文奖有感...
![235. Ancêtre public le plus proche de l'arbre de recherche binaire [modèle LCA + même chemin de recherche]](/img/f5/f2d244e7f19e9ddeebf070a1d06dce.png)
235. Ancêtre public le plus proche de l'arbre de recherche binaire [modèle LCA + même chemin de recherche]
![Leetcode: 11. Récipient contenant le plus d'eau [double pointeur + cupidité + enlèvement de la plaque la plus courte]](/img/d4/cbbaec40119be6cb5594899e348261.png)
Leetcode: 11. Récipient contenant le plus d'eau [double pointeur + cupidité + enlèvement de la plaque la plus courte]

Buuctf's different flags and simplerev

The earliest record

Driveseg: dynamic driving scene segmentation data set

Dart JSON编码器和解码器剖析

Yolov3 network model building

我們做了一個智能零售結算平臺

Octopus online ecological chain tour Atocha protocol received near grant worth $50000
随机推荐
C enum contains value - C enum contains value
Thinking about festivals
UE source code analysis: uccharactermovementcomponent - rootmotion
Why should the gradient be manually cleared before back propagation in pytorch?
What is the content of game modeling
Buuctf's different flags and simplerev
The most valuable thing
Basic principle of LSM tree
Record: solve the problem that MySQL is not an internal or external command environment variable
东数西算拉动千亿产业,敢啃“硬骨头”的存储厂商才更有机会
In addition to the prickles that pierce your skin, there are poems and distant places that originally haunt you in plain life
【水质预测】基于matlab模糊神经网络水质预测【含Matlab源码 1923期】
达梦数据库的物理备份和还原简解
QT -- qfile file read / write operation
Ego planner code parsing Bspline_ Optimizer section (1)
【LeetCode】【SQL】刷题笔记
Recommend a GIF processing artifact less than 300K - gifsicle (free download)
Flume learning notes
Zhang Fei hardware 90 day learning notes - personal records on day 2, please see my personal profile / homepage for the complete
application