Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Scrivere un programma che, dati due numeri interi M e N, calcoli M^N.
- Implementazione iterativa.
- */
- #include <stdio.h>
- int pot(int,int);
- int main() {
- int m,n; // m => base, n => esponente
- printf("Base > ");
- scanf("%d", &m);
- printf("Esponente > ");
- scanf("%d", &n);
- printf("%d^%d = %d\n",m,n,pot(m,n)); // Stampa dei risultati
- return 0;
- }
- // Funzione potenza
- int pot(int b, int e){
- int i,r = 1; // i => contatore del for, r => risultato
- for (i = 0; i < e; i++) { // Moltiplico la base per se stessa "e" volte
- r = b*r;
- }
- return r;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement