Today I have some question and their solution ,but I have problem with some.
Q1: Write a program that checks if a sequence of positive numbers is in increasing order or not.
I don't know what is missing her?!
Solution:
#include<iostream>
using namespace std;
int main(){
int value,check=1;
cout<<"Enter a number: ";
cin>>value;
while(value>=0)
{
int newvalue;
cout<<"Enter another value: ";
cin>>newvalue;
if(value>newvalue)
cout<<" ....Not sequence";
value=-1;
else
value=nwvalue;
if(check==1)
cout<<"....is increasing";
}
return 0;
}
Q 2: Let f(x,n) = x –x3/3! + x5/5! - …+(-1)n x2n+1 /(2n+1)!
Using a loop write a program to calculate f(x,n).
Solution:
#include<iostream>
#include<cmath>
using namespace std;
int main(){
cout<<"Enter a number ";
int m;
cin>>m;
for(double x=1;x<=m;x++)
{
for(double n=1;n<=x;n++)
{
n=2*n+1;
double fact=1;
fact*=n;
double f=1;
f=pow(x,n)/fact;
cout<<f<<endl;
f*=-1;
}
double f;
cout<< f<<endl;
}
return 0;
}
Q3: Write a program that prints all possible combinations of 3 numbers between 1 and n.
After I run the compiler ,the output doesn't stop.
Solution:
#include<iostream>
using namespace std;
int main(){
cout<<"Enter a number : ";
int num;
cin>>num;
for(int i=1;i<=num-2;i++)
{
cout<<i<<endl;
for(int j=1;j=num-1;j++)
{
cout<<j<<endl;
for(int k=1;k<=num;k++)
{
cout<<k<<endl;
}
}
}
return 0;
}
Please tell me, What are my mistakes?