Hello fairly new at coding, i have this program which should add a number each time the program is run, it computes 1 + 2 + 3 +......(n - 1) + n and an if statement that compares the value to (n*(n+1))/2 and then displays a message if its the same or different.
#include <stdio.h>
int main(void)
{
int value = 0, n_data_value, count = 0, second_value;
printf("Enter a number\n");
scanf("%lf", &n_data_value);
while (count < 10) {
value = (1 + value) + (n_data_value - 1) + n_data_value;
printf("%f\n", value);
second_value = (n_data_value * (n_data_value + 1))/2;
printf("The number is %f\n", value);
count = count + 1;
if(value = second_value){
printf("value = %f and second_value = %f", value, second_value);
}
}
return 0;
}
When i run it i just get this
Enter a number 3
0.000000
The number is 0.000000
0.000000
The number is 0.000000
0.000000
The number is 0.000000
0.000000
The number is 0.000000
0.000000
The number is 0.000000
0.000000
The number is 0.000000
0.000000
The number is 0.000000
0.000000
The number is 0.000000
0.000000
The number is 0.000000
0.000000
The number is 0.000000
N=65535. See stackoverflow.com/questions/12923523/…