fork download
  1. #include <stdio.h>
  2.  
  3. int power(int a, int b){
  4. int c = 1;
  5. while (b> 0){//カッコ内をb-->0にして7行目のb--をなくしても実行できる
  6. c *= a;
  7. b--;
  8. }
  9.  
  10.  
  11. return c;
  12. }
  13.  
  14. int main(void) {
  15. int x,n,y;
  16. x = 2;
  17. n = 4;
  18. y = power(x,n);
  19. printf("%d の %d 乗は %d",x,n,y);
  20.  
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 5332KB
stdin
Standard input is empty
stdout
2 の 4 乗は 16