跟我从零开始学 C 语言系列(四)
hi!我是渔火。今天开始跟我学,从零开始学C语言(四)
int r; //定义r为整型
float v,f; //定义v,f为单精度浮点型
double x,y; //定义x,y为双精度浮点型
char ch; //定义ch为字符型
//2023.1.28 渔火 by Linux迷 www.linuxmi.com
int main()
{
int a,b,c;
char ch='Y' ;
a=8;
b=a+ch;
scanf("%d",&c);
printf("%d,%d,%d,%c\n",a,b,c,ch);
//2023.1.28 渔火 by Linux迷 www.linuxmi.com
return ;
}
//2023.1.28 渔火 by Linux迷 www.linuxmi.com
int main()
{
int a,b,c,d;
unsigned long e;
a=6;
b=8;
e=10;
c=a+e;
d=b+e;
printf("c=%d,d=%d\n",c,d);
//2023.1.28 渔火 by Linux迷 www.linuxmi.com
return ;
}
//2023.1.28 渔火 by Linux迷 www.linuxmi.com
int main()
{
short int a,b;
a=32767;
b=a+1;
printf("a=%d,b=%d\n",a,b);
//2023.1.28 渔火 by Linux迷 www.linuxmi.com
return ;
}
//2023.1.28 渔火 by Linux迷 www.linuxmi.com
int main()
{
float a=8888.56789;
double b=8888.567895678;
printf("a=%f,b=%f\n",a,b);
//2023.1.28 渔火 by Linux迷 www.linuxmi.com
return ;
}
分析:因为a是单精度浮点型,有效字位数位7位,其中整数已占4位,故3位小数之后的均为数字。但是b是双精度型,有效数字位16位。
//2023.1.28 渔火 by Linux迷 www.linuxmi.com
int main()
{
char y1,y2;
y1='Y';
y2=89;
printf("%c,%c\n",y1,y2);
printf("%d,%d\n",y1,y2);
//2023.1.28 渔火 by Linux迷 www.linuxmi.com
return ;
}
我们可以利用字符变量将大写字母转换为小写字母,也可以将小写字母转换为大写字母。
大写字母转换为小写字母:
//2023.1.28 渔火 by Linux迷 www.linuxmi.com
int main()
{
char y1,y2;
y1='Y';
y2='U';
y1=y1+32;
y2=y2+32;
printf("%c,%c\n",y1,y2);
printf("%d,%d\n",y1,y2);
//2023.1.28 渔火 by Linux迷 www.linuxmi.com
return ;
}
小写字母转换为大写字母:
//2023.1.28 渔火 by Linux迷 www.linuxmi.com
int main()
{
char y1,y2;
y1='y';
y2='u';
y1=y1-32;
y2=y2-32;
printf("%c,%c\n",y1,y2);
printf("%d,%d\n",y1,y2);
//2023.1.28 渔火 by Linux迷 www.linuxmi.com
return ;
}
https://www.linuxmi.com/learn-c-language-from-scratch-1.html
https://www.linuxmi.com/learn-c-language-from-scratch-2.html
https://www.linuxmi.com/learn-c-language-from-scratch-3.html
https://www.linuxmi.com/learn-c-language-from-scratch-4.html
https://www.linuxmi.com/learn-c-language-from-scratch-5.html
相关文章