idastan97

CSCI151 L16 P5

Sep 27th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. _Bool isIdeal(int n){
  5.     int i, s=1;
  6.     for (i=2; i<=sqrt(n); i++){
  7.         if (n%i==0) {
  8.             s+=i;
  9.             if (i!=sqrt(n))s+=(n/i);
  10.         }
  11.     }
  12.     if (n==1) return 0;
  13.     return (n==s);
  14. }
  15.  
  16. int main(){
  17.     int n;
  18.     scanf("%i", &n);
  19.     if (isIdeal(n)) printf("This number is ideal.");
  20.     else printf("This number is not ideal.");
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment