Write a program that computes the x^th term and summation of the following seque
ID: 3666519 • Letter: W
Question
Write a program that computes the x^th 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 1^st and x^th term. 1, square root 2:2;... Compute the summation of all the elements between x^th and 100^th term. 1^3, 2^3, 3^3.... Compute the summation of all the odd position elements between x^th and 100^th term. Summation_n - i^j n^2 Assume that i and j are integers from user input, where i, j > 0 and iExplanation / Answer
1.
#include<stdio.h>
int main()
{
int x,i,sum=0;
cout<<"enter the number";
cin>>x;
for(i=0;i<=x;i++)
{
sum+=i;
}
cout<<"sum is"<<sum;
return 0;
}
2.
#include<stdio.h>
int main()
{
int x,i,sum=0;
cout<<"enter the number";
cin>>x;
if(x!=0&&x!=100)
{
for(i=x;i<=100;i++)
{
sum+=i;
}
}
cout<<"sum is"<<sum;
return 0;
}
3.
#include<stdio.h>
int main()
{
int oddSum = 0,n;
cout<<"enter n";
cin>>n;
bool odd = true;
while (n != 0)
{
if (odd)
{
oddSum += n % 10;
}
cout<<"sum is"<<oddSum;
return 0;
}
4.
#include<stdio.h>
int main()
{
int i,j,k,sum=0;
cout<<"enter i and j";
cin>>i>>j;
if(j>0&&i<j)
{
for(k=i;k<j;k++)
{
sum+=k;
}
}
cout<<"sum is"<<sum;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.