Write pseudocode to sum consecutive odd integers Let the low
Write pseudocode to sum consecutive odd integers. Let the lowest odd integer be L and the highest odd integer be H, and let both L and H be provided by the user.
Solution
// C++ code to sum consecutive odd integers from L to H
#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
#include <iomanip>
#include <math.h>
#include <vector>
#include <algorithm>
#include <ctime>
#include <limits.h>
using namespace std;
int main()
{
//Initialize total to zero
int total = 0;
// declaare L and H
int L, H;
// input L and H from the user
cout << \"Enter L: \";
cin >> L;
cout << \"Enter H: \";
cin >> H;
// for loop from L to H
for (int value = L; value <= H ; ++value)
{
// check if value is odd
if(value%2 != 0)
// update total
total = total + value;
}
// print the result
cout << \"Total: \" << total << endl;
return 0;
}
/*
output:
Enter L: 11
Enter H: 21
Total: 96
*/
