Hey guys, i've just started learning c, and i'm writing one of my first programs. I'm having some problems running it, though. Here is the code :
Code:
#include <stdio.h>
int main ()
{
int soma,n,nf,nz;
soma = 0;
n = 0;
printf ("Digite o primeiro termo da sequência");
scanf("%d", &nz);
printf ("digite o termo final da sequência");
scanf("%d", &nf);
printf ("o programa calculara a soma de todos os termos dentro da sequência/n");
while (nz+n<=nf) {
soma = soma + nz + n ;
n=n+1 ;
}
printf("%d",soma);
return 0 ;
}
Here's a quick tutorial of what it does (the text is in portuguese, i forgot to translate) : First i type the first number of a sequence, then, i type the last one, and then the program should sum all of the numbers within the sequence, including the first and last number. (i've tested on paper and so far it works with positive integers).
My problem is that the program doesn't print "soma" ( soma = sum) after the while loop ends. How can i fix it?