Pages

Program to determine Friendly number in C

Friendly number is such number whose sum of the divisor is exactly divisible by that number.

Source Code:
#include <stdio.h>
#include <conio.h>

void main()
{
int i, n, s;
   clrscr();
   s = 0;

  printf("\tProgram to Find Friendly Number.");
   printf("\n\t\t\tEnter numbers:");
   scanf("%d %d", &n);

   for(i = 1; i <= n; i++)  //loop to find divisor
   {
    if(n1 % i == 0)  // condition for divisor
      s += i; //adding divisor
   }

   // check for condition of friendly number
   if(s % n == 0)
    printf("\n\t\t%d is a Friendly Number", n1);
   else
    printf("\n\t\t%d is not a Friendly Number", n1);

   getch();
}

Output:
Program to Find Friendly Number: 6
6 is a Friendly Number

@msucil

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

No comments:

Post a Comment