Absolute Difference Multiples

The program must accept two integers N1 and N2 as the input. The program must print the first 10 multiples of their absolute difference (N1 and N2) as the output.

Example Input/Output 1:
Input:
5 8

Output:
3 6 9 12 15 18 21 24 27 30

Example Input/Output 2:
Input:
7 5

Output:
2 4 6 8 10 12 14 16 18 20

#include <stdio.h>

int main()
{
    int N1,N2;
    scanf("%d%d",&N1,&N2);
    int difference=N1-N2;
    if(difference<0)
    {
        difference=difference*(-1);
    }
    for(int ctr=1;ctr<=10;ctr++)
    {
        printf("%d ",ctr*difference);
    }
}
import java.util.*;

public class Hello {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N1 = sc.nextInt();
        int N2 = sc.nextInt();
        int difference = N1 - N2;
        if (difference < 0) {
            difference = difference * (-1);
        }
        for (int ctr = 1; ctr <= 10; ctr++) {
            System.out.print(ctr * difference + " ");
        }
    }
}
num1, num2 = map(int, input().split())
difference = abs(num1-num2)
for ctr in range(1, 11):
print(ctr*difference, end = " ")
#include <iostream>
using namespace std;

int main()
{
    int N1, N2;
    cin >> N1 >> N2;
    int diff = abs(N1 - N2);
    for(int ctr = 1; ctr <= 10; ctr++)
    {
        cout << ctr*diff << " ";
    }
    return 0;
}
Previous Article

Alphanumeric Palindrome

Next Article

Magical Board Game

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *