openjudge noi 题库答案 c++

 1.2编程基础之变量定义、赋值及转换(10题)

01:整型数据类型存储空间大小

#include<stdio.h>
int main()
{
    printf("%d %d\n",sizeof(int),sizeof(short));
    return 0;
}

02:浮点型数据类型存储空间大小

#include<stdio.h>
int main()
{
    printf("%d %d\n",sizeof(float),sizeof(double));
    return 0;
}

03:其他基本数据类型存储空间大小

#include<stdio.h>
#include<stdbool.h>
int main()
{
    printf("%d %d\n",sizeof(bool),sizeof(char));
    return 0;
}

04:填空:类型转换1

#include<stdio.h>
int main()
{
    printf("D C");
    return 0;
}

05:填空:类型转换2

#include <iostream>
using namespace std;
int main()
{
	cout<<"F E"<<endl;
	return 0;
}

06:浮点数向零舍入

#include<stdio.h>
int main()
{
    float a;
    int b;
    scanf("%f %d\n",&a,&b);
    b=(int)a;
    printf("%d\n",b);
    return 0;
}

07:打印ASCII码

#include <iostream>
using namespace std;
int main() {
    char x;
    cin >> x;
    cout << (int)x << endl;
    return 0;
}

08:打印字符

#include <iostream>  
using namespace std;   
int main(){  
    int n;      
    cin >> n;      
    cout << (char)n;     
    return 0;  
}

09:整型与布尔型的转换

#include<stdio.h>
#include<stdbool.h>
int main()
{
    int a;
    bool b;
    scanf("%d",&a);
    b=a;
    printf("%d\n",b);
    return 0;
}

10:Hello, World!的大小

#include<stdio.h>
int main(){
	int a;
	a=sizeof("Hello, World!");
	printf("%d",a);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值