Write a program to input an integer N and print the sum of all its even digits and sum of all its odd digits separately.
Digits mean numbers, not the places! That is, if the given integer is "13245", even digits are 2 & 4 and odd digits are 1, 3 & 5.
Input format :
Integer N
Output format :
Sum_of_Even_Digits Sum_of_Odd_Digits
(Print first even sum and then odd sum separated by space)
Constraints
0 <= N <= 10^8
import java.util.Scanner;
public class SumEvenAndOddDigits {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an integer N: ");
int N = scanner.nextInt();
int evenSum = 0;
int oddSum = 0;
while (N != 0) {
int digit = N % 10;
if (digit % 2 == 0) {
evenSum += digit;
} else {
oddSum += digit;
}
N /= 10;
}
System.out.println("Sum of even digits: " + evenSum);
System.out.println("Sum of odd digits: " + oddSum);
}
}
a = int(input()) n = [] for _ in range(a): m = int(input()) n.append(m) even = 0 odd = 0 for x in range(0, len(n)): if n[x] % 2 == 0: even = even + n[x] else: odd = odd + n[x] print(even) print(odd) M...read more
Namepace SumOfEvenAndOddDigits
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter an integer: ");
int number = int.Parse(Console.ReadLine());
int sumEven = 0;
int sumOdd = 0;
// C...read more
def sum_of_even_and_odd_digits(N):
even_sum = 0
odd_sum = 0
while N > 0:
digit = N % 10 # Extract the last digit
if digit % 2 == 0: # Check if the digit is even
even_sum += digit
else:
odd_sum += digi...read more
Top Accenture Application Development Associate interview questions & answers
Popular interview questions of Application Development Associate
Top HR questions asked in Accenture Application Development Associate
Reviews
Interviews
Salaries
Users/Month