Questions: 5 831

Answers by our Experts: 5 728

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Mean, Median and Mode

Given a list of integers, write a program to print the mean, median and mode.

Mean - The average value of all the numbers.

Median - The mid point value in the sorted list.

Mode - The most common value in the list. If multiple elements with same frequency are present, print all the values with same frequency in increasing order.Input


The input will be a single line containing space-separated integers.Output


For example, if the given list of integers are

2 6 3 1 8 12 2 9 10 3 4

The average of all the numbers is 5.45


After sorting the array,

1 2 2 3 3 4 6 8 9 10 12

as the length of the list is an odd number, the median will be the middle number in the sorted list. So the median will be 4.

As 2 and 3 are having the same frequency, the mode will be 2 3.

So the output should be

Mean: 5.45
Median: 4
Mode: 2 3

Sample Input 1

2 4 5 6 7 8 2 4 5 2 3 8


Sample Output 1

Mean: 4.67

Median: 4.5

Mode: 2


Sample Input 2

2 6 3 1 8 12 2 9 10 3 4


Sample Output 2

Mean: 5.45

Median: 4

Mode: 2 3








Shift Numbers - 2

Given a string, write a program to move all the numbers in it to its start.Input


The input will contain a string A.Output


The output should contain a string after moving all the numbers in it to its start.Explanation


For example, if the given string A is "1good23morning456", the output should be "123456goodmorning", as it contains numbers at the start.


Sample Input 1

1good23morning456


Sample Output 1

123456goodmorning


Sample Input 2

com876binat25ion


Sample Output 2

87625combination




Sum of Prime Numbers In the Input

Given a list of integers, write a program to print the sum of all prime numbers in the list of integers.

Note: One is neither prime nor composite number.Input


The input will be a single line containing space-separated integers..Output


The output should be a single line containing the sum of all prime numbers from 1 to N.Explanation


For example, if the given list of integers are

2 4 5 6 7 3 8


As 2, 3, 5 and 7 are prime numbers, your code should print the sum of these numbers. So the output should be 17.


Sample Input 1

2 4 5 6 7 3 8


Sample Output 1

17


Sample Input 2

65 87 96 31 32 86 57 69 20 42


Sample Output 2

31




Sum of Prime Numbers from M to N

Given two integers M and N, write a program to print the sum of prime numbers from M to N. (Both M and N are inclusive).Input


The first line of input will contain a positive integer (M).

The second line of input will contain a positive integer (N).Output


The output should be a single line containing the sum of prime numbers from M to N.Explanation


For example, if the given M and N are 5 and 11, as all the prime numbers from 5 to 11 are 5, 7, and 11. So the output should be sum of these primes (5+7+11), which is 23.


Similarly, if the given numbers are M is 18 and N is 40, as all the prime numbers from 18 to 40 are 19, 23, 29, 31,and 37. So the output should be sum of these primes (19+23+29+31+37), which is 139.


Sample Input 1

5

11


Sample Output 1

23


Sample Input 2

18

40


Sample Output 2

139




Index of Last Occurrence

Write a program to print the index of the last occurrence of the given number N in the list.Input


The first line of input will contain space-separated integers.

The second line of input will contain an integer N.Output


The output should be the index of the last occurrence of the number N.Explanation


For example, if the given list of numbers and N are

2 4 5 6 7 8 2 4 5 2 3 8
2


Number 2 present at index locations 0, 6, 9, as the last occurrence, is at index 9. So the output should be 9.


Sample Input 1

2 4 5 6 7 8 2 4 5 2 3 8

2


Sample Output 1

9


Sample Input 2

65 87 96 31 32 86 57 69 20 42 32 32

32


Sample Output 2

11




Mean, Median and Mode
Given a list of integers, write a program to print the mean, median and mode.
Mean - The average value of all the numbers.
Median - The mid point value in the sorted list.
Mode - The most common value in the list. If multiple elements with same frequency are present, print all the values with same frequency.
Input

The input will be a single line containing space-separated integers.
Output

The first line of output should contain the mean, round off the value to 2 decimal places.
The second line of output should contain the median, round off the value to 2 decimal places.
The third line of output should contain the mode.
See Sample Input/Output for the output format.
Explanation
as the length of the list is an odd number, the median will be the middle number in 

Mean: 5.45
Median: 3
Mode: 2 3

Sample Input 1
2 4 5 6 7 8 2 4 5 2 3 8
Sample Output 1
Mean: 4.67
Median: 4.5
Mode: 2

Sample Input 2
2 6 3 1 8 12 2 9 10 3 4
Sample Output 2
Mean: 5.45
Median: 3
Mode: 2 3
Shift Numbers - 2
Given a string, write a program to move all the numbers in it to its start.
Input

The input will contain a string A.
Output

The output should contain a string after moving all the numbers in it to its start.
Explanation

For example, if the given string A is "1good23morning456", the output should be "123456goodmorning", as it contains numbers at the start.
Sample Input 1
1good23morning456
Sample Output 1
123456goodmorning

Sample Input 2
com876binat25ion
Sample Output 2
87625combination


Sum of Prime Numbers In the Input
Given a list of integers, write a program to print the sum of all prime numbers in the list of integers.
Note: One is neither prime nor composite number.
Input

The input will be a single line containing space-separated integers..
Output

The output should be a single line containing the sum of all prime numbers from 1 to N.
Explanation

For example, if the given list of integers are

2 4 5 6 7 3 8


As 2, 3, 5 and 7 are prime numbers, your code should print the sum of these numbers. So the output should be 17.
Sample Input 1
2 4 5 6 7 3 8
Sample Output 1
17

Sample Input 2
65 87 96 31 32 86 57 69 20 42
Sample Output 2
31


Sum of Prime Numbers from M to N
Given two integers M and N, write a program to print the sum of prime numbers from M to N.
Input

The first line of input will contain a positive integer (M).
The second line of input will contain a positive integer (N).
Output

The output should be a single line containing the sum of prime numbers from M to N.
Explanation

For example, if the given M and N are 5 and 11, as all the prime numbers from 5 to 11 are 5, 7, and 11. So the output should be sum of these primes (5+7+11), which is 23.

Similarly, if the given numbers are M is 18 and N is 40, as all the prime numbers from 18 to 40 are 19, 23, 29, 31,and 37. So the output should be sum of these primes (19+23+29+31+37), which is 139.

Sample Input 1
5
11
Sample Output 1
23

Sample Input 2
18
40
Sample Output 2
139


Index of Last Occurrence
Write a program to print the index of the last occurrence of the given number N in the list.
Input

The first line of input will contain space-separated integers.
The second line of input will contain an integer N.
Output

The output should be the index of the last occurrence of the number N.
Explanation

For example, if the given list of numbers and N are

2 4 5 6 7 8 2 4 5 2 3 8
2


Number 2 present at index locations 0, 6, 9, as the last occurrence, is at index 9. So the output should be 9.
Sample Input 1
2 4 5 6 7 8 2 4 5 2 3 8
2
Sample Output 1
9

Sample Input 2
65 87 96 31 32 86 57 69 20 42 32 32
32
Sample Output 2
11

LATEST TUTORIALS
APPROVED BY CLIENTS