K va N (N>0) butun sonlari berilgan. K sonini N marta chiqaruvchi dastur tuzilsin. Kodi import java.util.Scanner; class HelloWorld { public static void main(String[] args) { Scanner kiritish = new Scanner(System.in); double N; double K; System.out.print("N Sonni kiriting -> "); N = kiritish.nextInt(); System.out.print("K Sonni kiriting -> "); K = kiritish.nextInt(); for(int i=1; i<=N; i++){ System.out.println("K soni " + K); } } }
import java.util.Scanner;
class HelloWorld {
public static void main(String[] args) {
Scanner kiritish = new Scanner(System.in);
double S=0;
double N;
double X;
System.out.print("N Sonni kiriting -> ");
N = kiritish.nextInt();
System.out.print("X Sonni kiriting -> ");
X = kiritish.nextInt();
for(int i=1; i<=N; i++){
S = S + Math.pow((-1),(i-1))*(Math.pow(X,i))/I;
}
System.out.println("Yig'indi - " + S);
} }