R009 BT Lab6
R009 BT Lab6
Blockchain Technology
1. Function to Double a Number:Write a pure function named double that takes an integer parameter x and
returns its double.
2. Function to Check Odd Number: Write a view function named isOdd that takes an integer parameter x and
returns true if it's odd, otherwise false.
3. Function to Calculate Factorial: Write a pure function named factorial that takes a positive integer n and
returns its factorial.
4. Function to Check if Number is Perfect Square: Write a view function named isPerfectSquare that takes an
integer x and returns true if it's a perfect square, otherwise false.
5. Function to Calculate Power: Write a pure function named power that takes two integers base and exponent
and returns base raised to the power of exponent.
6. Function to Find Maximum of Two Numbers: Write a pure function named max that takes two integers a
and b and returns the maximum of the two.
7. Function to Calculate Sum of Digits: Write a pure function named sumOfDigits that takes a positive integer
n and returns the sum of its digits.
8. Function to Check Armstrong Number: Write a view function named isArmstrong that takes a positive
integer n and returns true if it's an Armstrong number, otherwise false.
9. Function to Calculate Fibonacci Series: Write a view function named Fibonacci series that takes a positive
integer n and returns an array containing the first n Fibonacci numbers.
10. Function to Check Palindrome Number: Write a view function named isPalindrome that takes a positive
integer n and returns true if it's a palindrome number, otherwise false.
PART B
(PART B: TO BE COMPLETED BY STUDENTS)
Students must submit the soft copy as per the following segments within two hours of the
practical. The soft copy must be uploaded to the portal at the end of the practical.
CODE:
//SPDX-License-Identifier: UNLICENSED
contract tasks
result1=x*x;
{
return x %2 !=0;
result2 = 1;
result2 *= i;
uint y = x;
while (y * y > x)
y = (y + x / y) / 2;
}
return y;
result3=x**y;
if (x>y)
return x;
else
return y;
while (x > 0) {
sum += x % 10;
x /= 10;
return sum;
uint originalNumber = x;
uint digits = 0;
while (x > 0) {
digits++;
x /= 10;
uint sum = 0;
x = originalNumber;
while (x > 0) {
x /= 10;
if (x == 0) {
return fib;
fib[0] = 0;
if (x > 1) {
fib[1] = 1;
return fib;
}
function isPalindrome(uint x) public pure returns (bool) {
uint originalNumber = x;
uint reversed = 0;
while (x > 0) {
x /= 10;
SCREENSHOTS:
1. Function to Double a Number:Write a pure function named double that takes an integer parameter x
and returns its double.
Deployed:
2. Function to Check Odd Number: Write a view function named isOdd that takes an integer parameter
x and returns true if it's odd, otherwise false.
Deployed:
3. Function to Calculate Factorial: Write a pure function named factorial that takes a positive integer n
and returns its factorial.
Deployed:
4. Function to Check if Number is Perfect Square: Write a view function named isPerfectSquare that
takes an integer x and returns true if it's a perfect square, otherwise false.
Deployed:
5. Function to Calculate Power: Write a pure function named power that takes two integers base and
exponent and returns base raised to the power of exponent.
Deployed:
6. Function to Find Maximum of Two Numbers: Write a pure function named max that takes two
integers a and b and returns the maximum of the two.
Deployed:
7. Function to Calculate Sum of Digits: Write a pure function named sumOfDigits that takes a positive
integer n and returns the sum of its digits.
Deployed:
8. Function to Check Armstrong Number: Write a view function named isArmstrong that takes a
positive integer n and returns true if it's an Armstrong number, otherwise false.
Deployed:
9. Function to Calculate Fibonacci Series: Write a view function named Fibonacci series that takes a
positive integer n and returns an array containing the first n Fibonacci numbers.
Deployed:
10. Function to Check Palindrome Number: Write a view function named isPalindrome that takes a positive
integer n and returns true if it's a palindrome number, otherwise false.
Deployed: