Skip to content

Instantly share code, notes, and snippets.

@brunolpw
Created June 11, 2016 04:48
Show Gist options
  • Save brunolpw/12022d8533e2eed6f0133e009f359fcd to your computer and use it in GitHub Desktop.
Save brunolpw/12022d8533e2eed6f0133e009f359fcd to your computer and use it in GitHub Desktop.
#include <stdio.h>
/*
* Por Bruno La Porta
* Em 01/09/15
*
* Apenas um simples exemplo de como trocar os valores de uma variavel com outra sem a utilização de uma variavel auxiliar.
* */
int main()
{
int VA = 0;
int VB = 0;
// Recebe os valor para a variavel VA.
printf("insira o valor de VA: ");
scanf("%d", &VA);
// Recebe os valor para a variavel VB.
printf("insira o valor de VB: ");
scanf("%d", &VB);
// Mostra os valores atuais das variaveis.
printf("Antes \nVA = %d ~ VB = %d\n", VA, VB);
// Operação para inverter os valores das mesmas.
VA = VA + VB;
VB = VA - VB;
VA = VA - VB;
// Apresenta os valores atualizados.
printf("Depois \nVA = %d ~ VB = %d\n", VA, VB);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment