**********WRITE ONE C++ PROGRAM*********** Write a program that computes the x t
ID: 3923628 • Letter: #
Question
**********WRITE ONE C++ PROGRAM***********
Write a program that computes the xth term and summation of the following sequences, where x is a user input between 1 and 100.
1. -1,1,3,5,7,....
Compute the summation of all the elements between 1st and xth term.
2. 1,-sqrt(2),2,....
Compute the summation of all the elements between xth and 100th term.
3. 13,23,33
compute the summation of all the odd postion elements between xth and 100th term.
4. jn=i n2
assume that i and j are integers from user input, where i, j>0 and i<j. write a program that computes the summation of all the elements between ith and jth term.
Explanation / Answer
#include <iostream>
using namespace std;
int main(){
int number;
int x,i,j;
int sum = 0;
cout << "Enter a positive integer: ";
cin >> x;
for(number = -1;number <= x; number++)
if (number%2!=0)
sum = sum + number;
cout << "Sum = " << sum;
cout<<" ";
sum=0;
for (number=x;number<=100;number++)
sum=sum+number;
cout << "Sum = " << sum;
cout<<" ";
sum=0;
for (number=x;number<=100;number++)
if (number%2!=0)
sum = sum + number;
cout << "Sum = " << sum;
cout<<" ";
sum=0;
cout << "Enter I: ";
cin >> i;
cout << "Enter J: Greater than J";
cin >> j;
for (number=i;number<=j;number++)
sum=sum+number;
cout << "Sum = " << sum;
cout<<" ";
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.