編程練習!
#include <iostream>
#include <stdlib.h>
using namespace std;
? ? ? ? ? myNum ? ? ? ? ? ?//填寫命名空間的關鍵字
{
? ? int x = 105;
}
int main()
{
? ? // 使用bool類型定義isOdd,作為狀態位
? ? ? ? ? ? ?isFlag = false; ? ? ??
if(myNum::x % 2 == 0)
{
//改變狀態位的值,使其為false
? ? ? ? ??
}
else
{
? ?//改變狀態位的值,使其為true
? ? ? ? ??
}
? ? // 判斷狀態位的值
if(?)
{
// 如果狀態位的值為true,則打印變量x是奇數
? ? ? ? ?
}
else
{
? ? ? ? // 如果狀態位的值為false,則打印變量x是偶數
}
return 0;
}
請問這個怎么做?
2017-08-01
#include <iostream>
#include <stdlib.h>
using namespace std;
? ? namespace ? ? myNum ? ? ? ? ? ?//填寫命名空間的關鍵字
{
? ? int x = 105;
}
using namespace myNum;
int main()
{
? ? // 使用bool類型定義isOdd,作為狀態位
? ? ? ? bool ? ?isFlag = false; ? ? ??
if(myNum::x % 2 == 0)
{
//改變狀態位的值,使其為false
? ? ? ? isFlag=false;
}
else
{
? ?//改變狀態位的值,使其為true
? ? ? ? isFlag=true;
}
? ? // 判斷狀態位的值
if(isFlag)
{
// 如果狀態位的值為true,則打印變量x是奇數
? ? ? ? cout<<x<<"是奇數"<<endl;
}
else
{
? ? ? ? // 如果狀態位的值為false,則打印變量x是偶數
cout<<x<<"是偶數"<<endl;
}
return 0;
}
2017-03-20
#include <stdlib.h>
#include <iostream>
using namespace std;
int getMaxorMin(int *arr, int count, bool isMax)
{
int temp = arr[0];
for (int i = 0; i < count; i++)
{
if (isMax)
{
if (temp < arr[i])
{
temp = arr[i];
}
}
else
{
if (temp > arr[i])
{
temp = arr[i];
}
}
}
return temp;
}
int main(void)
{
int arr[5] = { 1, 4, 6, 2, 7 };
bool isMax = false;
cin >> isMax;
cout << getMaxorMin(arr, 5, isMax) << endl;
system("pause");
return 0;
}