Computer Science, asked by tusharsamy, 8 months ago

write a program in java to find the sum of all three digit odd no which are multiple of 5

Answers

Answered by joshuaabrahamshomu
7

Answer:

Explanation:

import java.util.Scanner;

public class Sum_Odd_Even  

{

   public static void main(String[] args)  

   {

       int n, sumE = 0, sumO = 0;

       Scanner s = new Scanner(System.in);

       System.out.print("Enter the number of elements in array:");

       n = s.nextInt();

       int[] a = new int[n];

       System.out.println("Enter the elements of the array:");

       for(int i = 0; i < n; i++)

       {

           a[i] = s.nextInt();

       }

       for(int i = 0; i < n; i++)

       {

           if(a[i] % 2 == 0)

           {

               sumE = sumE + a[i];

           }

           else

           {

               sumO = sumO + a[i];

           }

       }

       System.out.println("Sum of Even Numbers:"+sumE);

       System.out.println("Sum of Odd Numbers:"+sumO);

   }

}

Answered by snehajeetgujar83
1

Explanation:

AP:105+115+125.......995

AP:105+115+125.......995a=105

AP:105+115+125.......995a=105d=10

AP:105+115+125.......995a=105d=10l=995

AP:105+115+125.......995a=105d=10l=995an=a+(n-1)d

AP:105+115+125.......995a=105d=10l=995an=a+(n-1)d995=105+(n-1)

AP:105+115+125.......995a=105d=10l=995an=a+(n-1)d995=105+(n-1)890/10=n-1

AP:105+115+125.......995a=105d=10l=995an=a+(n-1)d995=105+(n-1)890/10=n-1 89=n-1

AP:105+115+125.......995a=105d=10l=995an=a+(n-1)d995=105+(n-1)890/10=n-1 89=n-1 90 =n

AP:105+115+125.......995a=105d=10l=995an=a+(n-1)d995=105+(n-1)890/10=n-1 89=n-1 90 =nNow,

AP:105+115+125.......995a=105d=10l=995an=a+(n-1)d995=105+(n-1)890/10=n-1 89=n-1 90 =nNow, Sn =n/2(a+l)

AP:105+115+125.......995a=105d=10l=995an=a+(n-1)d995=105+(n-1)890/10=n-1 89=n-1 90 =nNow, Sn =n/2(a+l)sn=90/2(105+995)

AP:105+115+125.......995a=105d=10l=995an=a+(n-1)d995=105+(n-1)890/10=n-1 89=n-1 90 =nNow, Sn =n/2(a+l)sn=90/2(105+995)sn=45(1100)

AP:105+115+125.......995a=105d=10l=995an=a+(n-1)d995=105+(n-1)890/10=n-1 89=n-1 90 =nNow, Sn =n/2(a+l)sn=90/2(105+995)sn=45(1100) sn =49500

AP:105+115+125.......995a=105d=10l=995an=a+(n-1)d995=105+(n-1)890/10=n-1 89=n-1 90 =nNow, Sn =n/2(a+l)sn=90/2(105+995)sn=45(1100) sn =49500Sum of all 3 digit multiples of 5 is 49500.

Similar questions