Posts

Showing posts from July, 2017
Solutions:- 1) W.A.P. to display roots of a quadratic equation where coefficients a,b,c are given ?   #include<iostream> #include<cmath> using namespace std; int main() { int a,b,c; float D,r1,r2; cout<<"Enter the Coefficients of the quadratic equation-"; cin>>a>>b>>c; D=pow(b,2) - (4*a*c); if(D<0) {cout<<"\nNo Real Roots"; return 0;} else {if(D>0) { cout<<"\nDistinct Real Roots\n"; r1=(-b + sqrt(D))/(2*a); r2=(-b - sqrt(D))/(2*a); cout<<"Roots ="<<r1<<" "<<r2;} else{ cout<<"\nEqual Roots\n";r1=-b/(2*a); cout<<"Root ="<<r1; }} return 0;} 2) W.A.P. to check whether a given number is prime or not ?   #include<iostream> using namespace std; int main() {  int n; char p='Y';  cout<<"Enter a number=";  cin>>n; if(n==1) p='N'; for(int i=2;i<=n/2;...