Answer:
def main():
n = int(input('Enter the value of the variable n:'))
k=2;
totalSum = 0
print('The list of the prime numbers are as follows:')
while k <= n:
totalSum = totalSum+is_prime(k)
k=k+1
print('Total sum of the prime numbers:',totalSum)
def is_prime(k):
primeNumber = 0
i=1
while i<=int(k):
if (k % i) == 0:
primeNumber = primeNumber + 1
i=i+1
if(primeNumber==2):
print(k)
return k;
else:
return 0;
main()
Explanation:
- Run the while loop until k is less than n.
- Determine if the variable k is prime then add it to the totalSum variable.
- Increment the value of k by 1.
- Create a function isPrime to check whether the number is prime or not by determining the factors of k which can be found using the modulus operator.
-
Call the main function at the end.
Here you go,
Import java.util.scanner
public class SumOfMax {
public static double findMax(double num1, double num2) {
double maxVal = 0.0;
// Note: if-else statements need not be understood to
// complete this activity
if (num1 > num2) { // if num1 is greater than num2,
maxVal = num1; // then num1 is the maxVal.
}
else { // Otherwise,
maxVal = num2; // num2 is the maxVal.
}
return maxVal;
}
public static void main(String[] args) {
double numA = 5.0;
double numB = 10.0;
double numY = 3.0;
double numZ = 7.0;
double maxSum = 0.0;
/* Your solution goes here */
maxSum = findMax(numA, numB); // first call of findMax
maxSum = maxSum + findMax(numY, numZ); // second call
System.out.print("maxSum is: " + maxSum);
return;
}
}
/*
Output:
maxSum is: 17.0
*/
The answer is procedural programming and object oriented programming. Procedural programming focuses on the procedures that programmers create. This simply contain a series of computational steps to be carried out. While the object-oriented programming or oop, focuses on objects, or “things”, and describes their features, or attributes, and their behaviors.
Answer:
1. G=D+(A+C^2)*E/(D+B)^3
cobegin:
p1: (D+B)
p2: p1^3
p3: C^2
p4: A+ p3
p5: E/p2
p6: p4 * p5
p7: D + p6
:G
coend
2. Now The value A=2, B=4, C=5, D=6, and E=8
p1: 6+4 =10
p2: p1 ^3= 10^3= 1000
p3: c^2= 5^2 =25
p4: A + p3= 2 +25 =27
p5: 8/1000
p6: 27 *8/1000
p7: D+ P6= 6+ 216/1000
= 6216/1000
=6.216
Explanation:
The above, first bracket with power is processed, and then power inside and outside bracket. And rest is according to BODMAS, and one process is solved at a time.