Project 3: Application of if statement
Requirements:
(1) Please program to judge the positive and negative and odd and even of an input integer.
(2) If it is a positive number, please output z; if it is a negative number, please output f.
(3) If it is an even number, please output o; if it is an odd number, please output j.
#include <iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter a Number: ";
cin>>num;
if (num > 0)
{
cout<<"z"<<endl;
if (num % 2 == 0)
{
cout<<"o"<<endl;
}
else
{
cout<<"j"<<endl;
}
}
else
{
cout<<"f"<<endl;
if (num % 2 == 0)
{
cout<<"o"<<endl;
}
else
{
cout<<"j"<<endl;
}
}
return 0;
}
Comments
Leave a comment