求绝对值:
#include "stdio.h"
#include "conio.h"
main()
{
int x,y; \\设置变量x,y,类型整数型
printf("please input the x:\n");
scanf("%d",&x); \\输入变量x,类型整数型
if(x>0) y=x;else y=-x; \\如果x>0,y=x ,否则y=-x;
printf("x=%d,|x|=%d\n",x,y); \\打印|x|类型为整数型
getch(); \\使用win-tc的话就要加,vc就不用加;作用停留在结果的画面
}
密码加密:
#include "stdio.h"
main()
{
int d=3; \\定义变量d的值为3,而且为整数型
char ch1,ch2,ch3; \\定义3个变量,类型为字符型
printf("input three better:");
ch1=getchar();
ch2=getchar();
ch3=getchar();
ch1=ch1+d;
ch2=ch2+d;
ch3=ch3+d;
ch1='a'+(ch1-'a')%26; \\变量ch1='a'加了‘’就变成字符串了.. %26,是指 超过26之后就又重头来过
ch2='a'+(ch2-'a')%26;
ch3='a'+(ch3-'a')%26;
putchar(ch1);putchar('\n');
putchar(ch2);putchar('\n');
putchar(ch2);putchar('\n');
getch();
}
0-9数字密码加密:
#include "stdio.h"
main()
{
int d=2;
char ch1,ch2,ch3;
printf("input three better:");
scanf("%c%c%c",&ch1,&ch2,&ch3);
ch1=ch1+d;
ch2=ch2+d;
ch3=ch3+d;
ch1='0'+(ch1-'0')%10;
ch2='0'+(ch2-'0')%10;
ch3='0'+(ch3-'0')%10;
putchar(ch1);
putchar(ch2);
putchar(ch3);
getch();
}