Abundant, deficient and perfect number classifications: Difference between revisions
Abundant, deficient and perfect number classifications (view source)
Revision as of 21:47, 3 October 2018
, 5 years agoTidied 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"▼
sum += p
}
}▼
func main() {▼
for i := 1; i <= 20000; i++ {▼
j := pfacSum(i)
if j < i {
d++
} else if j == i {
p++
} else {
a++
}
}
}</lang>▼
{{out}}▼
<pre>▼
</pre>
Line 3,073 ⟶ 3,112:
180 LET sump=sum
190 RETURN</lang>
▲=={{header|Go}}==
▲package main
▲import "fmt"
▲func main() {
▲var d,a,p,i=0,0,0,1
▲for i=1;i<=20000;i++{
▲}
▲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 {
▲ for p=1;p<=i/2;p++{
▲ y := float64(p)
▲ 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>
|