Computer Science, asked by rynasunil, 1 month ago

Write a program to accept 20 different numbers in a Single Dimensional
Array (SDA). Display the sum of all the numbers which are divisible by
either 3 or 5.
mhers which are divisible by 3 or 5​

Answers

Answered by Equestriadash
7

The following co‎des have been written using Python.

\tt import\ numpy\ as\ np\\arr\ =\ np.ndarray(shape\ =\ (20,\ ),\ dtype\ =\ int)\\for\ i\ in\ range(20):\\{\ \ \ \ \ }arr[i]\ =\ int(in put("Enter\ the\ number:\ "))\\s\ =\ 0\\for\ i\ in\ arr:\\{\ \ \ \ \ }if\ i\%3\ ==\ 0\ or\ i\%5\ ==\ 0:\\{\ \ \ \ \ }{\ \ \ \ \ }s\ =\ s\ +\ i\\print(s,\ "is\ the\ sum\ of\ the\ numbers\ divisible\ by\ 3\ or\ 5.")

We import the \tt numpy module to create the array. Once the definition of the array has been created, we use a loop to retrieve the numbers. After that, a variable is assigned to represent the sum of the numbers. We start another loop to traverse through the array and test which of the numbers are divisible by 3 or 5 using a conditional statement. If they're divisible by 3 or 5, they get added to the variable earlier assigned for the same and an appropriate \tt print statement is pas‎sed.

Answered by ⲎⲟⲅȋⲊɑⲛ
7

\huge\sf\purple{★Quєstioꪀ}

Q. Write a program to accept 20 different numbers in a Single Dimensional Array (SDA). Display the sum of all the numbers which are divisible by either 3 or 5.

\huge\sf\blue{★Aꪀswєг}

THIS PROGRAM IS BASED ON SINGLE DIMENSIONAL ARRAYS!

\red{━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━}

// To display the sum of numbers which are divisible by 3 or 5

import java.util.*;

public class Sum

{

public static void main (String args[])

{

Scanner in = new Scanner (System.in);

int i,s = 0

int m [ ] = new int [20];

for (i = 0; i < 20 ; i + + )

{

System.out.print("Enter the number in the cell :");

m[I] = in.nextInt();

}

for(i = 0; i < 20 ; i + + )

{

if(m[I]%3 == O||m[I]%5 == O)

s = s + m [i];

}

System.out.println("The sum of numbers divisible by 3 or 5:" +s);

}

}

\red{━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━}

Similar questions