123krikit krukut
123krikit krukut

Reputation: 1

C program to find last three digits of a^b

So, for small numbers my code does work, but it doesn't work for big numbers, for instance 100^10. So someone could help me finding my mistakes, or point out some clues for me to fix my code.

#include <stdio.h>
int main ( )  
{  
    int n , exp ,  i;  
    char a[1000];
    long long int value = 1 ;   
    scanf ( "%d %d" , & n , & exp ) ;    
    while ( exp --> 0 )  
    {  
        value *= n ;  
    }  
    
    if (value>999)
    {
    for (i=2; i>=0; i--) 
    {
        a[i]=value%10;
        value = value/10;
      }  
    

        printf ("The last 3 numbers is %d%d%d.\n",a[0],a[1],a[2]);
        
    

}
    else 
    printf ("The last 3 numbers is %d.\n", value);
    return 0; 
}

Upvotes: 0

Views: 111

Answers (0)

Related Questions