c程序填空

来源:百度知道 编辑:UC知道 时间:2024/06/19 12:14:30
已知24有8个因子,而24正好被8整除。求[100,300]之间有多少个整数能被其因子的个数整除,将下列程序补充完整,正确结果填入相应窗口。
程序:
#include <conio.h>
#include <stdio.h>
#include <math.h>
main()
{
int a,b,c,n,count=0;
for (a=100; a<=300; a++)
{
________
for (c=1;c<=a;c++)
if ( _______ )
b+=1;
if (a%b==0)
{
count++;
}
}
printf("\n count = %d",count);
}

分析了一下题,理解一下定义的各变量的意义就知道怎么做了。
  a用来表示被除的数,就是100到300中间的数中的一个。
  b用来记录a的因子的个数。
  c用来做除数,就是从1到a中间的数。也就是a的因子。
  n好像没有用到这个变量
  count用来记录a中有多少个能被自己因子整除的数的总数。

  ①b=0; //每次应当把b的值清0
  ②a%c==0; //判断a是否能被c整除,若能整除,c就是因子。

  我没有下载C的调式环境。你自己试一下对不对。

  我用VB试了下,成功。语法上有一点差别,希望能给你提供参考。
  Private Sub Command1_Click()
  Dim a, b, c, n, count As Integer
  Dim str As String
  count = 0 '记录符合条件的数的总个数
  For a = 100 To 300
  b = 0 '记录因子个数
  str = ""
  For c = 1 To a
  If (a Mod c) = 0 Then
  b = b + 1 '若是因子,就记录因子个数。
  str = str & "/" & c '把所有的因子都记录在str变量中
  End If
  Next
  If (a Mod b) = 0 Then
  count = count + 1
  Print a & ">>" & str '打印出所有符合条件的数,后边打印出相应的因子
  End If
  Next
  Print "共有" & count & "个能被自己的因子数整除的数"
  End Sub

#include <conio.h>
#include <