Практикум по программированию. Основы. Циклы. Возведение в степень

From AsIsWiki
(Difference between revisions)
Jump to: navigation, search
Line 8: Line 8:
 
==Java==
 
==Java==
  
<pre>
+
<source lang="java">
 
import java.util.Scanner;
 
import java.util.Scanner;
  
Line 39: Line 39:
 
     }
 
     }
 
}
 
}
</pre>
+
</source>
  
  
 
==C++==
 
==C++==
  
<pre>
+
<source lang="cpp">
 
// g++ 4.2
 
// g++ 4.2
  
Line 78: Line 78:
 
     return 0;
 
     return 0;
 
}
 
}
</pre>
+
</source>
  
  
 
==Pascal==
 
==Pascal==
  
<pre>
+
<source lang="delphi">
</pre>
+
</source>
 +
 
 +
 
 +
==JavaScript==
 +
 
 +
<source lang="js">
 +
</source>
  
  

Revision as of 09:35, 19 March 2016

Назад · Задачи · Дальше


Contents

Java

import java.util.Scanner;

public class Task04 {

    public static void main(String[] args) {
        
        Scanner in = new Scanner(System.in);
        
	System.out.println();
        System.out.println("      Вычисление степени       ");
        System.out.println(" с натуральным показателем A^N ");
        System.out.println("-------------------------------");

        System.out.print(" Введите основание степени A: "); 
	double a = in.nextDouble();

        System.out.print(" Введите показатель степени N: "); 
	long n = in.nextLong();

        System.out.println("-------------------------------");
        
	double p = 1;

	for (long i = 1; i <= n; i++) {
	    p *= a;
	}

	System.out.printf(" A^N = %.2f\n", p);
    }
}


C++

// g++ 4.2

#include <iostream>

using namespace std;

int main() {
    
    double a;
    long n;
    
    cout << "\n      Вычисление степени\n";
    cout << " с натуральным показателем A^N\n";
    cout << "-------------------------------\n";
    
    cout << " Введите основание степени A: ";
    cin >> a;
    
    cout << " Введите показатель степени N: ";
    cin >> n;
    
    cout << "-------------------------------\n";
    
    double p = 1;
    
    for (long i = 1; i <= n; i++) {
        p *= a;
    }
    
    printf(" A^N = %.2f\n\n", p);
    
    return 0;
}


Pascal



JavaScript




Назад · Задачи · Дальше

Personal tools
Namespaces

Variants
Actions
Navigation
Tools