Question

LISP lambda calculate, expression

3) Consider reducing the following λ-expression to its normal form. Show the sequence of normal order reductions the sequence of applicative order reductions. · · 4) Consider the following function: Fx) ifx-0) then return 0 else return x+1 a) Express F as a lambda calculus expression b) Evaluate F(0) as a lambda expressiorn c) Evaluate F(1) as a lambda expression HINT: Use the representations introduces in Section 10. 5) Describe a function to compute the sum of the cubes of the first n positive numbers, using the abstract programming language introduced in section 11

0 0
Add a comment Improve this question Transcribed image text
Answer #1

5) SUM OF CUBES OF FIRST N POSITIVE NNUMBERS

Fist of all know that java , c++ and other where you hide the details of operation from user is the absttract proggramming language.

so heres the program for cube addition in jva as a function

import java.util.*;

import java.lang.*;

public class CubeSum {

/* Returns the sum of series */

public static int cubeSum(int n)

{

int x;

if (n % 2 == 0)

x = (n/2) * (n+1);

else

x = ((n + 1) / 2) * n;

return x * x;

}

// Main function for calling of cubeSum()

public static void main(String[] args)

{

int n;

Scanner reader = new Scanner(System.in); // Reading from System.in

System.out.println("Enter a number: ");

n = reader.nextInt(); // Scans the next token of the input as an int.

//once finished

reader.close();

  

int sum=cubeSum(n);

System.out.println("Sum of cubeis of first "+n+" numbers is "+sum);

}

}

Add a comment
Know the answer?
Add Answer to:
LISP lambda calculate, expression 3) Consider reducing the following λ-expression to its normal form. Show the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT