Part 1.Write a complete program describing all the tasks below.
In the main function, the program respectively request an Integer (N), an operation flag, and finally a flag to decide if it is going to work on odd / even numbers. The program will support only 2 operations, addition or multiplication. According to the selection of the flags, the program will calculate the sum/multiplication of the odd/even numbers between the range of [1,N]. The addition and the multiplication operations should be done by using two different functions. The operation selection should be determined by using operation flag with switch-case, after that, the integer and the other flag should be used to call the related function. If user enters invalid value for the flags, the program should print an error message.
Function prototypes are :
int sum (int n, int flag) int mult (int n, int flag)
Examples:
Part 2. Write a complete program which takes an integer N from the user and checks the every integer from 2 to that number if they are prime or not. The primality testing is made by a function with the following information:
A is prime if A is not dividible by any integer X where X is;
1<𝑋≤√𝐴
This operation should be done in a function, the function should return a flag if the integer is prime, or should return the least divisor of that integer if it is not a prime. In the main function, you should use a loop to check every A between 1<𝐴<N, obtain a result by using the function and finally print it.
Only ‘for’ loops should be used. You are allowed to use sqrt() function from math library to calculate the square root.
Function prototype is : int isprime (int a)
Example:
Part 3.Write a complete program describing all the tasks below.
In the main function, 2 integers are requested from the user. These integers will work as decimal numbers but you are expected to work on them as binary numbers and implement AND logical operator without using “&”. To do this,
1. The program should check if the integers are binary or not (their digits must be 0, 1). If the integers are not binary, the program should ask for new integers again and again until it obtains a proper pair. 2. The program should check if the integers’ lengths (number of digits) are the same or not. If the lengths are not the same, the program should ask for new integers again and again until it obtains a proper pair.
3. After obtaining a decent integer pair (2 binary numbers with the same length), the program should implement logical AND operation on these integers, without using ‘&’ operator. Here, there should be a function which calculates the result of the AND operation and returns it to the main(). And the result should be printed in the main() function.
Function prototype is : int andop (int a, int b)
Note that you can’t use arrays & you are allowed to use ‘do-while’ or ‘while’ loops only.