Without using any conditional statement check whether a number is even or not? - My articles - Publisher - Information Technology
Saturday, 2016-12-03, 10:45 PM
ebooks Programming Computer Science
Welcome Guest | RSS
Site menu
Section categories
My articles [23]
Main » Articles » My articles

Without using any conditional statement check whether a number is even or not?
#include <iostream>
#include <string>
#include <bitset>

int main() {

std::string const type[] = {"even", "odd"};
int n;
std::cout << "Enter an integer." << std::endl;
std::cin >> n;
std::cout << type[(std::bitset<1>(std::abs(n))[0])] << std::endl;
}




Category: My articles | Added by: Sumrat (2012-11-04)
Views: 1459 | Comments: 4 | Rating: 0.0/0
Total comments: 0
Name *:
Email *:
Code *:
Our poll
Rate my site
Total of answers: 152
Statistics

Total online: 1
Guests: 1
Users: 0
Login form