Download - prog c++

Transcript
Page 1: prog c++

16

#include<iostream>

#include<math.h>

using namespace std;

int main()

{

int x,y,count1;

float t;

cout<<"enter any no. greater than 3"<<endl;

cin>>x;

t=x/2;

for(y=2;y<=t;y++)

{

if(x%y==0)

count1=1; }

if(count1==1)

cout<<"the no is not prime";

else

cout<<"the no.is prime";

return 0;}

Page 2: prog c++

17

#include<iostream>

#include<math.h>

using namespace std;

int main()

{

int n,m,x,y,z,count1=0,a=0,b=0;

float t;

cout<<"enter any two no. greater than 3"<<endl;

cin>>m>>n;

while(m<=n)

{

t=sqrt(m);

count1=0;

for(y=2;y<=t;y++)

{

if(m%y==0)

count1=1;

}

if(count1!=1)

cout<<"the prime no is "<<m<<"\n";}

m++;

}

return 0;}

Page 3: prog c++

18

#include<iostream>

#include<math.h>

using namespace std;

int main()

{

int n,m,x,y,z,count1=0,a=0,b=0;

float t;

cout<<"enter any two no. greater than 3"<<endl;

cin>>m>>n;

while(m<=n)

{

t=m/2;

count1=0;

for(y=2;y<=t;y++)

{

if(m%y==0)

count1=1;

}

if(count1==1)

cout<<"the no is not prime\n";

else

Page 4: prog c++

{cout<<"the no.is prime\n";

a=a+1;}

m++;

}

cout<<"\n The no of prime no.is"<<a;

return 0;

}

24

#include<iostream>

#include<math.h>

using namespace std;

int main()

{

float a=0,x,b=0,i,y,n,z,sum=0,f;

cout<<"enter any no. and the n(th)term \n";

cin>>x>>n;

while(a<n&&b<n)

{

a++;

b++;

Page 5: prog c++

f=1;

for(i=1;i<=b;i++)

{ f=f*i;

}

y=(pow(x,a))/f;

cout<<y<<" ";

sum = sum + y;

}

cout<<"="<<sum+1;

return 0;

}

23

#include<iostream>

#include<math.h>

using namespace std;

int main()

{

float a=0,x,b=0,y,n,z,sum=0;

cout<<"enter any no. and the n(th)term \n";

cin>>x>>n;

Page 6: prog c++

while(a<n&&b<n)

{

a++;

b++;

y=(pow(x,a))/b;

sum = sum + y;

}

cout<<sum+1;

return 0;

}

22

#include<iostream>

#include<math.h>

using namespace std;

int main()

{

int x,y,n,z,sum=0;

Page 7: prog c++

cout<<"enter any no. and the n(th)term \n";

cin>>x>>n;

for(z=1;z<=n;z++)

{

y=pow(x,z);

sum = sum + y;

}

cout<<(2*x)-sum;

return 0;

}

26

#include<iostream>

#include<math.h>

using namespace std;

int main()

{

float b=0,i,y,n,z,sum=0,f;

int x,a=0;

cout<<"enter any no. and the n(th)term \n";

Page 8: prog c++

cin>>x>>n;

{

while(a<2*n&&b<2*n)

{

a++;

b++;

if(a%2!=0)

{

f=1;

for(i=1;i<=b;i++)

{ f=f*i;

}

y=(pow(x,a))/f;

sum = sum + y;

}}

cout<<"="<<sum+1-x;

return 0;

}}

Page 9: prog c++

Top Related