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();
}
#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
No comments:
Post a Comment