69,371
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
int if_char();
void main()
{
int i;
printf("please enter something,if there is a letter,\n");
printf("i'll report it and its position in the alphabet.\n");
printf("enter a '&' to end this programme.\n");
while((i=if_char())!=0) //如果是&则结束
{
if(i>0) //如果是字母则显示其在字母表中的位置
printf(" and it's %d in the alphabet.\n",i);
}
printf("Bye!\n");
system("pause");
}
int if_char()
{
int ch;
ch=getchar(); //获取字符
if(ch='&') // 如果是结束符号&则返回0
return 0;
else if((ch>=65&&ch<=90)||(ch>=97&&ch<=122)) //如果是字母则进入字母大小写判别
{
if(ch>=65&&ch<=90) //如果是小写则返回字母ASCII码减64,(a返回1)
{
printf("%c is a letter",ch);
return ch-64;
}
else //如果是大写则返回字母ASCII码减96,(A返回1)
{
printf("%c is a letter",ch);
return ch-96;
}
}
else //非字母返回-1
return -1;
}
#include <stdio.h>
int if_char();
void main()
{
int i;
printf("please enter something,if there is a letter,\n");
printf("i'll report it and its position in the alphabet.\n");
printf("enter a '&' to end this programme.\n");
while((i=if_char())!=0) //如果是&则结束
{
if(i>0) //如果是字母则显示其在字母表中的位置
printf(" and it's %d in the alphabet.\n",i);
}
printf("Bye!\n");
system("pause");
}
int if_char()
{
int ch;
ch=getchar(); //获取字符
if(ch=='&') // 如果是结束符号&则返回0
return 0;
else if((ch>=65&&ch<=90)||(ch>=97&&ch<=122)) //如果是字母则进入字母大小写判别
{
if(ch>=65&&ch<=90) //如果是小写则返回字母ASCII码减64,(a返回1)
{
printf("%c is a letter",ch);
return ch-64;
}
else //如果是大写则返回字母ASCII码减96,(A返回1)
{
printf("%c is a letter",ch);
return ch-96;
}
}
else //非字母返回-1
return -1;
}