交换两值
#include<stdio.h>
#include<windows.h>
int main()
{
int a , b , c ;
scanf("%d%d", &a, &b);
c = a;
a = b;
b = c;
printf("%d %d\n", a, b);
system("pause");
return 0;
}
无临时变量交换两值
#include<stdio.h>
#include<windows.h>
int main()
{
int a = 0, b = 0;
scanf("%d%d", &a, &b);
a = a + b;
b = a - b;
a = a - b;
printf("%d %d\n", a, b);
system("pause");
return 0;
}
十个数最大值
#include<stdio.h>
#include<windows.h>
int main()
{
int max = 0;
int arr[10] = { 0 };
int i;
printf("enter 10 integer numbers:");
for (i = 0; i < 10; i++)
{
scanf("%d",&arr[i]);
}
for (i = 0; i < 10; i++)
{
if (arr[i]>=max)
{
max = arr[i];
}
}
printf("The largest number is %d\n", max);
system("pause");
return 0;
}
二进制1的个数
#include<stdio.h>
#include<windows.h>
int count_one_bits(unsigned int value);
int main()
{
int num,COUNT;
scanf("%d",&num);
COUNT = count_one_bits(num);//计算二进制中的1的个数
printf("%d\n",COUNT );
system("pause");
return 0;
}
int count_one_bits(unsigned int value)
{
int count=0;
while (value)
{
value = value&(value - 1);//按位与&
count++;
}
return count;
}
小题练习
最新推荐文章于 2023-06-21 18:16:13 发布