0
Good evening, I wonder, why my code return a wrong value for a case in which the input is 1.1 and 100000, the output should give 100000 and 5000050000 and this giving 100000 and 705082704?? the output should be double or float??
#include <stdio.h> //Bibliteca para as fuñcoes de entrada e saida
int main (void) //Programa principal
{
int a1, r, n, An, Sn; //Declaracao das variaveis necessarias
scanf("%d\n%d\n%d",&a1, &r, &n); //Insercao dos valores de A1, r e n
An = a1+(n-1)*r; //Formula para encontrar o enesimo termo da PA
printf("%d\n", An); //Impressao na tela do valor do enesimo termo encontrado
Sn = (a1+An)*n/2; //Formula para fazer a soma dos "n" termos da PA
printf("%d", Sn); //Impressao na tela do valor da soma da PA
return 0;
}
And how can I solve this problem??
– Gabriel Vinicius
You can use a data type with upper limits (
long
for example), or if you intend to use really large numbers (with thousands of bits) use a bignum library (article in English).– pmg