用c语言编写一个程序,从键盘上输入两个字符给字符变量a,b,并输出变量a,b的值。

用c语言编写一个程序,从键盘上输入两个字符给字符变量a,b,并输出变量a,b的值。
第二题编写一个程序,从键盘上输入一个整数,一个浮点数,一个字符分别给三个变量,分别以以下的格式输出:
(1) 整数以10位的宽度输出;
(2)浮点数保留两位小数
(3) 字符型以getchar()函数输入,以putchar()函数输出。

程序代码如下:
#include <stdio.h> //编译预处理命令
int main(int argc, char *argv[]) //主函数,字符的声明
{
char a,b; //定义字符a,b

scanf("%c %c",&a,&b); //输入字符a,b

printf("%c %c\n",a,b);//打印字符a,b

return 0; //返回并且输出a,b
}
扩展知识:
Matlab变量的特点:不需事先声明,也不需指定变量类型,Matlab自动根据所赋予变量的值或对变量所进行的操作来确定变量的类型;在赋值过程中,如果变量已经存在,Matlab会用新值代替旧值,并以新的变量类型代替旧的变量类型。
变量的默认类型为double。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-10-17
#include <stdio.h>
int main()
{
char a,b;
a=getchar();
scanf("%c", &b );
printf("a=%c\n", a );

printf("b=%c\n", b );
return 0;
}

#include <stdio.h>
int main()
{
int i;
double d ;
char c;
printf("input char :" );
c=getchar();
putchar(c);
printf("input integer :" );
scanf("%d", &i );
printf("i=%10d\n", i );

printf("input float:" );
scanf("%lf", &d );
printf("d=%.2lf\n", d );
return 0;
}本回答被提问者和网友采纳
第2个回答  2014-10-17
1、
#include <stdio.h>
int main(int argc, char *argv[])
{
char a,b;

scanf("%c %c",&a,&b);

printf("%c %c\n",a,b);

return 0;
}
2、
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int a;
double b;
char c;

scanf("%d %lf",&a,&b);
getchar();
c=getchar();

printf("%10d %.2lf\n",a,b);
putchar(c);

return 0;
}
相似回答