Computer Science, asked by karthikashok2004, 4 months ago

Write a program to input any 10 integers and find the sum of even numbers and odd numbers separately using for loop

Answers

Answered by nishasutar29
0

Python Program to find Sum of Even and Odd Numbers in a List

Write a Python Program to find Sum of Even and Odd Numbers in a List using For Loop, While Loop, and Functions with a practical example.

Python Program to find Sum of Even and Odd Numbers in a List using For Loop

In this python program, we are using For Loop to iterate each element in a given List. Inside the Python loop, we used the If statement to check and find the Sum of Even and odd numbers.

Answered by avantikamanna2307
3

Answer:

import java.util.Scanner;

class esum_osum

{

   public static void main(String args[])

   {

       Scanner sc=new Scanner(System.in);

       int i,s=0,l=0,c=0;

       int esum=0;

       int osum=0;

       int n=0;

       System.out.println("Enter 10 integers");

       for(i=1;i<=10;i++)

       {

           n=sc.nextInt();

{

               if(n%2==0)

                   esum+=n;

               else

                   osum+=n;

           }

       }

System.out.println("Sum of even numbers is "+esum+" and sum of odd numbers is "+osum);

   }

}

Explanation:

Similar questions