intmain..._a65a97">
赞
踩
day1
1.大小写字母转换ASCII码
A65 a97 (大写转小写+32,小写转大写-32)
#include <stdio.h>
int main()
{
char a;
printf("Input a:");
scanf("%c",&a);
a=a-32;
printf("%c",a);
return 0;
}
2.倒换整数顺序(将数值转换为数字)
#include <stdio.h>
int main()
{
int a,b,c,x;
printf("Input x:");
scanf("%d",&x);
a=x/100;
b=(x-a*100)/10;
c=x%10;
printf("%d",c*100+b*10+a);
return 0;
}
3.倒换小数/字符顺序(注意录入格式)
#include <stdio.h>
int main()
{
char a,b,c,d;
scanf("%c%c%c.%c",&a,&b,&c,&d);
printf("%c%c%c.%c",d,c,b,a);
return 0;
}
4.switch语句的使用(char/int) 注意符号
char型
char op;
switch(op)
{
case '+': (case后有空格!!!)
printf("%d+%d=%d",a,b,a+b);
break;
}
int型
int a;
switch(a)
{
case 1:
printf("i love u");
break;
}
5.算面积的数学公式 (sqrt()求根函数)
#include <stdio.h>
#include <math.h>
int main()
{
double a,b,c,s,p;
printf("Input a,b,c:");
scanf("%lf %lf %lf",&a,&b,&c);
p=(a+b+c)/2;
s=sqrt(p*(p-a)*(p-b)*(p-c));
printf("%.1lf",s);
return 0;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。