#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
int fib(int n)
{
int num1 = 0;
int num2 = 1;
int num3 = n;
for (int i = 2; i <= n; i++)
{
num3 = num1 + num2;
num1 = num2;
num2 = num3;
}
return num3;
}
int main()
{
int ret = 0;
int n = 0;
printf("请输入要进行计算的数字\n");
scanf("%d", &n);
ret = fib(n);
printf("%d\n", ret);
system("pause");
return 0;
#include<stdio.h>
#include<stdlib.h>
int fib(int n)
{
int num1 = 0;
int num2 = 1;
int num3 = n;
for (int i = 2; i <= n; i++)
{
num3 = num1 + num2;
num1 = num2;
num2 = num3;
}
return num3;
}
int main()
{
int ret = 0;
int n = 0;
printf("请输入要进行计算的数字\n");
scanf("%d", &n);
ret = fib(n);
printf("%d\n", ret);
system("pause");
return 0;
}
//一个数组中只有两个数字是出现一次,其他所有数字都出现了两次//
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
void find_diff(int arr[], int len)
{
int i = 0;
int j = 0;
int num1 = 0;
int num2 = 0;
int flag = 0;
for (i = 0; i < len; i++)
{
flag ^= arr[i];
}
for (j = 0; j < 32; j++)
{
if (((flag >> j) & 1) == 1)
break;
}
for (i = 0; i < len; i++)
if (((arr[i] >> j) & 1) == 0)
num1 ^= arr[i];
else
num2 ^= arr[i];
printf("%d %d \n", num1,num2);
}
int main()
{
int arr[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 7, 8 }; //6和8
int len = sizeof(arr) / sizeof(arr[0]);
find_diff(arr, len);
system("pause");
return 0;
}