Write a program in C++ to find power of any number using for loop

  • برمجة سي بلس بلس
  • برمجة

Write a program in C++ to find power of any number using for loop

Sample Output:

 Find power of any number using for loop:                              
---------------------------------------------                          
 Input the base: 2                                                     
 Input the exponent: 5                                                 
2 ^ 5 = 32

الأجوبة

#include <iostream>
using namespace std;
int main()
{
    int bs, ex, num=1,i;
    cout << "\n\n Find power of any number using for loop:\n";
    cout << "---------------------------------------------\n";
    cout << " Input the base: ";
    cin >> bs;
    cout << " Input the exponent: ";
	cin>>ex;
	
    for (i = 1; i <=ex; i++) 
    {
       num=num*bs;
    }
	cout <<bs<<" ^ "<<ex<<" = "<<num<<endl ;
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...