मराठी

WAmicable Number Definition: The number n is amicable if it belongs to an amicable pair. Two numbers n and m are called an amicable pair if the sum of all positive divisors of n and the sum of all

Advertisements
Advertisements

प्रश्न

WAmicable Number Definition: The number n is amicable if it belongs to an amicable pair. Two numbers n and m are called an amicable pair if the sum of all positive divisors of n and the sum of all positive divisors of m are equal to (n + m).

First ten such numbers: 220, 284, 1184, 1210, 2620, 2924, 5020, 5564, 6232, 6368. Declare a class named Numbers contain a method AmicableNos(int, int) that will check both the numbers are of Amicable pairs or not. Appropriate error message should be given in case.

कोड लेखन
Advertisements

उत्तर

import java.io.*;
class Amicable2
{
   public static void AmicableNos(int m, int n)
   {
      int i,f1=0,f2=0;
      for(i=1;i<m;i++)
      {
         if(m%i= =0)
         f1+=i;
      }
      for(i=l<n;i++)
      {
         if(n%i==0)
         f2+=i;
      }
      f((f1+f2)= =(m+n))
         System.out.println("Amicable pair:"+m+","+n);
      else
         System.out.println("Both are not amicable pair");
      }
      public static void main()
      {
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         System.out.println("Enter 2 numbers");
         int m=Integer.parseInt(br.readLine());
         int n=Integer.parseInt(br.readLine());
         AmicableNos(m,n);
   }
}
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 1: Revision of Class 9 Syllabus - Exercises [पृष्ठ ४९]

APPEARS IN

रूपा पंडित Computer Applications [English] Class 10 ICSE
पाठ 1 Revision of Class 9 Syllabus
Exercises | Q 10. | पृष्ठ ४९
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×