CodeSolved

Solved Programming Questions & Exercises

Power to be able

Practice Easy 249/ Download 2718 Views

Write a program that receives two integers m and n from the user andOnly with the operator of the pluralThe number m is to the power of n

15 Answers

This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
m = int(input("please enter a number: "))
n = int(input("please enter a number: "))
a = 1
for i in range(0, n):
    a *= m
print(a)

Where is the collector ???? User 35


m = int(input("m ra vared konid: "))
n = int(input("n ra vared konid: "))

print(m ** n)
Shayan.fm Download Python
def power_using_addition(m, n):
    # If n is negative, the result is 0
    if n < 0:
        return 0
    # If n is equal to 0, the result is 1
    elif n == 0:
        return 1
    result = 0
    for _ in range(n):
        result += m  # The sum of m to the number of n
    return result

# Get input from the user
try:
    m = int(input("عدد m را وارد کنید: "))
    n = int(input("عدد n را وارد کنید: "))
    
    # The calculation and display of the result
    result = power_using_addition(m, n)
    print(f"{m} به توان {n} برابر است با: {result}")
except ValueError:
    print("لطفاً یک عدد صحیح وارد کنید.")
Mma123 Download Python
def click(m,n):
    return f"natije = {m ** n}"
print(click(m=int(input("enter:")),n=int(input("enter:"))))
Sumy.amiri Download Python
/*
این بخش رو فقط برای پیدا کردن یک فرمول برای حل این سوال نوشتم
در ضمن زبان برنامه  سی پلاس پلاس هست

     x = شماره الگو = n - 1
     y = تعداد ضرب در خودش = n * m
     n = عدد اول = input
     m = عدد دوم = input


     x      n ** m  ==>  y = n * m      ==>
     ---------------------------------------------------------------------
     1 :    3 ** 2  ==>  3 * 3          ==>  3 + 3 + 3
     2 :    3 ** 3  ==>  3 * 3 * 3      ==>  3 + 3 + 3 + 3 + 3 + 3
     3 :    3 ** 4  ==>  3 * 3 * 3 * 3  ==>  3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3

     0 = 1 = 2 = 3  = 4  = 5   = 6
     1 = 3 = 9 = 27 = 81 = 243 = 729
    */

#include <conio.h>
#include <iostream>
using namespace std;

int main() {
    int x, y;
    while (1 == 1) {
        cout<< " Please enter x and y or enter 0 and 0 for exit : " ;
        cin >> x >> y;
        int l = 1;
        int i = 1;
        if (x != 0 && y != 0) {
            while (i <= y) {
                int temp = 0;
                for (int j = 0; j < x; ++j) {
                    temp += l;
                }
                l = temp;
                i++;
            }
        }
        else {
            cout << '\n' << '\n' << " OK. Thanks for use my app, Bye!!" ;
            break;
        }
        cout<< " It is Result : " ;
        cout << " " << l << '\n' << '\n' ;
    }
    getch();
}
from itertools import product

def f01(m , n):
    m = m
    n = n
    m2 = 0

    for i in product(range(m),repeat=n-1):
        m2 = m2 + m
    print(m2)

f01(5,3)
while True:
    try:
        x = int(input("m: "))
        y = input("n: ")
        if y == "0":
            print("1")
        elif x >= 0 and int(y) >= 0:
            f01(x,int(y))
        else:
            print("این برنامه برای محاسبه اعداد منفی نمیباشد")
    except ValueError:
        print("لطفا عدد وارد کنید")

'''
توضیحات بیشتر:
ماژول پروداکت رو ایمپورت کردم تا به جای نوشتن چند بار حلقه تو در تو از این ماژول استفاده کنم

روش سنتی:
for i in range(m):
    for j in range(m):
        for h in range(m):
            print("hello world")

روش ماژول پروداکت:
for i, j, h in product(range(m),range(m),range(m)):
    print("hello world")

برای تعداد تکرار مشخص:
for i in product(range(m),repeat=n):
    print("hello world")
'''
def tavan(m,n):
    a=0
    if n==0:
        result=1
        print(result)
    elif n>m:
        print('n bayad az m kamtar basheh!') # I can't just solve this part with the collector for now
    else:
        for i in range(1,m+1):
            a+=m
        print(a)

m=int(input('m: '))
n=int(input('n: '))
tavan(m,n)
User 35 Download Python
<< Previous page 1 2 Next page >>

Submit answer

Submitting answers is currently unavailable.

×
×
Close