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 12:14:17 浏览: 73
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
```
阅读全文