Abundant, deficient and perfect number classifications: Difference between revisions

Tidied up Go entry and moved it into correct alphabetical order.
(Added K program for number classification into Abundant, Perfect and Deficient)
(Tidied up Go entry and moved it into correct alphabetical order.)
Line 1,109:
Number perfect 4
Number abundant 4953
</pre>
 
=={{header|Go}}==
<lang go>package main
 
import "fmt"
 
func pfac_sumpfacSum(i int) int {
sum := sum+p0
for p := 1; p <= i/2; p++ {
if yi%p :== float64(p)0 {
sum += p
}
}
return sum
 
func main() {
var d, a, p,i = 0, 0, 0,1
for i := 1; i <= 20000; i++ {
j := pfacSum(i)
if j < i {
d++
} else if j == i {
p++
} else {
a++
}
}
fmt.Printf("thereThere are %d deficient numbers b/wbetween 1 and 20000\n", d)
fmt.Printf("thereThere are %d abundant numbers b/w between 1 and 20000\n", a)
fmt.Printf("thereThere are %d perfect numbers b/wbetween 1 and 20000\n", p)
}</lang>
 
{{out}}
<pre>
thereThere are 15043 deficient numbers b/wbetween 1 and 20000
thereThere are 4953 abundant numbers b/w between 1 and 20000
thereThere are 4 perfect numbers b/wbetween 1 and 20000
</pre>
 
Line 3,073 ⟶ 3,112:
180 LET sump=sum
190 RETURN</lang>
=={{header|Go}}==
<lang Go>
package main
 
import "fmt"
 
import "math"
 
func main() {
 
var d,a,p,i=0,0,0,1
 
for i=1;i<=20000;i++{
 
if pfac_sum(i)<i{
 
d++
 
}else if pfac_sum(i)==i{
 
p++
 
}else{
a++
}
fmt.Printf("there are %d deficient numbers b/w 1 and 20000\n", d)
fmt.Printf("there are %d abundant numbers b/w 1 and 20000\n", a)
fmt.Printf("there are %d perfect numbers b/w 1 and 20000\n",p)
}
func pfac_sum(i int) int {
var p,sum=1,0
for p=1;p<=i/2;p++{
x := float64(i)
y := float64(p)
if math.Mod(x,y)==0{
sum= sum+p
}
}
return sum
}
</lang>
{{out}}
<pre>
there are 15043 deficient numbers b/w 1 and 20000
there are 4953 abundant numbers b/w 1 and 20000
there are 4 perfect numbers b/w 1 and 20000
</pre>
9,485

edits