//二进制取反 求值
#define CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main1(){
int i, j;
int tmp = 0;
int sum = 0;
scanf("%d", &j);
for (i = 0 ; i < 32; i++, j /= 2){
tmp = j % 2;
sum = sum * 2 + tmp;
}
printf("%d\n", sum);
system(“pause”);
return 0;
}
//不用(a+b)/2 求平均值
#define CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main2(){
double a = 0;
double b = 0;
double c = 0;
printf(“输入两个数:”);
scanf("%d %d",&a,&b);
//a-b = c
if (a > b){
c = (a - b) ;
b = b + (c / 2.0);
printf(“这两个数的平均值为:%d\n”,b);
}
if (a < b){
c = (b - a);
a = a + (c / 2.0);
printf("这两个数的平均值为:%d\n", a);
}
system("pause");
return 0;
}
//" qw we er ets"变成
//“ets er we qw”
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
void change_part(char *a,int i,int j){
char tmp;
for (;i<j; i++, j–){
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
void change_all(char * str)
{
int i;
int start = 0, end = 0;
for (i = 0; str[i]; i++)
{
if (str[i] == ' ')
{
end = i - 1;
change_part(str, start, end);
start = i + 1;
}
}
change_part(str, start, i - 1);
change_part(str, 0, i - 1);
}
int main4_(){
char a[100] = “qw we er rts”;
change_all(a);
puts(a);
system("pause");
return 0;
}
//找到数组中单独出现的数
#define CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main3(){
int i,sum = 0;
int a[10] = { 1, 2, 4, 3, 1, 2, 3, 4, 5, };
for (i = 0; i < 10; i++){
sum ^= a[i];
}
system(“pause”);
return 0;
}