Docsity

C++ Program to Determine Even or Odd Numbers - Prof. Omer Farook, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
// This program asks you to input a number.
// It then determines if it is an even number
// or an odd number.
#include <iostream>
using namespace std;
//declaration of functions
void data_input(int *);
void calculation(int *);
void main(void)
{
int number;
//function calls
data_input(&number);
calculation(&number);
char c1;
cin >> c1;
}
//body of function data_input
//Data input for test scores.
void data_input(int *p1)
{
cout << "Enter a number and I will tell you if it\n";
cout << "is odd or even. ";
cin >>*p1;
}
void calculation(int *p2)
{
if (*p2 % 2 == 0)
cout << *p2 << " is even.\n";
else
cout << *p2 << " is odd. \n";
}
/* Typical output if number is even:
pf2

Partial preview of the text

Download C++ Program to Determine Even or Odd Numbers - Prof. Omer Farook and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

// This program asks you to input a number. // It then determines if it is an even number // or an odd number. #include using namespace std; //declaration of functions void data_input(int *); void calculation(int *); void main(void) { int number; //function calls data_input(&number); calculation(&number); char c1; cin >> c1; } //body of function data_input //Data input for test scores. void data_input(int p1) { cout << "Enter a number and I will tell you if it\n"; cout << "is odd or even. "; cin >>p1; } void calculation(int p2) { if (p2 % 2 == 0) cout << *p2 << " is even.\n"; else cout << p2 << " is odd. \n"; } / Typical output if number is even:

Enter a number and I will tell you if it is odd or even. 100 100 is even. Typical output if number is odd: Enter a number and I will tell you if it is odd or even. 75 75 is odd. */