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;...
Hello Everyone!Now we will discuss about the switch statement. It is a kind of Selective Flow statement that tests the equality of a variable or expression with a list of Values,also called cases ,and execute the cases which satisfies the condition till there is a break or end of switch statement.There can also be a default case which executes when no other case matches with the variable.For example:- int main() { int n; cout<<"Enter Your Marks in C++ out of 10="; cin>>n; switch(n) { case 10:cout<<"Grade=O";break; case 9:cout<<"Grade=A+";break; case 8:cout<<"Grade=A";break; case 7:cout<<"Grade=B+";break; case 6:cout<<"Grade=B";break; case 5:cout<<"Grade=C";break; case 4:cout<<"Grade=D";break; case 3: case 2: case 1:cout<<"Grade=F";break; default:cout<<"Absent"; } return 0; } In the above...
Comments
Post a Comment