重新再写个 这个没法用
时间: 2024-02-11 08:25:09 浏览: 24
幸运数是波兰数学家乌拉姆命名的。它采用与生成素数类似的“筛法”生成。首先从1开始写出自然数1,2,3,4,5,6,....1就是第一个幸运数。我们从2这个数开始。把所有序号能被2整除的项删除,变为:1 _ 3 _ 5 _ 7 _ 9 ....即把它们缩紧,再写在下面,形成新的数列:1 3 5 7 9 .... 这时,3将作为下一个幸运数字。然后去掉所有可以被3整除的序号,留下的数列是: 1 3 7 9 13 15 21 25 31 33 37 43 49 51 63 67 69 73 75 79, ...
相关问题
用C语言再写一个
好的,以下是一个使用 C 语言编写的物料管理系统程序示例,您可以根据需要进行修改和完善:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// 定义物料结构体
typedef struct Material {
char code[20]; // 物料编码
char name[50]; // 物料名称
char model[50]; // 物料型号
char process[50]; // 工序
int count; // 数量
char unit[20]; // 单位
char location[50]; // 存放位置
char category[50]; // 物料分类
char in_time[20]; // 入库时间
char warranty_time[20]; // 质保时间
char picture[100]; // 备件图片
int remaining_time; // 剩余时间
} Material;
// 定义物料管理系统结构体
typedef struct MaterialManagementSystem {
Material *materials[1000]; // 存储物料信息的数组
int count; // 物料数量
} MaterialManagementSystem;
// 初始化物料管理系统
void initialize(MaterialManagementSystem *system) {
system->count = 0;
}
// 物料入库
void inbound(MaterialManagementSystem *system) {
Material *material = (Material*)malloc(sizeof(Material));
printf("请输入物料编码:");
scanf("%s", material->code);
printf("请输入物料名称:");
scanf("%s", material->name);
printf("请输入物料型号:");
scanf("%s", material->model);
printf("请输入工序:");
scanf("%s", material->process);
printf("请输入数量:");
scanf("%d", &material->count);
printf("请输入单位:");
scanf("%s", material->unit);
printf("请输入存放位置:");
scanf("%s", material->location);
printf("请输入物料分类:");
scanf("%s", material->category);
printf("请输入入库时间(格式为YYYY-MM-DD):");
scanf("%s", material->in_time);
printf("请输入质保时间(格式为YYYY-MM-DD):");
scanf("%s", material->warranty_time);
printf("请输入备件图片:");
scanf("%s", material->picture);
time_t now = time(NULL);
struct tm *tm_now = localtime(&now);
struct tm tm_warranty_end;
memset(&tm_warranty_end, 0, sizeof(struct tm));
sscanf(material->warranty_time, "%d-%d-%d", &tm_warranty_end.tm_year, &tm_warranty_end.tm_mon, &tm_warranty_end.tm_mday);
tm_warranty_end.tm_year -= 1900;
tm_warranty_end.tm_mon -= 1;
time_t warranty_end_time = mktime(&tm_warranty_end);
double remaining_time = difftime(warranty_end_time, now) / (24 * 60 * 60);
material->remaining_time = (int)remaining_time;
system->materials[system->count++] = material;
printf("物料入库成功!\n");
}
// 物料领用
void outbound(MaterialManagementSystem *system) {
char code[20];
int count;
printf("请输入物料编码:");
scanf("%s", code);
printf("请输入领用数量:");
scanf("%d", &count);
for (int i = 0; i < system->count; i++) {
Material *material = system->materials[i];
if (strcmp(material->code, code) == 0) {
if (material->count >= count) {
material->count -= count;
printf("物料领用成功!\n");
return;
}
else {
printf("库存不足,无法领用!\n");
return;
}
}
}
printf("未找到该物料编码!\n");
}
// 物料查询
void query(MaterialManagementSystem *system) {
char code[20];
printf("请输入物料编码:");
scanf("%s", code);
for (int i = 0; i < system->count; i++) {
Material *material = system->materials[i];
if (strcmp(material->code, code) == 0) {
printf("物料编码:%s\n", material->code);
printf("物料名称:%s\n", material->name);
printf("物料型号:%s\n", material->model);
printf("工序:%s\n", material->process);
printf("数量:%d\n", material->count);
printf("单位:%s\n", material->unit);
printf("存放位置:%s\n", material->location);
printf("物料分类:%s\n", material->category);
printf("入库时间:%s\n", material->in_time);
printf("质保时间:%s\n", material->warranty_time);
printf("剩余时间:%d天\n", material->remaining_time);
printf("备件图片:%s\n", material->picture);
return;
}
}
printf("未找到该物料编码!\n");
}
// 主函数
int main() {
MaterialManagementSystem system;
initialize(&system);
int choice;
while (1) {
printf("请选择操作:\n");
printf("1. 物料入库\n");
printf("2. 物料领用\n");
printf("3. 物料查询\n");
printf("4. 退出程序\n");
scanf("%d", &choice);
switch (choice) {
case 1:
inbound(&system);
break;
case 2:
outbound(&system);
break;
case 3:
query(&system);
break;
case 4:
exit(0);
default:
printf("请输入正确的选项!\n");
break;
}
}
return 0;
}
```
以上是一个使用 C 语言编写的物料管理系统程序示例,您可以根据需要进行修改和完善。
再用c语言写一个景区查找函数
好的,以下是一个简单的景区查找函数的示例代码,供参考:
```c
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 100
struct Spot {
char name[50];
char city[20];
int rating;
};
struct Spot spots[MAX_SIZE];
int num_spots = 0;
void addSpot() {
if (num_spots >= MAX_SIZE) {
printf("无法添加,已达到最大数量!\n");
return;
}
printf("请输入景点名称:");
scanf("%s", spots[num_spots].name);
printf("请输入所在城市:");
scanf("%s", spots[num_spots].city);
printf("请输入评分(1-10):");
scanf("%d", &spots[num_spots].rating);
num_spots++;
printf("已添加!\n");
}
void searchSpot() {
if (num_spots <= 0) {
printf("无法查找,没有景点!\n");
return;
}
char name[50];
printf("请输入要查找的景点名称:");
scanf("%s", name);
int found = 0;
for (int i = 0; i < num_spots; i++) {
if (strcmp(spots[i].name, name) == 0) {
printf("景点名称:%s\n所在城市:%s\n评分:%d\n", spots[i].name, spots[i].city, spots[i].rating);
found = 1;
break;
}
}
if (!found) {
printf("未找到该景点!\n");
}
}
int main() {
int choice = 0;
while (1) {
printf("请选择操作:\n");
printf("1. 添加景点\n");
printf("2. 查找景点\n");
printf("3. 退出\n");
printf("请选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
addSpot();
break;
case 2:
searchSpot();
break;
case 3:
printf("谢谢使用!\n");
return 0;
default:
printf("无效的选择!\n");
}
printf("\n");
}
}
```
这个程序中添加了一个新的函数 `searchSpot()`,用于根据用户输入的景点名称查找并打印对应的景点信息。如果找到了对应的景点,则会输出景点名称、所在城市和评分;否则会提示用户未找到该景点。
主函数中同样使用了一个循环来不断接收用户的选择,以及一个空行来提高程序输出的可读性。
需要注意的是,在实际应用中,查找景区时可能需要使用更高效的数据结构和算法来提高查找速度,比如哈希表、二叉搜索树等。这里只是提供了一个简单的示例代码,如果需要实现更高效的查找功能,可以根据需要进行修改和扩展。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)