English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

撰寫一支程式,能夠讀取一個整數,並且判斷他是奇數還是偶數
例如
輸入2
畫面就顯示
2為偶數

2007-10-18 11:33:08 · 3 個解答 · 發問者 ? 1 in 電腦與網際網路 程式設計

3 個解答

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("判斷奇偶數");
Console.Write("請輸入一個數字:");

int i = Convert.ToInt32(Console.ReadLine());

if (i % 2 == 0)
{
Console.WriteLine(i + "為偶數");
}
else
{
Console.WriteLine(i + "為奇數");
}
Console.Read();

}
}
}

2007-10-18 11:58:41 · answer #1 · answered by 風中之沙 3 · 0 0

#include
#include
int main(int argc, char* argv[]){
//=====START=====//
int n;
printf("Input a number: "),scanf("%d",&n);
printf("%s\n",(n&1?"Odd":"Even"));
//=====END=====//
system("PAUSE");
return 0;
}

2007-10-18 18:31:49 · answer #2 · answered by Big_John-tw 7 · 0 0

#include
#include

using namespace std;

int main(int argc, char *argv[])
{
int num1,num2;
cout<<"請輸入一個整數\n";
cin>>num1;
num2=num1%2;
if(num2==0)
{cout< else
{cout< system("PAUSE");
return EXIT_SUCCESS;
}
若有不懂的地方歡迎請教

2007-10-18 16:26:28 · answer #3 · answered by ? 1 · 0 0

fedest.com, questions and answers