0
嘿,我一直在試圖弄清楚這個代碼中的錯誤我應該問用戶一個正整數,然後在每一行上列出第一個emirps 5 ......米只是扁平卡住在這一點..感謝在Prime Emirp C++中需要幫助查找錯誤
#include <iostream>
using namespace std;
int isPrime(int value); //Prototyle for "prime number function"
int reverse (int value2); //Prototype for "emirp function"
int main()
{
//Ask the user for a positive number
cout << "Please enter a positive number: ";
int n;
cin >> n;
//Reject negative value input
if (n < 1)
{
cout << "INVALID NUMBER \n";
}
else
//Calculate all emirps up to 'n'.
for (int test = 0; test < n; test++)
{
int number = 2;
if (isPrime(number))
{
cout << "\n" << reverse(number) << "\t\t\t";
}
}
return 0;
}
int isPrime(int value)
{
//If value is prime, the remainder (count) will be zero twice--for 1 and itself.
int divisor = 1;
int count = 0;
int prime = 0;
if (value % divisor == 0)
{
count++;
++divisor;
}
if ((count = 2))
{
int prime = value; //store prime value in new variable
}
return prime;
}
int reverse(int value2)
{
//reverse the number
value2*=10;
value2 = value2 %10;
value2/=10;
//same procedure as prime function
int divisor2 = 1;
int count2 = 0;
int emirp = 0;
if (value2 % divisor2 == 0)
{//if
count2++;
++divisor2;
}
if ((count2 = 2))
{
int emirp = value2;
}
return emirp;
system ("pause");
縮進符合真正的目的,最好獨立開發新功能。 – Beta 2014-09-24 05:41:12
您提供的代碼將不會編譯,因爲反向函數最終會丟失。 – InvincibleWolf 2014-09-24 05:41:34
它給我的兩個錯誤來自 int prime = value; //將初始值存儲在新變量中int emirp = value2; //////說未使用的變量 – xGrips 2014-09-24 05:54:05