0% found this document useful (0 votes)
32 views19 pages

R009 BT Lab6

The document describes a laboratory manual for a blockchain technology course. It outlines 10 programming tasks for students to complete, including writing functions to double a number, check if a number is odd, calculate factorials, check if a number is a perfect square, calculate powers, find the maximum of two numbers, calculate the sum of digits, check if a number is an Armstrong number, calculate the Fibonacci series, and check if a number is a palindrome.

Uploaded by

aryanbond1009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views19 pages

R009 BT Lab6

The document describes a laboratory manual for a blockchain technology course. It outlines 10 programming tasks for students to complete, including writing functions to double a number, check if a number is odd, calculate factorials, check if a number is a perfect square, calculate powers, find the maximum of two numbers, calculate the sum of digits, check if a number is an Armstrong number, calculate the Fibonacci series, and check if a number is a palindrome.

Uploaded by

aryanbond1009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Laboratory Manual

Blockchain Technology

Academic Year 2023 - 2024


B.Tech and MBA Tech AI Semester
VI
Experiment 5
PART A
(PART A: TO BE REFERRED BY STUDENTS)

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.

The filename should be: BT_Batch_RollNo_ExperimentNo

Roll No.: R009 Name: Aryan Bondgulwar

Prog/Yr/Sem: III Semester VI Batch: B1

Date of Experiment: Date of Submission:

B1. Complete the following tasks:

CODE:

//SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.13;

contract tasks

function double(uint x) public pure returns(uint result1)

result1=x*x;

function odd(uint x) public view returns(bool)

{
return x %2 !=0;

function fact(uint x) public pure returns(uint result2)

result2 = 1;

for (uint i = 2; i <= x; i++)

result2 *= i;

function integerSquareRoot(uint x) public pure returns (uint)

uint y = x;

while (y * y > x)

y = (y + x / y) / 2;

}
return y;

function power(uint x,uint y) public pure returns(uint result3)

result3=x**y;

function max(uint x,uint y) public pure returns(uint result4)

if (x>y)

return x;

else

return y;

function sumOfDigits(uint256 x) public pure returns (uint) {


uint sum = 0;

while (x > 0) {

sum += x % 10;

x /= 10;

return sum;

function isArmstrong(uint x) public pure returns (bool) {

uint originalNumber = x;

uint digits = 0;

while (x > 0) {

digits++;

x /= 10;

uint sum = 0;

x = originalNumber;

while (x > 0) {

uint remainder = x % 10;


sum += remainder ** digits;

x /= 10;

return sum == originalNumber;

function fibonacci(uint x) public pure returns (uint[] memory) {

uint[] memory fib = new uint[](x);

if (x == 0) {

return fib;

fib[0] = 0;

if (x > 1) {

fib[1] = 1;

for (uint i = 2; i < x; i++) {

fib[i] = fib[i-1] + fib[i-2];

return fib;

}
function isPalindrome(uint x) public pure returns (bool) {

uint originalNumber = x;

uint reversed = 0;

while (x > 0) {

reversed = reversed * 10 + x % 10;

x /= 10;

return originalNumber == reversed;

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:

You might also like