Mister-小方


私信TA

用户名:1104986125

访问量:239519

签 名:

如此英俊为哪般

等  级
排  名 3
经  验 35781
参赛次数 1
文章发表 68
年  龄 19
在职情况 学生
学  校 大连交通大学
专  业 车辆工程

  自我简介:

解题思路以及注意事项:

  1. 本题主要了解scanf的用法,其格式为            scanf("%d或%c或%f(这里写入你想要输入的变量的格式)",&ch(这里写你想要把输入的值赋给的变量));

  2. 一定要注意输入格式不能错,整型用%d,字符型用%c,浮点型用%f。

  3. &一定不能掉了,掉了编译链接没问题,但运行的时候会崩溃。

实例代码:

#include"stdio.h"
int main()
{
    char ch1,ch2,ch3,ch4,ch5;
    scanf("%c",&ch1);
    scanf("%c",&ch2);
    scanf("%c",&ch3);
    scanf("%c",&ch4);
    scanf("%c",&ch5);
    printf("%c%c%c%c%c",ch1+4,ch2+4,ch3+4,ch4+4,ch5+4);
    return 0;
}

有什么不懂的可以在评论区评论

 

0.0分

210 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区

这个字符型的ch12345,怎么直接与数字相加,不用转为int 然后+4 然后再转为char吗
2019-03-06 12:30:41
#include<stdio.h>
int main()
{
    int c1='C',c2='h',c3='i',c4='n',c5='a';
    printf("%c%c%c%c%c",c1+4,c2+4,c3+4,c4+4,c5+4);
    return 0;
}
2019-03-03 17:52:45
#include<stdio.h>
int main()
{
	char c1,c2,c3,c4,c5;
	scanf("%c%c%c%c%c\n",&c1,&c2,&c3,&c4,&c5);
	printf("%c%c%c%c%c\n",c1+4,c2+4,c3+4,c4+4,c5+4);
     return 0;
}
为什么在scanf哪一行加了一个\n后输入China不行,但输入China+任何一个字或数却行?
2019-02-16 16:25:32
#include <stdio.h>
int main()
{
	char c[5];
	gets(c);
	for(int i=0;i<5;i++)
		c[i]=c[i]+4;
	printf("%s",c);	
}
2019-02-07 19:24:52
char ch1 ch2 ch3 ch4 ch5什么意思?
2019-02-02 19:39:55
他说我代码太短不通过,啥意思。。。。
#include<stdio.h>
int main()
{
    int i;
    char c[5];
    gets(c);
    for(i=0;i<5;i++)
    c[i]=c[i]+4;
    return 0;
}
2019-02-01 18:08:28
#include <stdio.h>
#include<stdlib.h>

 int main()
	 {char a,b,c,d,e;
	  scanf("%c%c%c%c%c",&a,&b,&c,&d,&e);
	  a=a+4;
	  b=b+4;
	  c=c+4;
	  d=d+4;
	  e=e+4;
	  putchar(a);
	  putchar(b);
	  putchar(c);
	  putchar(d);
	  putchar(e);
	  system("pause");
	  return 0;
	 }
本机dev编译通过,结果无误,但提交显示运行错误,这是怎么回事?
2019-01-27 21:27:43
// 这样提交代码不通过
#include<stdio.h>
int main()
{
    char ch;
    
    while ((ch = getchar())!='\n') {
        ch += 4;
        putchar(ch);
    }
    
    printf("\n");
    return 0;
}
2019-01-24 20:05:17