1 what we will learn introduction passing input parameters producing output scope of variables ...
TRANSCRIPT
![Page 1: 1 What We Will Learn Introduction Passing input parameters Producing output Scope of variables Storage Class of variables Function usage example](https://reader035.vdocuments.us/reader035/viewer/2022072015/56649ed55503460f94be5cf7/html5/thumbnails/1.jpg)
1
What We Will Learn
Introduction
Passing input parameters
Producing output
Scope of variables
Storage Class of variables
Function usage example
Recursion
![Page 2: 1 What We Will Learn Introduction Passing input parameters Producing output Scope of variables Storage Class of variables Function usage example](https://reader035.vdocuments.us/reader035/viewer/2022072015/56649ed55503460f94be5cf7/html5/thumbnails/2.jpg)
2
How to use functions: Example
An Example Goldbach’s Conjecture Any even number larger than 2 can be expressed
as sum of two prim numbers
It is not proved yet! 1,000,000$ to proof ;-)
Write a program that takes numbers from user and checks correctness of the conjecture
![Page 3: 1 What We Will Learn Introduction Passing input parameters Producing output Scope of variables Storage Class of variables Function usage example](https://reader035.vdocuments.us/reader035/viewer/2022072015/56649ed55503460f94be5cf7/html5/thumbnails/3.jpg)
3
Main Algorithm
While(number is not zero)
if(number >= 2 and even)
Check Goldbach’s Conjecture
else
Print some message
read next number
![Page 4: 1 What We Will Learn Introduction Passing input parameters Producing output Scope of variables Storage Class of variables Function usage example](https://reader035.vdocuments.us/reader035/viewer/2022072015/56649ed55503460f94be5cf7/html5/thumbnails/4.jpg)
4
Check Goldbach’s Conjecture Algorithm
Algorithm: Goldbach Input: nOutput: 0 if conjecture is incorrect else 1
for(i from 2 to n/2)j = n – iif(is_prime(j))
conjecture is correct
i = next_prime_number(i)
Conjecture is incorrect
![Page 5: 1 What We Will Learn Introduction Passing input parameters Producing output Scope of variables Storage Class of variables Function usage example](https://reader035.vdocuments.us/reader035/viewer/2022072015/56649ed55503460f94be5cf7/html5/thumbnails/5.jpg)
5
is_prime algorithm
Algorithm: is_prime Input: n
Output: 1 if n is prime else 0
for(i from 2 to sqrt(n))
if(n % i == 0)
n is not prime
n is prime
![Page 6: 1 What We Will Learn Introduction Passing input parameters Producing output Scope of variables Storage Class of variables Function usage example](https://reader035.vdocuments.us/reader035/viewer/2022072015/56649ed55503460f94be5cf7/html5/thumbnails/6.jpg)
6
next_prime_number algorithm
Algorithm: next_prime_number Input: nOutput: prime number
if n is 2output is 3
else do
n = n + 2while(is_prime(n) == 0)output is n
![Page 7: 1 What We Will Learn Introduction Passing input parameters Producing output Scope of variables Storage Class of variables Function usage example](https://reader035.vdocuments.us/reader035/viewer/2022072015/56649ed55503460f94be5cf7/html5/thumbnails/7.jpg)
7
Putting them altogetherint is_prime(int n){…
}
int next_prime_number(int n){…
}
int check_Goldbach(int n){…
}
int main(void){…
}