Skip to content

Commit d9f822e

Browse files
committed
Added functions programs
1 parent 3c411f6 commit d9f822e

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ This repo includes:
4242
- [Pyramid Number Pattern](./milestone2/test1/PyramidNumberPattern.cpp)
4343
- [Number Star Pattern](./milestone2/test1/NumberStarPattern.cpp)
4444
- [Second Largest](./milestone2/test1/SecondLargest.cpp)
45+
- [Functions](./milestone2/functions/)
46+
- [Fahrenheit to Celsius Table](./milestone2/functions/FahrenheittoCelsiusTable.cpp)
47+
- [Fibonacci Number](./milestone2/functions/FibonacciNumber.cpp)
4548

4649
# Coding Ninjas
4750
## Rate my Repo ⭐!!!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Given three values - Start Fahrenheit Value (S), End Fahrenheit value (E) and Step Size (W),
2+
// you need to convert all Fahrenheit values from Start to End at the gap of W, into their corresponding Celsius values and print the table.
3+
4+
/*Main code
5+
6+
#include<iostream>
7+
using namespace std;
8+
#include "Solution.h"
9+
10+
int main(){
11+
int start, end, step;
12+
cin >> start >> end >> step;
13+
14+
printTable(start, end, step);
15+
16+
}
17+
*/
18+
19+
// code
20+
void printTable(int start, int end, int step) {
21+
/* Don't write main().
22+
* Don't read input, it is passed as function argument.
23+
* Print output and don't return it.
24+
* Taking input is handled automatically.
25+
*/
26+
while (start <= end){
27+
int cel = (5*(start-32))/9;
28+
cout<<start<<" "<<cel<<endl;
29+
start+=step;
30+
}
31+
}
32+
33+
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Given a number N, figure out if it is a member of fibonacci series or not.
2+
// Return true if the number is member of fibonacci series else false.
3+
// Fibonacci Series is defined by the recurrence
4+
// F(n) = F(n-1) + F(n-2)
5+
// where F(0) = 0 and F(1) = 1
6+
7+
/* Main Code
8+
#include<iostream>
9+
using namespace std;
10+
#include "Solution.h"
11+
12+
int main(){
13+
14+
int n;
15+
cin >> n ;
16+
if(checkMember(n)){
17+
cout << "true" << endl;
18+
}else{
19+
cout << "false" << endl;
20+
}
21+
}
22+
*/
23+
24+
// Code
25+
26+
27+
bool checkMember(int n){
28+
29+
/* Don't write main().
30+
* Don't read input, it is passed as function argument.
31+
* Return output and don't print it.
32+
* Taking input and printing output is handled automatically.
33+
*/
34+
35+
int a=0, b=1, sum=0;
36+
while (sum<=n){
37+
sum = a+b;
38+
if (sum == n)
39+
return true;
40+
a = b;
41+
b = sum;
42+
}
43+
return false;
44+
}

0 commit comments

Comments
 (0)