WAP to input a number and find the average of all the factors
Answers
Answered by
0
Answer:
int N, sum=0, c=0;
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
for(int i=0; i<=N; i++)
{
if(N%i==0)
{
c++;
sum = sum+i;
}
}
avg = sum/c;
System.out.println(avg);
Explanation:
Take N as input
Run a loop from 1 to N
If N is divisible by the loop index, add 1 to the counter, and add it onto the sum as well.
end loop
divide sum by the final counter value for average
Similar questions