Computer Science, asked by PuruVyas, 6 months ago

Write a java program to find out the sum of factors of number using for loop.

p.s: don't write anything if you don't have the answer please this will be really helpful of I only get the answer (not from google)

Answers

Answered by anindyaadhikari13
1

Question:-

Write a Java program to find the sum of factors of a number using for loop.

Solution:-

Here is your program written in Java.

import java.util.*;

class Sum

{

public static void main(String args[])

{

int n, s=0, i;

Scanner sc=new Scanner(System.in);

System.out.print("Enter a number: ");

int n=sc.nextInt();

for(i=1;i<=n;i++)

{

if(n%i==0)

s+=i;

}

System.out.println("Sum of factors is: "+s);

// @AnindyaAdhikari

}

}

Similar questions