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;...
Posts
Showing posts from 2017
- Get link
- X
- Other Apps
Hello Everyone ! This time ,as i mentioned last time, we will discuss some examples related to what we have done. 1) W.A.P.(Write a Program) to enter 3 numbers and display the highest of them? Solution: #include<iostream> using namespace std; int main() { int a,b,c,max; cout <<"Enter 3 numbers:"; cin>>a>>b>>c; if(a>b && a>c) max=a; else { if(b>c) max=b; else max=c; } cout<<"\nMaximum = "<< max; return 0; } 2) W.A.P. to check whether a date entered in dd/mm/yy format is Valid or not? #include<iostream> using namespace std; int main() { int d,m,y,maxdays; char v='N'; cout<<"Enter a date as dd/mm/yy="; cin>>d>>m>>y; if(m>=1 && m<=12) { if (m==1 || m==3 || m==5 || m==7 || m==8|| m==10|| m==12) maxdays=31; else { if(m==2) { if((y%4...
- Get link
- X
- Other Apps
Hello Everyone. Now Lets Talk about the very useful if-else statements. It is a very simple type of Selective Statement but is of great Use. A If statement is Generally used to Compare Standard Data Types like integer,char ,double,etc. which is put inside parenthesis, whose result is given in either true or false,or 0 or 1, and is then checked by the compiler, if it is true ,the statements following this if statement will execute ,Otherwise it will not execute if statement block and execute the else block if present. An else block is a Block that executes in case if statement is not satisfied. Now Coming to the example.It will be more clear when you see the Example. int n=5; if(n>2) { n++; n = 2*n; } else{ n--; n=2*n; } Here, We have Declared a integer type variable n with value 5. Then there is an if statement with test expression = n>2 . Since, n=5 ,i.e., n>2 , Therefore, this condition is true and satisfied. Therefore , if statement block will execu...
- Get link
- X
- Other Apps
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...
- Get link
- X
- Other Apps
Hello Everyone.Sorry for a Long Delay. By the way,Now we are going to discuss about Flow of control(of a program). Flow of Control is a way in which a program is compiled and executed.It can be a bunch of statements Within braces ending with a semicolon or it can be selective or repetitive. Sequential Flow is as mentioned above a bunch of statements ending with semicolon within braces.For Example:- int main() { statement1; statement2; return 0; } Selective Flow includes if-else and switch statements which verifies a condition/text expression in order to execute the statements enclosed under it.The usage of if-else and switch statements is Shown in the Example.Example:- int main() { int a,b,c; cin>>a>>b; cout<<"\n1.Maximum\n2.Minimum\nEnter your Choice="; cin>>c; switch(c)//verify Condition { case 1:if(a>b)//text expression-Condition cout<<a; ...