Input 50 numbers and display the sum of those numbers and separately:
Which are divisible of 5 but not by 8
b. Which are divisible of 8 but Not by 5
Which are divisible by 5 and 8
mharic nrimo or not
C.
Answers
Answer:
a 50
b48
c 40.
is the answer of your question
JAVA PROGRAM➛
Input 50 numbers and display the sum of those numbers➽
a).Which are divisible of 5 but not by 8
b).Which are divisible of 8 but Not by 5
c).Which are divisible by 5 and 8
_________________________________
CODE ➠
import java.util.*;
class Sum
{
public static void main ()
{
Scanner sc=new Scanner (System.in);
int a[]=new int[50];
int x=0,y=0,z=0;
System.out.println("Enter 50 numbers");
for(int b=0;b<50;b++)
{
a[b]=sc.nextInt();
if(a[b]%5==0&&a[b]%8!=0)
x=x+a[b];
else if(a[b]%8==0&&a[b]%5!=0)
y=y+a[b];
else if(a[b]%5==0&&a[b]%8==0)
z=z+a[b];
}
System.out.println("Sum of Numbers Which are divisible of 5 but not by 8 "+x);
System.out.println("Sum of Numbers Which are divisible of 8 but not by 5 "+y);
System.out.println("Sum of Numbers Which are divisible of both 5 and 8"+z);
}//main() end
}//class end.
_________________________________
LoGIC USED:-
Initialisation of 50 number in Array make the code Compressed hence Easy too.