首页 > 编程语言 > 详细

实验1 C语言开发环境使用和数据类型、运算符、表达式

时间:2019-10-17 22:39:36      阅读:81      评论:0      收藏:0      [点我收藏+]

Part2 : 按要求写出符合要求的表达式,补全程序。 给出补全后完整的程序源码及运行结果截图。

          Test 1:判断其是奇数还是偶数

#include <stdio.h>
#include<stdlib.h>

int main()
{
    int x;

    printf("please input:\n");
    scanf("%d", &x);

    if (x % 2 == 0)
        printf("even");
    else
        printf("odd");

    system("pause");
    return 0;
}

技术分享图片

 

  Test 2 判断是否是工作日

#include <stdio.h>
#include<stdlib.h>

int main()
{
    int days;

    printf("please input:\n");
    scanf("%d", &days);

    if (days >= 1 && days <= 5)
        printf("workdays,fighting\n");
    else if (days == 6 || days == 7)
        printf("weekend,relax~\n");
    else
        printf("Oops,not in 1~7\n");

    system("pause");
    return 0;
}

技术分享图片

 

 

Test 3 小写字母转换为大写字母

#include <stdio.h>
#include<stdlib.h>

int main()
{
    char ch;

    printf("please input:\n");
    scanf_s("%c", &ch);

    if (ch >= a&&ch <= z)
        ch -= 32;

    printf("%c", ch);

    system("pause");
    return 0;
}

技术分享图片

 

Part 3 编程练习

编写程序,实现把一个十进制两位数整数转换成二进制。十进制整数由键盘输入,转换后的二进制数据输出到显示器上。 

#include <stdio.h>
#include<stdlib.h>

int main()
{
    int n;
    int a[32];
    scanf_s("%d", &n);

    int i = 0;
    while (n > 0)
    {
        a[i++] = n & 1;
        n = n >> 1;
    }
    while (i--)
    {
        printf("%d", a[i]);
    }
    printf("\n");

    system("pause");
    return 0;
}

技术分享图片

实验1 C语言开发环境使用和数据类型、运算符、表达式

原文:https://www.cnblogs.com/faspk/p/11695418.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!