我要讓符合此規則的程序:鑑於來自用戶的輸入「N」計數幸運數字 - C++
,你需要找到1中所有的幸運數字爲n。幸運數字是那些有4或7或兩者都是他們的數字。
我做了這個,但不能管理如何做到這一點的數字比10
#include<iostream>
using namespace std;
int main()
{
int digits, n, count=0;
cout << "Enter upper limit: ";
cin >> n;
for (int i=0; i<n; i++){
if((i==4) || (i==7)){
count++;
}
}
cout << "Number of lucky numbers in given range is " << count;
return 0;
}
這是聰明的想法。 –
這甚至沒有回答這個問題,但它有upvotes。 Rawr – Poriferous