当前位置:网站首页>第一章:三位阶乘和数,图形点扫描
第一章:三位阶乘和数,图形点扫描
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:没有空格会乱码
边栏推荐
- Smart wax therapy machine based on STM32 and smart cloud
- Common text labels
- The installation path cannot be selected when installing MySQL 8.0.23
- Analyse du Code du planificateur ego bspline Section Optimizer (1)
- Free hand account sharing in September - [cream Nebula]
- 2020 intermediate financial management (escort class)
- math_ Taylor formula
- High concurrency Architecture - read write separation
- Free year-end report summary template Welfare Collection
- High concurrency architecture cache
猜你喜欢
Ctrip will implement a 3+2 work system in March, with 3 days on duty and 2 days at home every week
EGO Planner代码解析bspline_optimizer部分(2)
SQL injection for Web Security (1)
ActiveMQ的基础
SSM integration - joint debugging of front and rear protocols (list function, add function, add function status processing, modify function, delete function)
[academic related] how to find the innovation of top papers? Chinese universities won the CVPR Best Student Thesis Award for the first time
If the warehouse management communication is not in place, what problems will occur?
Dart JSON编码器和解码器剖析
235. The nearest common ancestor of the binary search tree [LCA template + same search path]
【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁
随机推荐
High concurrency Architecture - distributed search engine (ES)
Streaming media server (16) -- figure out the difference between live broadcast and on-demand
为什么要做特征的归一化/标准化?
Zhang Fei hardware 90 day learning notes - personal records on day 2, please see my personal profile / homepage for the complete
Record: install MySQL on ubuntu18.04
Sentinel source code analysis part I sentinel overview
我眼中真正优秀的CTO长啥样
【光学】基于matlab介电常数计算【含Matlab源码 1926期】
Bad mentality leads to different results
Ego planner code parsing Bspline_ Optimizer section (1)
Free hand account sharing in September - [cream Nebula]
“google is not defined” when using Google Maps V3 in Firefox remotely
Pecan — @expose()
FBI警告:有人利用AI换脸冒充他人身份进行远程面试
[academic related] how to find the innovation of top papers? Chinese universities won the CVPR Best Student Thesis Award for the first time
Latex image rotates with title
P1891 crazy LCM (Euler function)
The more you talk, the more your stupidity will be exposed.
【疾病识别】基于matlab GUI机器视觉肺癌检测系统【含Matlab源码 1922期】
Ctrip will implement a 3+2 work system in March, with 3 days on duty and 2 days at home every week