Fundamentals of Computer Science IN2203-G6
Fundamentals of Computer Science IN2203-G6
Course
Due Date
Instructor Total Marks: /15
Week 6 (Feb 15, 2021)
Abiodun Ojo
Instructions:
Design and document your response. Zip your codes along with your response back in this
Tasks
the task.
Java code:
class Fibonacci{
int n1=0,n2=1,n3,i,count=10;
for(i=2;i<count;++i)
n3=n1+n2;
System.out.print(" "+n3);
n1=n2;
n2=n3;
Output:
ASSIGNMENT 1 3
6*1=6
6 * 2 = 12
6 * 3 = 18
6 * 4 = 24
6 * 5 = 30
6 * 6 = 36
6 * 7 = 42
6 * 8 = 48
6 * 9 = 56
6* 10 = 60
Java Code:
Output:
Java code
import java.util.Scanner;
class Factorial{
int i,fact=1;
int num;
num=sc.nextInt();
for(i=1;i<=num;i++){
fact = fact*i;
} }
Output:
4. A prime number is a number divisible by only 1 and itself. Write a prime number
Java Code:
int i,m=0,flag=0;
m=n/2;
if(n==0||n==1){
}else{
for(i=2;i<=m;i++){
if(n%i==0){
ASSIGNMENT 1 6
flag=1;
break;
}//end of else
Output:
Java Code:
int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
sum += array[i];
return Math.sqrt(standardDeviation/array.length);
Output:
ASSIGNMENT 1 8