import java.util.Scanner ; public class Main { public static void main ( String [] args ) { // write your code here int arr[] = new int [ 5 ]; Scanner sc = new Scanner ( System . in); for ( int i = 0 ;i < 5 ;i ++ ) { arr[i] = sc . nextInt(); } for ( int i = 0 ;i < arr . length;i ++ ) { System . out . println(factorial(arr[i])); ; } } private static int factorial ( int num ) { int fact = 1 ; for ( int i = 1 ;i <= num;i ++ ) fact = fact * i; return fact; } }
# include < stdio.h > # include < string.h > # include < stdlib.h > void main () { int number; float temp, sqrt ; scanf ( " %d " , &number); // store the half of the given number e.g from 256 => 128 sqrt = number / 2 ; temp = 0 ; // Iterate until sqrt is different of temp, that is updated on the loop while ( sqrt != temp){ // initially 0, is updated with the initial value of 128 // (on second iteration = 65) // and so on temp = sqrt ; // Then, replace values (256 / 128 + 128 ) / 2 = 65 // (on second iteration 34.46923076923077) // and so on sqrt = ( number/temp + temp) / 2 ; } printf ( " %.0f " , sqrt ); }
Comments
Post a Comment