标签:exchange include system return 二进制
1.给定两个整形变量的值,将两个值的内容进行交换。
2. 不允许创建临时变量,交换两个数的内容(附加题)
3. 求10 个整数中最大值。
4. 写一个函数返回参数二进制中 1 的个数
比如: 15 0000 1111 4 个 1
程序原型:
int count_one_bits(unsigned int value)
{
// 返回 1的位数
}
#include<stdio.h>
#include<stdlib.h>
void exchange(int *num1, int *num2)
{
int tmp;
tmp = *num1;
*num1 = *num2;
*num2 = tmp;
}
int main()
{
int num1=0;
int num2=0;
scanf("%d%d", &num1, &num2);
printf("num1=%d num2=%d\n", num1, num2);
exchange(&num1,&num2);
printf("num1=%d num2=%d\n", num1, num2);
system("pause");
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int num1=0;
int num2=0;
scanf("%d%d", &num1, &num2);
printf("num1=%d num2=%d\n", num1, num2);
num1 = num1 + num2;
num2 = num1 - num2;
num1 = num1 - num2;
printf("num1=%d num2=%d\n", num1, num2);
system("pause");
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int max_num(int *p)
{
int i = 0;
for (i = 0; i <9; i++)
{
if (p[i]>p[i + 1])
{
p[i + 1] = p[i];
}
}
return p[9];
}
int main()
{
int arr[10];
for (int i = 0; i < 10; i++)
{
scanf("%d", &arr[i]);
}
int ret = max_num(arr);
printf("%d\n", ret);
system("pause");
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int count_one_bits(unsigned int value)
{
int count = 0;
for (int i = 0; i < 32; i++)
{
if (value & 1 == 1)
{
count++;
}
value = value >> 1;
}
return count;
}
int main()
{
unsigned int value= 0;
scanf("%d", &value);
int ret = count_one_bits(value);
printf("%d\n", ret);
system("pause");
return 0;
}
本文出自 “11132019” 博客,请务必保留此出处http://11142019.blog.51cto.com/11132019/1751438
标签:exchange include system return 二进制
原文地址:http://11142019.blog.51cto.com/11132019/1751438