c语言编写,1. 打印100以内的质数2. 使用while循环在/project目录下通过随机小写10个字母加固定字符串project批量创建10个html文件。例如:coaolvajcq_project.html3. 将以上文件名中的project全部改成task (用for循环实现),并且html改成大写HTML4. bash for循环打印下面这句话中字母数不大于6的单词real estate price increases in shanghai retreated by nearly 7% last year

时间: 2024-02-01 08:14:17 浏览: 29
1. 打印100以内的质数 ```c #include <stdio.h> int main() { int i, j, flag; for (i = 2; i <= 100; i++) { flag = 1; for (j = 2; j <= i / 2; j++) { if (i % j == 0) { flag = 0; break; } } if (flag == 1) { printf("%d ", i); } } return 0; } ``` 2. 使用while循环在/project目录下通过随机小写10个字母加固定字符串project批量创建10个html文件。例如:coaolvajcq_project.html ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> int main() { char filename[30]; int i = 1; srand(time(NULL)); while (i <= 10) { sprintf(filename, "/project/%c%c%c%c%c%c%c%c%c%c_project.html", rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a'); FILE *fp = fopen(filename, "w"); if (fp != NULL) { fclose(fp); i++; } } return 0; } ``` 3. 将以上文件名中的project全部改成task (用for循环实现),并且html改成大写HTML ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> int main() { char filename[30]; int i = 1; srand(time(NULL)); while (i <= 10) { sprintf(filename, "/project/%c%c%c%c%c%c%c%c%c%c_project.html", rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a'); FILE *fp = fopen(filename, "w"); if (fp != NULL) { fclose(fp); i++; } } for (i = 1; i <= 10; i++) { sprintf(filename, "/project/%c%c%c%c%c%c%c%c%c%c_project.html", rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a', rand() % 26 + 'a'); char *pos = strstr(filename, "_project.html"); if (pos != NULL) { memcpy(pos, "_task.HTML", 10); } rename(filename, "/project/newname"); } return 0; } ``` 4. bash for循环打印下面这句话中字母数不大于6的单词real estate price increases in shanghai retreated by nearly 7% last year ```bash for word in real estate price in by 7% last; do echo $word; done ```

相关推荐

最新推荐

recommend-type

C语言实现输入一个字符串后打印出该字符串中字符的所有排列

主要介绍了C语言实现输入一个字符串后打印出该字符串中字符的所有排列的方法,是数学中非常实用的排列算法,需要的朋友可以参考下
recommend-type

使用c语言判断100以内素数的示例(c语言求素数)

主要介绍了使用c语言判断100以内素数的示例(c语言求素数),需要的朋友可以参考下
recommend-type

C语言之实现字符串小写变大写的实例

主要介绍了C语言之实现字符串小写变大写的实例的相关资料,需要的朋友可以参考下
recommend-type

C语言中查找字符在字符串中出现的位置的方法

主要介绍了C语言中查找字符在字符串中出现的位置的方法,分别是strchr()函数和strrchr()函数的使用,需要的朋友可以参考下
recommend-type

C语言字符串快速压缩算法代码

主要介绍了C语言字符串快速压缩算法代码,将字符串中连续出席的重复字母进行压缩,其主要的压缩字段的格式为”字符重复的次数+字符”。有需要的小伙伴参考下吧。
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB图像处理算法宝典:从理论到实战

![MATLAB图像处理算法宝典:从理论到实战](https://img-blog.csdnimg.cn/20200717112736401.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2d1emhhbzk5MDE=,size_16,color_FFFFFF,t_70) # 1. MATLAB图像处理基础理论 MATLAB图像处理是一种利用MATLAB编程语言进行图像处理的强大工具。它提供了丰富的函数和工具箱,用于图像获取、增强、分
recommend-type

matlab中1/x的非线性规划

在MATLAB中,可以使用非线性规划函数(`fmincon`)来优化一个包含1/x的非线性目标函数。下面是一个简单的例子: ```matlab % 定义目标函数 fun = @(x) 1/x; % 定义约束函数(这里没有约束) nonlcon = []; % 定义初始点 x0 = 1; % 定义优化选项 options = optimoptions('fmincon', 'Display', 'iter'); % 进行非线性规划 [x, fval] = fmincon(fun, x0, [], [], [], [], [], [], nonlcon, options); ``` 在
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。