Sum of Even & Odd Digits Problem Statement
Create a program that accepts an integer N
and outputs two sums: the sum of all even digits and the sum of all odd digits found in the integer.
Explanation:
Digits refer to the numbers themselves, not their positional values. For example, if N
is "13245", the even digits are 2 & 4, and the odd digits are 1, 3 & 5.
Input:
Integer N
Output:
Sum_of_Even_Digits Sum_of_Odd_Digits
First print the sum of even digits, followed by the sum of odd digits, separated by a space.
Example:
Input:
13245
Output:
6 9
Explanation:
In the input 13245
, the even digits are 2 and 4, summing to 6. The odd digits are 1, 3, and 5, summing to 9.
Constraints:
0 <= N <= 10^8
Create a program to find the sum of even and odd digits in an integer.
Iterate through each digit of the integer and check if it is even or odd
Keep track of the sum of even digits and odd digits separa...read more
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