[ create a new paste ] login | about

Link: http://codepad.org/hDSlsjEK    [ raw code | output | fork | 3 comments ]

C, pasted on Sep 11:
#include<stdio.h>
#include<conio.h>


#include<stdio.h>
#include<conio.h>


double Power_n(double x, long n)
{
	// n >= 0
	double result = 1;
	while(n--)
	{
		result = result * x;
	}
	return result;
}
double qPower_n(double x, long n)
{
	// n >= 0
	double result = 1;
	while(n)
	{
		if(n % 2 == 1)
		{
			result = result * x;
		}
		x = x * x;
		n = n / 2;
	}
	return result;
}
int main()
{
	double x = 4;
	long n = 2;
	double z;
	z = qPower_n(x, n);
	printf("z = %f", z);

	getch();
	return 0;
}


Output:
1
Line 17: error: conio.h: No such file or directory


Create a new paste based on this one


Comments:
posted by yonnon on Jul 17
#include<bits/stdc++.h>

using namespace std;
int main()
{
int x;
int y;
cout << "Enter x: ";
cin >> x;
cout << "Enter y: ";
cin >> y;
int S;
S = pow(x,y);
cout<<S<<
endl;
cin.ignore();
return 0;

}
reply
posted by Phamoanh on Oct 1
s=a^3*b^4
Ai chỉ em bài nay dc ko a.
reply
posted by lehoangan01 on Feb 1
#include <iostream>
#include <math.h>
using namespace std;

int tinhluythua(int x, int y){
if (y == 0) return 1;
if (y == 1) return x;
return x * tinhluythua(x, y - 1);
}

int main() {
int x, y, luythua;
printf("\nNhap vao x: ");
scanf("%d", &x);
printf("\nNhap vao y: ");
scanf("\%d", &y);
luythua = tinhluythua(x, y);
cout << luythua << endl;
return 0;
}
reply