Write a program that calculates element of sequence by its index if given first and second elements of arithmetic sequence.Input first, second elements of sequence and index:
1 5 3
1
Expert's answer
2013-09-10T11:06:24-0400
#include <cstdlib> #include <iostream>
using namespace std;
int main() { int a,b,n; cin>>a>>b>>n; cout<<a+(n-1)*(b-a)<<endl; cin.get(); cin.get(); return 0; }
Comments
Leave a comment