Skip to content

Instantly share code, notes, and snippets.

@fsouza
Created December 15, 2010 22:32
Show Gist options
  • Save fsouza/742717 to your computer and use it in GitHub Desktop.
Save fsouza/742717 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int produto (int a, int b) {
int vet1[20], vet2[20];
int soma, i, j;
vet2[0]=b;
vet1[0]=a;
i=1;
while (vet1[i]!=1) {
if ((vet1[i-1] % 2)==1) {
vet1[i]=(vet1[i-1]-1)/2;
} else
vet1[i] = vet1[i-1]/2;
vet2[i] = vet2[i-1]*2;
i++;
}
soma =0;
for (j=0;j<i;j++) {
if ((vet1[j] % 2)==1) {
soma = soma + vet2[j];
}
}
return (soma);
}
int main () {
int valor1[10], valor2[10], prod[10];
int i;
for (i=0;i<10;i++) {
printf ("Par %d", i+1);
printf ("Valor1: ");
scanf ("%d", &valor1[i]);
printf ("Valor2: ");
scanf ("%d", &valor2[i]);
printf ("\n");
}
for (i=0;i<10;i++) {
prod[i]= produto(valor1[i], valor2[i]);
}
for (i=0;i<10;i++) {
printf ("%d vezes %d : %d\n", valor1[i], valor2[i], prod[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment