Accept an integer A as the input. If A is a positive integer then print the first five multiples of the unit digit of A as the output. If A is a negative integer then print the first ten multiples of the unit digit of A as the output.
Example Input/Output 1:
Input:
46
Output:
6 12 18 24 30
Example Input/Output 2:
Input:
-53
Output:
3 6 9 12 15 18 21 24 27 30
#include <stdio.h>
int main()
{
int num, ctr, value;
scanf("%d", &num);
if(num > 0)
{
value = num % 10;
for(ctr = 1; ctr <= 5; ctr++)
{
printf("%d ", value * ctr);
}
}
else
{
value = (num % 10) * (-1);
for(ctr = 1; ctr <= 10; ctr++)
{
printf("%d ", value * ctr);
}
}
}
import java.util.*;
public class Hello {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int ctr, value;
if (num > 0) {
value = num % 10;
for (ctr = 1; ctr <= 5; ctr++) {
System.out.print(value * ctr + " ");
}
} else {
value = (num % 10) * (-1);
for (ctr = 1; ctr <= 10; ctr++) {
System.out.print(value * ctr + " ");
}
}
}
}
num = int(input())
if num > 0:
unit = num%10
for ctr in range(1, 6):
print(ctr*unit, end = " ")
else:
unit = (num*-1)%10
for ctr in range(1, 11):
print(ctr*unit, end = " ")
#include <iostream>
using namespace std;
int main()
{
int num, ctr, value;
cin >> num;
if(num > 0)
{
value = num % 10;
for(ctr = 1; ctr <= 5; ctr++)
{
cout << (value * ctr) << " ";
}
}
else
{
value = (num % 10) * (-1);
for(ctr = 1; ctr <= 10; ctr++)
{
cout << (value * ctr) << " ";
}
}
return 0;
}
Leave a Reply