OpenJudge 09:Conversion between integer and Boolean

Description

If you assign the value of an integer variable to a boolean variable, and then assign the value of the boolean variable to an integer variable, what is the value you get?

Input

An integer in the integer range, that is, the initial value of the integer variable.

Output

An integer, the result obtained after going through the above process.

Input sample

3

Output sample

1

Answer

C++
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;
int main()
{
     int i;
     bool b;
     cin>>i;
     b=(bool)i;
     i=b;
     cout<<i<<endl;
     return 0;
}

Result

Used memory: 200kB
Run time: 9ms
Language:G++
Submit time:2019-04-14 09:35:00

http://noi.openjudge.cn/ch0102/01/

OpenJudge 09:Conversion between integer and Boolean

https://blog.tsinbei.com/en/archives/543/

Author
Hsukqi Lee
Posted on

2022-07-03

Edited on

2022-07-28

Licensed under

CC BY-NC-ND 4.0

# Programing  Cpp  OpenJudge  NOI  NOIP

Comments

Name
Mail
Site
None yet