C program exxmp


1. C Program to Count Leaf Nodes in a Binary Tree
2. Program to Find Diameter of a Binary Tree
3. Program to Find Maximum Node of Binary Tree



import java.util.Scanner;

public class Horner
{
private int sum;
    
public Horner(int[] cof, int x)
{
sum = 0;

calcSum(cof, x, cof.length - 1);

display();
}    
private void calcSum(int[] cof, int x, int N)
{
sum = cof[N] * x;

for (int i = N - 1; i >= 1; i--)

sum = (sum + cof[i]) * x;

sum += cof[0];
}
public void display()
{
System.out.println("Evaluated sum = "+ sum);
}
public static void main(String[] args) 
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter highest power");
int n = scan.nextInt();
int[] arr = new int[n + 1];
System.out.println("\nEnter "+ (n + 1) +" coefficients in increasing order");
for (int i = 0; i <= n; i++)
arr[i] = scan.nextInt();
        System.out.println("\nEnter x");
        int x = scan.nextInt();
        Horner h = new Horner(arr, x);
    }
}

Post a Comment

0 Comments