fork(4) download
  1. #include <stdio.h>
  2.  
  3. int tob (int b, int* arr);
  4. int pp(int a, int b);
  5.  
  6. int tob (int b, int* arr) {
  7. int i;
  8. for (i = 0; b>0; ++i) {
  9. if (b%2) arr [i] = 1;
  10. else arr[i] = 0;
  11. b = b/2;
  12. printf("value of i =%d\n",i);
  13. }
  14. printf("value of i after iteration =%d",i);
  15. printf("\n");
  16. return (i);
  17. }
  18.  
  19.  
  20. int pp(int a, int b) {
  21. int arr[20];
  22. int i, tot = 1, ex, len;
  23. ex = a;
  24. len = tob(b, arr);
  25. printf("\n");
  26. printf("length=%d\n",len);
  27. for (i=0; i<len ; i++) {
  28. if (arr[i] ==1)
  29. tot = tot * ex;
  30. ex= ex*ex;
  31. }
  32. return (tot) ;
  33. }
  34.  
  35.  
  36. int main()
  37. {
  38.  
  39. printf("%d\n", pp(3, 4));
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 5524KB
stdin
Standard input is empty
stdout
value of i =0
value of i =1
value of i =2
value of i after iteration =3

length=3
81