返回前后字母的程序
A program that returns the letter that comes after and before
我是编程新手。任务是制作一个程序,返回给定字母的pred和succ字母作为输出数据。输入数据是 b 和 z 之间的任何字母。我已经声明了每个字母 b-z 作为自身的变量,并将输入数据声明为字母。但是我该怎么做呢?我能想到的一种方法是将字母定义为彼此的前身/继任者(对于每个字母(。但在我看来,这将需要比必要的更多的代码。
#include <stdio.h>
int main(void)
{
char b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,k,r,s,t,u,v,z;
char letter;
printf("Type a letter between b and z> ");
scanf("%c", &letter);
}
字母的ASCII表示是连续的。所以你能做的是
- 获取输入
- 将 1 加到它以获得继任者 减去
- 1 得到前置任务
- 打印它们。
#include<stdio.h>
int main(){
char c;
scanf("%c",&c);
if( c<='z' && c>='b')
printf("succ = %c pred = %c", c-1, c+1);
else
printf(" You didnt enter between a and z");
return 0;
}
相关文章:
- 为什么这个程序返回最后一个单词而不是最长的单词?
- 当if语句告诉程序返回0时,我的程序不会退出
- 未知的错误导致程序返回怪异的符号
- 程序返回-1073741571而不是永远进行的值
- DLL – 在 DLL 初始化时填充的静态向量,向客户端程序返回零大小
- C - 程序返回值而无需返回语句
- C++线程中调用 std::terminate 时程序返回代码
- 为什么我的程序返回5
- 我如何在不关闭的情况下使这个简单的程序返回
- 用于获取以元音和辅音开头的单词数量的程序返回错误的答案
- 输入将为浮动价值,程序返回整个部分和小数值
- 为什么当我尝试计算平均绝对偏差时,我的程序返回 inf
- 对简单的帐户检查程序有问题?程序返回编译错误,指出"no match for 'operator||' unsure of how to fix?"
- 布尔程序返回错误,即使应该是正确的.简单程序
- 使用自定义删除程序返回unique_ptr的 nullptr 失败
- 如何将命令从c++应用程序返回到父终端
- C 程序返回默认值0
- glGetUniformLocation为所有程序返回相同的值
- 我的程序返回整数值,但即使在显式类型转换之后也应该给出双值
- 这是从信号处理程序返回值的可靠方法吗