Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1. Найти сумму от одного до 100;
- console.log("№1");
- {
- let a = 100, sum = 0;
- for(let i = 0, j = 10; i <= 100; i++){
- sum = sum + i;
- // console.log(j);
- }
- console.log(sum);
- }
- //2. Дано a -> (число а это n-значное число) найдите сумму цифр.
- {
- console.log("№2");
- let a = 123456, s = 0, i = 1, n = a;
- for(i = 1; i < n; i++){
- s += a % 10;
- a = (a - a%10) / 10;
- }
- console.log("S = " + s );
- }
- //3. Выведите все четные числа от 10 до 50
- {
- console.log("№3 ");
- let a = 10, b = 50;
- for( let i = a; i <= b; i = i + 2){
- console.log(i);
- }
- }
- //4. Выведите число 1 1-раза. 2 2-раз. 3 3-раза .. a a-раз,.
- {
- console.log("№4 ");
- let n = 10, j = 1;
- for(let i = 1; i <= 10; i++){
- for(j = 1; j <= i; j++ ){
- console.log(i);
- }
- j = 1;
- }
- }
- //5. Дано n = 15, найдите число Фибоначи под n.Fin1 = 1 Fin2 = 1 Fin3 = Fin1 + Fin2; Fin(n) = Fin(n - 1) + Fin(n - 2);
- {
- console.log("№5");
- let n = 15, f1 = 1, f2 = 1, fn;
- for(let i = 3; i <= n; i++) {
- fn = f1 + f2;
- f1 = f2;
- f2 = fn;
- }
- console.log(fn);
- }
- //6. Дано n = 5. найдите n!
- {
- console.log("№6");
- let n = 5, x = 1;
- for(let i = 1; i <= n; i++) {
- x = i * x;
- }
- console.log(x);
- }
- //7. Дано n = 4, r = 2. Найдите Combination. Combination formula ( n! / ( r! * ( n -r )! ) )
- {
- console.log("№7");
- let i; s = 1; r = 2, n = 4;
- let x1 = 1, x2 = 1, x3 = 1;
- for(i = 1; i <= n; i++){
- x1 = x1 * i;
- }
- for(i = 1; i <= r; i++){
- x2 = x2 * i;
- }
- for(i = 1 ; i <= (n-r); i++){
- x3 = x3 * i;
- }
- s = x1 / (x2 * x3);
- console.log(s);
- }
- //8. Дано число a. Простое ли число?
- {
- console.log("№8");
- let a = 10 , i = 2, k;
- let x = 0 ;
- if (a % 2 == 0 && a != 2) {
- console.log(" Нет ");
- }
- else {
- for( i = 2; i <= a; i++){
- if (a != i){
- k = a % i;
- if (k == 0){
- x = 1;
- }
- }
- }
- if (x > 0){
- console.log("Нет");
- }
- if (x === 0){
- console.log("Да");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement