Skip to content

P051.c

Problem Statement

Write a program to input two number and check whether they are Amicable Pair or not Example : Sum of Proper Divisors of 220 (1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110) = 284 Sum of Proper Divisors of 284 (1, 2, 4, 71, 142) = 220

Metadata

Property Detail
Author Amit Dutta (amitdutta4255@gmail.com)
License MIT
Difficulty Beginner (index: 1 / 10)

Concepts

Beta Feature

This concept detection system is still in beta and may occasionally show incorrect or incomplete results.

  • Recursion
  • Sorting (possible)
  • Iteration

Actions

Raw View on GitHub

You can print or save this file by opening Raw and using your browser.

Source Code

#include <stdio.h>

int main()
{
    int a, b, i, sa = 0, sb = 0;
    printf("Enter two number : ");
    scanf("%d %d", &a, &b);
    for (i = 1; i <= a / 2; i++)
        if (a % i == 0)
            sa += i;
    for (i = 1; i <= b / 2; i++)
        if (b % i == 0)
            sb += i;
    if (sa == b && sb == a)
        printf("\nInput %d and %d is Amicable Pair.", a, b);
    else
        printf("\nInput %d and %d is Not Amicable Pair.", a, b);
    return 0;
}

Explanation

Explain with AI

Copy the prompt below and paste it into any AI assistant.

    You are explaining a C programming code to a beginner.

    STRICT RULES:

    - Only use the given code. Do NOT assume anything not present.

    - Do NOT add extra examples.

    - Keep explanation clear and short.

    - If something is unclear, say "Not clear from code".

    - Follow the exact format below. Do NOT change headings.

    FORMAT:

    [START]

    ## What it does

    (Explain the overall purpose in 1-2 sentences)

    ## Step-by-step

    (Explain how the code works in steps, simple language)

    ## Key Concepts

    (List concepts like loop, condition, function, etc.)

    ## Notes

    (Mention any limitations, errors, or assumptions)

    [END]

    CODE (P051.c):

    #include <stdio.h>

    int main()
    {
        int a, b, i, sa = 0, sb = 0;
        printf("Enter two number : ");
        scanf("%d %d", &a, &b);
        for (i = 1; i <= a / 2; i++)
            if (a % i == 0)
                sa += i;
        for (i = 1; i <= b / 2; i++)
            if (b % i == 0)
                sb += i;
        if (sa == b && sb == a)
            printf("\nInput %d and %d is Amicable Pair.", a, b);
        else
            printf("\nInput %d and %d is Not Amicable Pair.", a, b);
        return 0;
    }