الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مسالة

مغلق
بدأه طالب برمجة في 30 نوفمبر 2003 · 2 رد · 1,221 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

اخواني لو سمحتو اذا ممكن حد يساعدني او يعطيني فكره حل اهذي المساله

Write a function Power(base, exponent) that when invoked returns

For example, Power(3,4) = 3 * 3 * 3 *3. Assume that exponent is an integer greater than or equal to 1. Use this function in a program that inputs base and exponent in a loop until user enters negative value for the exponent.

#2

وهذا الحل..............

#include<iostream>

#include<cmath>

using namespace std;

int base , exponent,x;

int main()

{

cout<<"Enter a number of base & exponent"<<endl;

cin>>base>>exponent;

while(exponent>=1)

{

x = pow(base,exponent);

cout<<x<<endl;

cin>>base>>exponent;

}

return 0;

}

#3

هذا هو الحل الصحيح.. باستخدام النداء المتكرر للدالة..

#include<stdio.h>

int power(int,int);

void main()
{
	int base,ex;
	printf("Enter the base: ");
	scanf("%d",&base);
	printf("Enter the exponent: ");
	scanf("%d",&ex);
	printf("The power is %d\n",power(base,ex));
}

int power(a,b)
{
	if(b==0)
  return 1;
	else
  return a*power(a,b-1);
}

هذا الموضوع مغلق.

مواضيع مشابهة