0
I’m solving a small exercise in C that should print the predecessor and successor of a number on screen. The predecessor prints correctly, but the successor always shows 108. regardless of the number typed. I imagine it’s kind of garbage. How do you fix this?
#include <stdio.h>
#include<stdlib.h>
int main ()
{
int numero,antecessor,sucessor;
printf("\n Escreva um numero inteiro: ");
scanf("%d",&numero);
antecessor=numero-1;
sucessor+numero+1;
printf("=============================================\n\n");
printf("\n O antecessor do numero %d e %d\n\n", numero, antecessor);
printf("=============================================\n\n");
printf("\n O sucessor do numero %d e %d\n\n", numero, sucessor);
printf("=============================================\n\n");
system("pause");
return(0);
}
IN TIME: I apologize to everyone. The mistake had nothing to do with garbage but with wrong typing on my part. Only after posting did I see that the second number (successor) was getting the value assignment wrong.
Instead of me writing:
successor=number+1
writ:
successor number+1
successor = number + 1 and not successor + number + 1
– pmargreff
Because it is pmargeff... Only after posting the doubt is that I saw that it was a typo! Thank you for the reply!
– JadilsonTorres