Design an algorithm and the corresponding flowchart for finding the sum of the numbers 2, 4, 6, 8, …, n
#include<iostream>
using namespace std;
float sum(float a, float d, int n) {
float sum = 0;
for (int i=0;i<n;i++) {
sum = sum + a;
a = a + d;
}
return sum;
}
int main() {
int n = 10;
float a = 2, d = 2;
cout<<"sum of series A.P is : "<<sum(a, d, n);
return 0;
}
Algorithm:
Comments
Leave a comment