QB Program to print the sum of all the factors of an input number.

Linear Program

Cls
Input "A number"; num
For i = 1 To num
If num Mod i = 0 Then
Print i
sum = sum + i
End If
Next
Print "The sum of factors is "; sum
End

Using SUB Program

Cls
Input "A number"; num
Call sum_fact(num)
End

Sub sum_fact (number)
For i = 1 To number
If number Mod i = 0 Then
Print i;
sum = sum + i
End If
Next
Print "The sum of factors is "; sum
End Sub


Using Function Procedure

Cls
Input "A number"; num
f = sum_fact(num)
Print "The sum of factors is "; f
End

Function sum_fact (number)
For i = 1 To number
If number Mod i = 0 Then
Print i;
sum = sum + i
End If
Next
sum_fact = sum
End Function

No comments:

Post a Comment