Home work N- bonacci
public class Homework {
// Printing first m n-bonacci numbers
public static void printing(int n, int m) {
int[] arr = new int[m];
for(int i = 0; i < n - 1; i++) {
arr[i] = 0;
System.out.print(arr[i] + " ");
}
arr[n - 1] = 1;
arr[n] = 1;
System.out.print(arr[n - 1] + " ");
System.out.print(arr[n] + " ");
int sum = 2;
for(int j = 0; j < m - n - 1; j++ ){
arr[n + 1 + j] = sum - arr[j];
sum += arr[n + 1 + j] - arr[j];
System.out.print(arr[n + 1 + j] + " ");
}
}
public static void main(String[] args) {
printing(4, 10);
}
}
Comments
Post a Comment