Write a program in C to fulfil the following requirements. Write a function that will accept an integer as an parameter. Check whether it forms a friendly pair or not. If it forms a friendly pair with a different number then the function will return that number. If the number is not friendly or friend to itself or the given number was negative the function will return 0. (two numbers are friendly if the summation of true factors of the first number is the second one and the summation of true factors of the second number is the first number). The number 6 is friendly to itself hence do not form a friendly pair. The factors of a number that are not equal to the number itself are called “True factors”. Write a function that will return the LCM of two positive integers sent as parameter. And will return 0 if parameters are invalid. Design a structure in the program that will have four integers and a real number as its member. Write a function that will display the information stored in a structure variable of the above type sent as a parameter. All five members should be displayed in a single line, and separated by TAB. The main function will accept an integer larger than 5000. The program should be able to find all the unique friendly number pairs. (ie. if A, B are found to be friendly, B and A should not be declared again as friendly again). The first output for a valid input should be the total number of friendly pairs found in the given range. Then it should display the following information for each of the friendly pairs separated by TAB and in one line for one pair in the format - Smaller one of the friendly pair, Larger one of the friendly pair, HCF or GCD of the friendly pair and LCM of the friendly pair and the average of the friendly pair. After producing the above output, program should display the integer value equivalent to the bitstring of the average of each of the friendly pair. (Hint. For any of the friendly pair you will get a value that is greater than 1 crore) The program should waste as less as p
Answers
Answer:
#include<stdio.h>
int main()
{
//1 Create two variables to use in first and second numbers
int i;
int f_Num,s_Num;
//2 two more variables created to store the sum of the divisors
int f_DivisorSum = 0;
int s_DivisorSum = 0;
//3 Asking user to enter the two numbers
printf("Enter two numbers to check if Amicable or not : ");
scanf("%d %d",&f_Num,&s_Num);
//4 Using one variable for loop and second to check for each number
for(int i=1;i<f_Num;i++)
{
//5 Condition check
if(f_Num % i == 0)
f_DivisorSum = f_DivisorSum + i;
}
//6 Calculating the sum of all divisors
for(int i=1;i<s_Num;i++)
{
if(s_Num % i == 0)
s_DivisorSum = s_DivisorSum + i;
}
//7 Check condition for friendly numbers
if((f_Num == s_DivisorSum) && (s_Num == f_DivisorSum))
else
{
printf("%d and %d are not Amicable numbers\n",f_Num,s_Num);
}
return 0;
}
Explanation: