c语言pta7-1输出星期名
时间: 2024-01-12 16:03:28 浏览: 146
pta C语言编程题-查找书籍
根据引用,C语言代码pta7-1可以实现输入一个1到7的数字,输出对应的星期名的缩写。以下是一个实现该功能的C语言代码示例:
```
#include <stdio.h>
int main() {
int n;
char* s[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
printf("请输入一个数字(1-7):");
scanf("%d", &n);
printf("%s\n", s[n-1]);
return 0;
}
```
这段代码会提示用户输入一个1到7的数字,然后根据输入的数字输出对应的星期名的缩写。例如,输入1会输出"Mon",输入2会输出"Tue",以此类推。注意,由于数组的索引是从0开始的,所以我们需要将输入的数字减去1来得到正确的索引值。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [PTA 第五章算法题汇总](https://blog.csdn.net/billlee7942/article/details/106250002)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [PTA-MOOC《Python程序设计浙江大学》拼题题目集第五章编程题题目及代码答案](https://blog.csdn.net/weixin_45115928/article/details/104516791)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文