2014-10-27 20 views
-2

任何人都可以給我一些見解,我將如何去做一個簡單的程序在C中,當我輸入例如數字16(代表程序會計算從1-100000開始有多少值恰好有16個因子。 我剛剛開始使用C,所以請詳細說明並使用相當簡單的方法。在一定範圍內具有x個因子數的C數量

到目前爲止,我已經做到了這一點:

#include <stdio.h> 


int main(void) 
{ 
    int n,x=1,y=100000,factors,count; 

    printf(the number of factors:\n"); 
    scanf("%d",&n); 

    for(factors=0;factors<=1;factors++){ 
    if(x%factors==0&&y%factors==0){ 
     count++; 
    } 
    } 

    printf("There are %d numbers between 1 and 100000 inclusive which have exactly %d divisors\n", 
      n,factors); 

    return 0; 
} 
+0

http://stackoverflow.com/questions/26587512/counting-positive-integers-with-a-given-number-of-divisors – BLUEPIXY 2014-10-27 23:45:35

回答

0

編寫返回的因素,一些具有數的函數。然後從1循環到100,000,調用該函數。對於每個與指定號碼匹配的退貨,請遞增計數。然後返回計數。

相關問題