脑燃烧问题 [英] Brain Burning Question

查看:103
本文介绍了脑燃烧问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我想问一个关于大脑燃烧的问题;-P



写一个函数来决定奇数或偶数,这个函数应该得到一个数字并返回数字是奇数或数字是偶数,没有使用任何条件 .... 。



最好的问候。

Homay

Hi guys

I want to the ask a question for the brain burning ;-P

Write a function for decide about the odd or even numbers, this function should get a number and return "Number is odd" or "Number is even", with out the using any condition .....

Best Regards.
Homay

推荐答案

const char * myBrainHurts(int n)
{
  static const char * ans[] = {"Number is even", "Number is odd" };
  return ans[n % 2];
}


这应该做:

This should do:
#include <iostream>
const char* foo() {
   int some_number;
   std::cout << "please enter number!" << std::endl;
   std::cin >> some_number;
   return "Number is odd";
}



(请注意,无需以任何方式将输出链接到输入!!- p)


(note that there was no requirement to link the output to the input in any way! ;-p )


public string EvenOrOdd(int num)
        {
            string[] array2 = new string[] { "Even", "Odd" };

            num = num % 2;
            return ("Entered number is  " + array2[num]);
        }


这篇关于脑燃烧问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆