43 lines
724 B
C
43 lines
724 B
C
#include <stdio.h>
|
|
|
|
// n-th term of an Arithmetic Sequence
|
|
// an = a1 + (n-1)*d
|
|
|
|
|
|
int main(void) {
|
|
|
|
int startValue, distValue, numOfValues, result;
|
|
|
|
printf("Hello to your n-th Term calculation!\n");
|
|
|
|
printf("Enter start value: ");
|
|
scanf("%d", &startValue);
|
|
|
|
printf("Enter the distance between the values: ");
|
|
scanf("%d", &distValue);
|
|
|
|
printf("Enter the number of calculations: ");
|
|
scanf("%d", &numOfValues);
|
|
|
|
|
|
result = startValue + (numOfValues -1) * distValue;
|
|
|
|
|
|
/*
|
|
for (int i = 0; i < numOfValues ; ++i) {
|
|
result = startValue;
|
|
printf("%d ", result);
|
|
startValue += distValue;
|
|
}
|
|
*/
|
|
|
|
printf("\nThe n-th term is: %d\n",result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
}
|