Exemplo n.º 1
0
int main(){
    int n;
    
    for(scanf("%d\n", &n); n > 0; n--){
        char licence[9];
        licence[0] = 0;
        scanf("%s", licence);

        int i;
        int sum;
        int count = 0;
        for(i = 0, sum = 2; i < 3; i++, sum--) count += ((licence[i] - 'A') * exponentiation(26, sum));

        sum = 0;
        for(i = 4; i < 8; i++){
            sum *= 10;
            sum += licence[i] - '0';
        }

        int total = (count - sum < 0) ? sum - count : count - sum; 

        if(total <= 100) printf("nice\n");
        else printf("not nice\n");
    }
}
Exemplo n.º 2
0
int main() {
    int ch;
    do {
	printf("What should i do?\n");
	printf("1. Factorial\n");
	printf("2. Exponentiation\n");
	printf("3. Exit\n");
	printf("Enter your choice:");
	scanf("%d", &ch);
	switch(ch) {
	case 1:
	    factorial();
	    break;
	case 2:
	    exponentiation();
	    break;
	case 3:
	    printf("Bye!\n");
	    break;
	default:
	    printf("Invalid option. Please Reselect\n");
	    break;
	}
    }while(ch!=3);
    return 0;
}
Exemplo n.º 3
0
int main()
{
	int i =0;
	for(i = 0;i < 11;i++)
		printf("%d\n",exponentiation(2,i));
	return 0;
}
Exemplo n.º 4
0
int exponentiation(int x, int y)
{

        //base case : y = 0
    if (y == 0){
        return 1;
    }
    return x * exponentiation(x, y - 1); 

}
Exemplo n.º 5
0
int main() {
    int p, q, r;
    int exponentiationResult;

    printf("Digite p: ");
    scanf("%d", &p);

    r = 0;
    while(!rmax(r, p)) {
        q = (r*2*p) + 1;
        exponentiationResult = exponentiation(2, p, q);

        printf("\n2^%d mod %d = %d", p, q, exponentiationResult);

        if(exponentiationResult == 1) {
            printf("\n\n\t%d e' um fator de M(%d) = 2^%d - 1\n\n", q, p, p);
            return 0;
        }
        r++;
    }

    printf("\n\n\tM(%d) = 2^%d - 1 eh um numero primo.\n\n", p, p);
    return 0;
}