Computer Science, asked by wajahat50977, 7 months ago

Write a complete algorithm that determines if a given number is a favorite number or not. Use the following definition of a favorite number. The algorithm should take one parameter, the number, and print a message that says if the number is favorite or not. A number N (greater than 0) is said to be favorite if the sum of all its factors equals the number. For example, 6 is a favorite number because 1 + 2 + 3 = 6, and 1, 2 and 3 are favorite of 6. 28 is also a favorite number because 1 + 2 + 4 + 7 + 14 = 28, and the individual numbers are all factors of 28

Answers

Answered by Anonymous
0

Answer:

#include <stdio.h>

int main() {

int num, k, i;

printf("Enter a positive integer: ");

scanf("%d", &num);

printf("Factors of %d are: ", num);

for (i = 1; i <= num; ++i) {

if (num % i == 0) {

k=k+i

printf("%d ", i);

}

}

if(k==num)

{

printf("It's ur favourite number");

}

}

//Mark as brainleist because it takes too much time and efforts to write this kind of algorithms

Similar questions