jeudi 7 juillet 2016

how the scanf() is executing before printf()

I have the following code to just implement the pow() as in math.h library. Well I have two questions:

  1. Why the scanf() statement is taking input before it prints "power:" from the printf() function?
  2. How can I calculate the power of big integers, like suppose the power calculated is like : 22235645654789787978797797 (just for example). How do I calculate and print it.

    #include <stdio.h>
    unsigned long long int pow(unsigned long long int n,unsigned long long int d);
    int main(){
    
    unsigned long long int a,x,n;
    printf("Number:");
    scanf("%un",&a);
    printf("power:");
    scanf("%un",&n);
    x = pow(n,a);
    printf("%un",x);
    }
    unsigned long long int pow(unsigned long long int n,unsigned long long int d){
    if(n+1==1)
        return 1;
    return d*pow(n-1,d);
    }
    

Image

In the image you can see the input of variable n is taking input before printing "power:" from printf(), so no matter what input do you type.

Please help me understand it. Open for any suggestions and comments.

Aucun commentaire:

Enregistrer un commentaire