① c语言编写一个程序,根据用户输入英文名和姓先显示姓氏,其后跟一个逗号,然后显示名的首字母:
//先看基迟租这这代码, 这段代码的可读性不高...... 注释等会.
#include <stdio.h>
int main(void)
{
char first_initial, ch; //这代码写得不好, 打眼一看以为是错的.....
printf("Enter a first and last name: ");
scanf(" %c", &first_initial); //这个是为了保旦慧存名字的第一个字符, 这样剩下的就只剩下名的后面部分和
while (getchar() != ' '); //这样它把名字给输入完了, 因为姓和名中间有空搏兆格
while ((ch = getchar()) != '\n') //输入姓.
if (ch != ' ') //这句感觉没啥用, 因为姓不可能会有空格在里面.
putchar(ch);
printf(", %c.\n", first_initial); //然后把刚刚保存到的名字的首字输出.
return 0;
// 我咋感觉这代码错了.....因为一个getchar后面紧跟一个putchar, 就相当于是, 你在控制台里输入一个1, 结果出来了俩1.
}
② 编写一个用指针数组处理的C程序,实现从键盘输入月份时输出对应的英文名。
#include"stdio.h"
intmain()
{
intm;
char*months[]={"岩此让埋January","February","March","April","May","June","July","August"粗滑迅,"September","October","November","December"};
printf("InputMonth:");
scanf("%d",&m);
printf("Themonthis:%s",*(months+m-1));
}
③ C语言 编写程序,当输入数月份时,显示相应英文月份名称。
#include<stdio.h>
int main(void){
char *month[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
int i;
printf("**************输入0结束循环************ ");
while(1){
printf("请输入月份号:");
scanf("%d",&i);
if(i==0){
闷局 return 0; 悄罩旁
}
启橡 printf("该月的英文名为:%s ",month[i-1]);
}
}
④ c语言程序
#include<stdio.h>
#include<string.h>
intmain(void)
{
哗绝旅charstr[100];
宏扰intcheck=0;
inti=0;
printf("请输入英文名:");
scanf("%s",str);
str[0]=toupper(str[0]);/*首字母大写*/
printf("%s ",str);
for(i=0;'