سلسلة++ Python VS C : المكشلة 3

    1. ++ FRIST BY C.
      // COPY Right:- “All rights reserved to Dr. Mohamed Abu-Hadhoud and programming advices channel”
      #include
      #include
      using namespace std;
      /Problem #3
      Write a program to ask the user to enter a number, then
      Print “ODD” if its odd, Or “Even” if its even.
      /
      //problem analysis
      //The program should ask the user to enter a number, then print “ODD” if its odd, Or “Even” if its even.
      //steps to solve the problem
      //1. Start
      //2. read the input from the user
      //3. check if the number is odd or even
      //4. print the result
      //5. End
      //tools to solve the problem
      //1.enum number_type {ODD =1 , EVEN =2};
      //2.function to read the input from the user
      //3.function to check if the number is odd or even
      //4.procedure to print the result
      //5.function to exit the program
      //6.function to clean screen

//slove the problem :
//function to read the input from the user

enum ennumber_type {ODD=1 , EVEN=2}
;
//function to read the input from the user
int read_number()
{
int number;
cout<<“Enter your number : \n” ;
cin >> number;
return number;
}
;
//function to check if the number is odd or even
ennumber_type check_number(int number)
{
if (number %2 ==0)
{
return ennumber_type ::EVEN;
}
else
{
return ennumber_type:: ODD;
}
}
;
//procedure to print the result
void print_number(ennumber_type numtype)
{
if (numtype ==ennumber_type::EVEN )
{
cout << “\nThe number is " << “\nEVEN” << endl;
}
else
{
cout << “\nThe number is " <<”\n ODD” << endl;
}
}
;
//function to exit the program
int exit_program()
{
cout << “Exit the program” << endl;
cin.ignore();
cin.get();
return 0;
}
;
//function to clean screen
int clean_screen()
{
system(“cls”);
return 0;
}
//main function
int main ()
{

  print_number(check_number(read_number()));
  exit_program();
  clean_screen();
  return 0;

}
2nd : by python :-1:
#Copyright© 2022 PROGRAMMING ADVICE Mohammed Abu-Hadhoud
#Problem #3
#Write a program to ask the user to enter a number, then
#Print “ODD” if its odd, Or “Even” if its even.

#steeps to solve the problem:
#1. Ask the user to enter a number
#2. Check if the number is odd or even
#3. Print the result

#sloution without using function :
number = int(input("please enter a number: "))
if number % 2 == 0:
print(“Even”)
else:
print(“ODD”)
#sloution by using function :
def check_number():
number = int(input("please enter a number: "))
if number % 2 == 0:
print(“Even”)
else:
print(“ODD”)
check_number()


إعجاب واحد (1)