C/C++编程学习 - 第4周 ④ 0与1

题目链接

题目描述

小蒜上了他的第一堂计算机概论,老师说计算机内部是由很多的小开关来组成:1 代表开、0 代表关。于是聪明的小蒜便了解了,原来我们平常使用电灯开关就是把 1 变成 0、0 变成 1 嘛!

输入格式
输入只有一行,含有一个为 0 或 1 的整数。

输出格式
输入为 0 则输出 1;
输入为 1 则输出 0。

Sample Input

1

Sample Output

0

思路

输入 0 ,输出 1 ; 输入 1 ,输出 0 。

C语言代码:

#include<stdio.h>
int main()
{
    
    
	int n;
	scanf("%d", &n);
	if(n == 0) printf("1");
	else printf("0");
	return 0;
}

C++代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int n;
	while(cin >> n)
		n == 0 ? cout << "1" << endl : cout << "0" << endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_44826711/article/details/112907489