Created
July 22, 2020 02:29
-
-
Save anitainfo/40c980efdfe7e243ffe9c41e753c9a3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> //biblioteca utilizada | |
using namespace std; | |
int main() | |
{ | |
int N,num,soma=0,padrao; //definição de variáveis | |
scanf("%d", &N); //lê a primeira linha de entrada | |
if(N%2==0) padrao=(N+1)*(N/2); //se 'N' for divisível por 2 (se 'N' é par), padrão recebe o valor da soma de a1 até an (a1+a2+a3....an-1,an) | |
else padrao=N*(N/2 + 1); //se não é divisível ('N' é ímpar), padrão recebe o valor da soma de a1 até an (a1+a2+a3....an-1,an) | |
for(int i=0; i<N-1; i++) //loop para ler a segunda linha de entrada ('N'-1 vezes de repetição) | |
{ | |
scanf("%d", &num); //lê um número | |
soma+=num; //soma-se 'num' a 'soma' | |
} | |
printf("%d", padrao-soma); //imprimi a resposta (soma ideal - soma real) | |
return 0; //retorna a 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment