I've been trying to code for subtraction of numbers from n number to 0 (i mean in decrementing order like if n is 5 then 5-4-3-2-1-0) in C language. But I'm not getting the correct answer for that. Here's my code for that, please correct me wherever it is wrong.
#include<stdio.h>
int main(void) {
int i, n, sum;
printf("Enter any number:");
scanf("%d", &n);
for(i=n; i>=0; i--) {
sum -= i;
}
printf("%d\n", sum);
}
I have done the same code for addition of numbers from 0 to n numbers. I got that right, and according to that code I tried for the subtraction but wasn't getting the right answer. Please help me out, thank you.