Computer Science, asked by auroshreemohapatra59, 20 days ago


WAP to display the sum of factors of a number...​

Answers

Answered by DasRicha
1

\huge{ \boxed{ \tt{ \color{navy}{Answer:}}}}

/*

* Author: TheSchoolProgrammer

* www.theschoolprogrammer.com

* Question:Write a program to accept a number and print sum of factors of that number.

*/

import java.util.*;

public class sumFact

{

public static void main()

{

Scanner sc=new Scanner(System.in);

System.out.println("ENTER A NUMBER");

int n=sc.nextInt();

int i,sum=0;

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

{

if(n%i==0)

sum=sum+i;

}

System.out.print("SUM = "+sum);

}

}

Answered by samarthkrv
1

Answer:

import java.util.*;

class factorSum

{

public static void main(String[] args)

{

int sum = 0;

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

Scanner scanner = new Scanner(System.in);

int inp = scanner.nextInt();

 for(int i = 1; i < inp;i++)

 {

 if(inp%i == 0)

  {

  sum = sum + i;

  }

 }

System.out.println("The sum of the factors of " + inp + " is " + sum);

}

}

Explanation:

Similar questions