Computer Science, asked by ShadowplayerLC, 8 months ago

Write a program that reads n digit number. After reading the number, compute and display the sum of the odd positioned digits, multiply all even positioned digits and add these two numbers.

Answers

Answered by prashantrohilla32
0

Answer:

import java.util.*;

public class Main

{

public static void main(String args[]){

   Scanner sc=new Scanner(System.in);

   int n =sc.nextInt();

    int oddsum=0;

   int evenproduct=1;

   while(n>0)

   {

       int r=n%10;

       if(r%2!=0)

       {

           oddsum=oddsum+r;    // 1+3+5+7=16

       }

       if(r%2==0)

       {

           evenproduct=evenproduct*r;     // 2*4*6*8= 384

       }

       n=n/10;

   }

System.out.println(oddsum+evenproduct);    // 16+384=400

}

}

Explanation:

it is a java program

Attachments:
Answered by Anonymous
1

Answer:

hi...

Explanation:

n =int(input('Enter a number: '))

num = []

s = 0

p = 1

i = 0

while n > 0:

   num.append(n%10)

   n //= 10

for num in reversed(num):

   if i%2 == 0:

       p*= num

   else:

       s+= num

   i += 1

print ('sum of odd digits:', s)

print ('product of even digits:', p)

print( 'answer:', s+p)

hope this helps you

please mark brainliest

Similar questions