Introduction A function is a named sequence of instructions that performs a spec
ID: 3722656 • Letter: I
Question
Introduction A function is a named sequence of instructions that performs a specific task and returns the result of ts computation. Once defined, it can be then called in your program wherever that particular task should be performed A function can receive zero or more arguments. For example, consider a function sum which receives three arguments, here nameda.b,and c. and retums their sum: int sum(int a, int b, int c) return atb To execute (or call) a function, you must supply its arguments. For example, if you want to compute the sum of 500, 600, and 700, you can write: sum(500, 600, 700) #include using namespace std Defining a function that computes the sum of three integers int sum(int a, int b, int c) return a+bc int main) ( // Ne call it with the actual argumenta 1, 20, 300 1 and save the result in a variable x int xsum(, 20, 300) Prints 321 Let's define a function that computes the maximum of two integers: Returns the maxinum of tvo arguments int max2(int a, int b) ( if (a b) return a else f return b Then one can find the maximum of thee integers, for example, like this: max2 { max2 (135. 8763), 500 // would return 8763Explanation / Answer
#include<iostream>
using namespace std;
//check whether given number or not
bool isPrime(int n){
int i, c=0;
for(i=2; i<n; i++){
if(n%i==0)
c++;
}
return c==0;
}
//checking Twin Prime with help of isPrime
bool isTwinPrime(int n){
if(isPrime(n+2) || isPrime(n-2))
return true;
return false;
}
//finding next Twin Prime with help of isTwinPrime
int nextTwinPrime(int n){
while(1){
if(isPrime(n)){
if(isTwinPrime(n)){
return n;
}
}
n++;
}
}
int main(){
if(isTwinPrime(23)){
cout<<"Yes"<<endl;
}
else{
cout<<"Not"<<endl;
}
cout<<nextTwinPrime(15)<<endl;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.