if else in C++ by R4R Team

Basically, if else work as decision making statement in all programming language.

Syntax-
if(condition){
body
}
else{
body
}

Now we can check number is positive or not using if else
Program:

#include < iostream>
using namespace std;
class myclass
{
public:
// check number is positive or negative
int check(int a)
{
if(a>0)
cout<<"Number is positive";
else
cout<<"Number is negative";
}
};
int main()
{
int n;
cout<<"Enter any number";
cin>>n;
myclass obj;
obj.check(n);
return 0;
}


output-

Enter any number
-19
Number is negative

Enter any number
34
Number is positive

-In this program, we take an input of one number through the user then pass in check function inside class that check whether number is positive or not.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!