1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Program A2_20a; Var a,p:real; n,k:integer; BEGIN readln(a,n); p:=1; k:=n; while (k>0) do begin p:=p*a; k:=k-1; end; writeln(p); readln; END. |
//Program A2.20a; #include <iostream>
using namespace std;
int main() { double a,p; int n,k; cin>>a>>n; p=1; k=n; while(k>0) { p=p*a; k--; } cout << p << endl; return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Program A2_20b; Var a,b,p:real; n,k:integer; BEGIN readln(a,n); k:=n; p:=1; b:=a; while (k>0) do begin if (k mod 2=0) then begin k:=k div 2; b:=b*b; end else begin k:=k-1; p:=p*b; end; end; writeln(p); readln; END. |
//Program A2.20b; #include <iostream>
using namespace std;
int main() { double a,b,p; int n,k; cin>>a>>n; k = n; p = 1; b=a; while(k>0) { if(k%2==0) {k=k/2; b=b*b;} else { k--; p=p*b;} } cout << p<< endl; return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Program A2_20c; Var a,b,p:real; n,k,m:integer; BEGIN readln(a,n); k:=n; p:=1; b:=a; m:=0; while (k>0) do begin m:=m+1; if (k mod 2=0) then begin k:=k div 2; b:=b*b; end else begin k:=k-1; p:=p*b; end; end; writeln(p,' ',m); readln; END. |
//Program A2.20c; #include <iostream>
using namespace std;
int main() { double a,b,p; int n,k,m=0; cin>>a>>n; k = n; p = 1; b=a; while(k>0) { m++; if(k%2==0) {k=k/2; b=b*b;} else { k--; p=p*b;} } cout << p<<" "<<m<<endl; return 0; } |