当前位置:网站首页>第一章:三位阶乘和数,图形点扫描
第一章:三位阶乘和数,图形点扫描
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:没有空格会乱码
边栏推荐
- The necessity of lean production and management in sheet metal industry
- User identity used by startup script and login script in group policy
- ActiveMQ的基础
- Scrape crawler framework
- Zhang Fei hardware 90 day learning notes - personal records on day 2, please see my personal profile / homepage for the complete
- The online customer service system developed by PHP is fully open source without encryption, and supports wechat customer service docking
- math_ Taylor formula
- Luogu-p1107 [bjwc2008] Lei Tao's kitten
- Yolov3 network model building
- Record: solve the problem that MySQL is not an internal or external command environment variable
猜你喜欢
Flutter network and data storage framework construction-b1
Why should we do feature normalization / standardization?
SSM整合-前后台协议联调(列表功能、添加功能、添加功能状态处理、修改功能、删除功能)
Day18 - basis of interface testing
QT -- qfile file read / write operation
东数西算拉动千亿产业,敢啃“硬骨头”的存储厂商才更有机会
记录在模拟器中运行flutter时报的错
Free hand account sharing in September - [cream Nebula]
Why should the gradient be manually cleared before back propagation in pytorch?
[proteus simulation] a simple encrypted electronic password lock designed with 24C04 and 1602LCD
随机推荐
Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement
Why should we do feature normalization / standardization?
Pecan — @expose()
Zhang Fei hardware 90 day learning notes - personal records on day 2, please see my personal profile / homepage for the complete
[wallpaper] (commercially available) 70 wallpaper HD free
leetcode:556. Next larger element III [simulation + change as little as possible]
cipher
Ctrip will implement a 3+2 work system in March, with 3 days on duty and 2 days at home every week
【疾病识别】基于matlab GUI机器视觉肺癌检测系统【含Matlab源码 1922期】
[free sharing] kotalog diary2022 plan electronic manual ledger
Dynamic planning -- expansion topics
math_泰勒公式
Work Measurement - 1
These problems should be paid attention to in the production of enterprise promotional videos
Octopus online ecological chain tour Atocha protocol received near grant worth $50000
[leetcode] [SQL] notes
Processing of user input parameters in shell script
[water quality prediction] water quality prediction based on MATLAB Fuzzy Neural Network [including Matlab source code 1923]
KINGS
Flask generates swagger documents