Posts

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 ! 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...
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...

bandicam 2017 01 23 20 38 45 832

Image
This is just for your Knowledge.Those who want to start with java can find this Helpful.