sum 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 prime numbers.
note.one is either 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 40, as all the prime numbers from 18 to 40 are 19,23,23,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 1
139
index of last occurrence
write s program to print the index of the last occurence 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 occurence 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 occurence, 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
The miles per gallon (mpg) of a car can be calculated by dividing the miles driven by the number of gallons of gas used. Any time you have division in a computer program you have to check division by zero (the results of division by zero is infinity). If you don't a user could input zero for the number of gallons used and crash your program. You should also always check that any numeric input only accepts numbers and not letters, and that any numeric input is reasonable. For example, miles driven is probably not more than 1000 miles and is also a positive value (negative miles driven makes no sense, as does negative gallons used).
Assignment: Write a program to calculate mpg given miles driven and gallons used. Use exception handling in C# to check for numeric inputs and division by zero. Use appropriate logic to check for the reasonableness of the inputs.
Discuss one Input-Output communication technique that is used
in a computer system; and outline the steps involved
#include <iostream> using namespace std; #include <string>
class cat
string color="White": string action="sitting"
Your Code Here
int main()
cat cl;
cat c2("Black"):
cat c3("Brown", "jumping");
cat c4("Red", "purring");
cl.print_cat():
c2.print_cat();
c3.print_cat():
c4.print_cat():
cl.change_color("Blue"); c3.change_color("Purple");
cl.print cat();
c3.print_cat():
return 0:
Complete the cat class so the main function above produces the following output:
White cat is sitting
Black cat is sitting Brown cat is jumping
Red cat is purring
Blue cat is sitting Purple cat is jumping
Complete the cat class so the main function above produces the following output:
White cat is sitting
Black cat is sitting Brown cat is jumping
Red cat is purring
Blue cat is sitting Purple cat is jumping
1. Write a program that will illustrate the use of a function for computing the square of a number. There must be three other functions aside from main(). The First function must be responsible for inputting the data, the second for computation of squares and the third, for Displaying the result. 10 points
Creat a program with the compilation of your activities in prelim
Implement your own string class using only primitive data types. Your string class should contain some of the same functionality as the string class in C++.
Your class should have the following member variables:
1. char *data
2. int length
Your object should have the following constructors and destructor:
1. String(): default constructor
2. String(int size)
3. String(char* str)
Note: You can assume that any character array that is sent as str will be terminated
by a null character (‘\0’)
4. String(const String &str)
5. ~String()
Your class should have the following functions:
1. int strLength()
2. void clear()
3. bool empty()
4. int charAt(char c)
5. char* getdata()
6. bool equals(char*str)
7. bool equalsIgnoreCase(char* str)
8. char* substring(char* substr, int startIndex)
9. char* substring(char* substr, int startIndex, int endIndex)
10. void print()