当前位置:网站首页>C语言函数作业
C语言函数作业
2022-07-20 05:28:00 【bjfu_yang】
今日作业
1、
我的代码:
#include<stdio.h>
#pragma warning(disable:4996)
bool IsWord(char a)
{
if (((a >= 65) && (a <= 90)) || ((a >= 97) && (a <= 122)))
{
return true;
}
else
{
return false;
}
}
int location(char a)
{
if (a < 97)
{
return a - 64;
}
else
{
return a - 96;
}
}
void input()
{
char a;
while (scanf("%c", &a) != EOF)
{
if (IsWord(a))
{
printf("该字符是字母,在字母表的位置是:%d\n",location(a));
}
else
{
printf("该字符不是数字!\n");
}
}
}
int main()
{
input();
return 0;
}
2、
我的代码:
#include<stdio.h>
#define MAX 10
#pragma warning(disable:4996)
void menu()
{
printf(" ----------数组处理系统----------\n");
printf("\n");
printf(" ----------输入数组-------------1\n");
printf("\n");
printf(" ----------输出数组-------------2\n");
printf("\n");
printf(" ----------排序数组-------------3\n");
printf("\n");
printf(" ----------逆序数组-------------4\n");
printf("\n");
printf(" ----------退出-----------------0\n");
printf("\n");
}
void array_input(int a[])
{
printf("请输入数组:\n");
for (int i = 0; i < MAX; i++)
{
scanf("%d", &a[i]);
}
printf("输入数组完毕!\n");
printf("\n");
}
void array_output(int a[])
{
for (int i = 0; i < MAX; i++)
{
printf("%d\n", a[i]);
}
printf("输出数组完毕!\n");
printf("\n");
}
void array_sort(int a[])
{
int i, j;
int temp, minIndex;
for (i = 0; i < MAX; i++)
{
minIndex = i;
for (j = i + 1; j < MAX; j++)
{
if (a[j] < a[minIndex])
{
minIndex = j;
}
}
temp = a[i];
a[i] = a[minIndex];
a[minIndex] = temp;
}
printf("排序数组完毕!\n");
printf("\n");
}
void array_reverse(int b[])
{
int temp;
for (int i = 0; i < MAX / 2; i++)
{
temp = b[i];
b[i] = b[MAX - i - 1];
b[MAX - i - 1] = temp;
}
printf("逆序数组完毕!\n");
printf("\n");
}
int main()
{
int a[MAX];
for (int i = 0; i < MAX; i++)
{
a[i] = 0;
}
int b[MAX];
for (int i=0; i < MAX; i++)
{
b[i] = a[i];
}
int choose;
while (1)
{
menu();
printf("请输入选择:\n");
scanf("%d", &choose);
switch (choose)
{
case 1:
array_input(a);
break;
case 2:
array_output(a);
break;
case 3:
array_sort(a);
break;
case 4:
printf("原数组逆序:");
array_reverse(b);
break;
case 0:
break;
default:
printf("输入错误!");
break;
}
}
return 0;
}
代码简简单单写,不是完美的代码,请大家多多帮助
边栏推荐
- Apache Doris ODBC Mysql外表在Ubuntu下使用方法及配置
- Would you like to ask me if I can synchronize the data of MySQL database built on ECs to MC, and use binlog to synchronize and formulate
- Partial voice feature recording
- Apache Doris ODBC appearance PostgreSQL User Guide
- DOM之事件对象
- Software testing career development direction (don't be confused, roll up quickly)
- J9数字平台论:元宇宙中DeFi的可能性和局限性
- 30 spark introduction: Spark Technology stack explanation, partition, system architecture, operator and task submission method
- Mysql 我随手造200W条数据,给你们讲讲分页优化。
- 浏览器工作原理剖析
猜你喜欢
[scientific literature measurement] statistics and visualization of word number and frequency of Chinese and English literature titles and abstracts
使用renren-generator逆向生成CRUD代码
CTFshow-web入门信息收集-wp(1-20) (详解)
[scientific literature measurement] keyword mining and visualization
二叉树实现(根据层级数组生成二叉树)
一文了解 NebulaGraph 上的 Spark 项目
How to choose data application development language and environment
RPC:Thrift框架
Apache Doris 使用 Prometheus Alertmanager 模块发送 异常信息至钉钉报警群
Mysql 我随手造200W条数据,给你们讲讲分页优化。
随机推荐
J9 Digital Platform Theory: the possibilities and limitations of defi in the metauniverse
基于Ansible实现Apache Doris快速部署运维指南
Apache Doris ODBC Mysql外表在Ubuntu下使用方法及配置
[AD learning record] Why are schematic diagrams and PCBs in the same folder, and PCB cannot be generated?
硅谷课堂笔记(上)
Binary tree implementation (generate binary tree according to hierarchical array)
算法面试问题
Idea starts the same project multiple times
STL list constructor, size
Technical dry goods | mindspire self-developed high-order optimizer source code analysis and practical application
Dictionary preface - company naming
解决OpenCV读取视频结束后报错的问题
【微信小程序】:分页请求数据、上拉加载、下拉刷新。
CentOS下Apache Doris Oracle ODBC外表使用指南
ES6新增二(字符串,数组)
Apache Doris Grafana监控指标介绍
Release test
An interesting example to illustrate the difference of emplace_ back() and push_ back()
In depth understanding of MySQL execution process and execution sequence
MATLAB数字图像处理 实验五:形态学图像处理