1. Given the values of the two shaping variables, the contents of the two values are exchanged.
2. Do not allow creation of temporary variables, exchange two number of content (additional questions)
3. Find the maximum value in 10 integers.
4. Write a function to return the number of 1 in the parameter binary
For example: 15 0000 1111 4 x 1
Program prototypes:
int count_one_bits (unsigned int value)
{
Returns the number of digits in 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 <; 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 <; 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;
}
This article is from the "11132019" blog, please be sure to keep this source http://11142019.blog.51cto.com/11132019/1751438
Swap the value of a variable without using an intermediate variable. Find the number of 1 in a binary binary