Computer Science, asked by chakethagilliam9370, 4 days ago

1.Accept a number and print if it is an even or an odd number (using if else).

Answers

Answered by Warloc369
0

Explanation:

a=int(input("Enter your number"))

if a%2==0:

print(a "is an even integer")

elif a%2==1:

print(a " is an odd integer")

else:

print("invalid input")

Answered by Anonymous
1

The following program has been written using Python.

num = int(input("Enter an integer: "))

if num%2 == 0:

   print("The given integer is an even number.")

else:

   print("The given integer is an odd number.")

The following program has been written using Java.

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    System.out.print("Enter an integer: ");

    int num = sc.nextInt();

    if (num%2 == 0) {

        System.out.println("The given integer is an even number.");

    }

    else {

        System.out.println("The given integer is an odd number.");

    }

}

}

The following program has been written using C.

#include <stdio.h>

int main()

{

   int num;

   printf("Enter an integer: ");

   scanf("%d", &num);

   if(num%2 == 0)

       printf("The given integer is an even number.");

   else

       printf("The given integer is an odd number.");

   return 0;

}

The following program has been written using C++.

#include <iostream>

using namespace std;

int main() {

 int num;

 cout << "Enter an integer: ";

 cin >> num;

 if (num%2 == 0)

   cout << "The given integer is an even number.";

 else

   cout << "The given integer is an even number.";  

 return 0;

}

The following program has been written using QBasic.

CLS

INPUT "Enter a Number: ", num

IF num MOD 2 = 0 THEN

  PRINT "The given integer is an even number."

ELSE

  PRINT "The given integer is an odd number."

END IF    

END

\rule{100mm}{2pt}

Logic:

  1. Take user input and store it in integer type value. Read: num.
  2. Check: if (num%2 == 0) is true, display num is an even number.
  3. If (num%2 == 0) is false, display num is an even number.

\rule{100mm}{2pt}

I have added a .txt file from where you can get all the co‎des.

Attachments:
Similar questions