A.P

PHOTO EMBED

Mon Oct 30 2023 11:35:21 GMT+0000 (Coordinated Universal Time)

Saved by @yolobotoffender

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main(){
    int a1,d,n,sum;
    char opt;
         
    cout<<"press 'e' for exit and 'c' for continue:"<<endl;
    cin>>opt;
    if(opt !='e' || opt != 'c' ){cout<<"invalid option: "<<endl; }
    else{
     while(opt != 'e' && opt == 'c'){ 
    cout<<"enter the starting number:"<<endl;
    cin>>a1;
    cout<<"enter the common difference:"<<endl;
    cin>>d;
    cout<<"enter the number of terms in the series:"<<endl;
    cin>>n;
    
    sum = (n*2*a1+n*d*(n-1))/2;
    
    cout<<sum<<endl;
    }
    }
    
    
    
    
    
}
content_copyCOPY