Take my code existing code and transform it into Functional Language code/Computer science
Here’s my code, I need to rewrite it into functional language.. it should be pretty easy assignment, thus the deadline is only a day.
#include<iostream>
using namespace std;
// function that returns absolute difference between 2 numbers
// input is a
int absoluteDiff(int a)
{
// variable declaration
int b = 4;
// condition
if(a>b)
return a-b;
else
return b-a;
}
main(){
// 2 sample runs
cout << absoluteDiff(2) << endl;
cout << absoluteDiff(8) << endl;
}
/*SAMPLE OUTPUT
2
4
*/
and here’s an example of functional language to which above code should be transformed to:
function isFive a: integer returns boolean;
b: boolean is false;
begin
if a==5 then
!b;
else
b;
endif;
end;
The program will return false for any input not equal to 5 and it will return true for an input equal to 5.
Project does not have any attached files