URI Online Judge | 1149
Somando Inteiros Consecutivos
Adaptado por Neilor Tonin, URI
Brasil
Timelimit: 1
Faça um algoritmo para ler um valor A e um valor N. Imprimir a soma dos N números a partir de A(inclusive). Enquanto N for negativo ou ZERO, um novo N(apenas N) deve ser lido.
Entrada
A entrada contém somente valores inteiros, podendo ser positivos ou negativos. Todos os valores estão na mesma linha.
Saída
A saída contém apenas um valor inteiro.
URI Online Judge | 1149
Summing Consecutive Integers
Adapted by Neilor Tonin, URI
Brazil
Timelimit: 1
Write an algorithm to read a value A and a value N. Print the sum of N numbers from A (inclusive). While N is negative or ZERO, a new N (only N) must be read. All input values are in the same line.
Input
The input contains only integer values, can be positive or negative.
Output
The output contains only an integer value.
#include <stdio.h>
int main()
{
int X, N, a,b=0;
scanf("%d %d", &X, &N);
while(N<=0)
scanf("%d", &N);
for(a=1; a<=N; a++)
{
b+=X;
X++;
}
printf("%d\n",b);
return 0;
}
Nenhum comentário:
Postar um comentário