东北大学秦皇岛分校通信工程中外合作2020级C语言实验6

2023-05-16

1.定义结构体类型,包括候选人名和选票两个成员,编程实现对候选人得票的统计。
1.Write a C program that implements the statistics of the candidate votes using the definition of structures including two members ( candidate name and vote count)

#include<stdio.h>
#include<string.h> 
int main()
{
	struct person
	{
		char name[7];
		int count;
	};
	struct person leader[2]={"Biden",0,"Trump",0};
	
	int i,j;
	char leadername[7];
	for(i=0;i<5;i++)
	{
		scanf("%s",leadername);
		for(j=0;j<2;j++)
		    if(strcmp(leadername,leader[j].name)==0)
		        leader[j].count++;
	}
	for(i=0;i<2;i++)
	    printf("%7s: %d\n",leader[i].name,leader[i].count);
	return 0;
}

2.定义结构体类型变量(包括年、月、日),编写程序实现输入一个日期显示它是该年的第几天。
2.Write a C program that Enter a certain day a year to determine the day of the year the first few days. Define a structure variable including year, month and day.

#include<stdio.h>
int main()
{
	int order=0,a,i;
    struct time
	{
		int year,month,day;
	}date;
	scanf("%d.%d.%d",&date.year,&date.month,&date.day);
	                                       /*数据输入*/ 
	if(date.year%400==0)
        a=1;
    else if(date.year%4==0&&date.year%100!=0)
        a=1;
    else
        a=0;                                /*判断闰年*/
        
    for(i=1;i<date.month;i++)
	{
	    if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
	        order+=31; 
	    else if(i==2&&a==0)
	        order+=28;
        else if(i==2&&a!=0)
	        order+=29;
    	else
    	    order+=30;
	}	    
	order+=date.day;
	printf("%d",order);
    return 0;
}

3.编写程序,使用结构体数组存储2个学生的学号、姓名、2门课成绩和平均成绩,要求定义输入函数实现学生的学号、姓名、2门课成绩的键盘输入以及平均成绩的计算,定义输出函数实现以上信息的输出。
3.Write a C program that stores the number, name, two scores and average score of two students using structure array. Input function is required to realize input of student number, name, scores by keyboard and the calculation of average score. Output function is defined to realize the output of the above information.

#include<stdio.h>
#include<string.h>
#define N 2
int main()
{
	int i;
    struct student
	{
		char name[10];
		int num,g1,g2;
		float gave;
	}stu[N];
	for(i=0;i<N;i++)
	{
		scanf("%d\n",&stu[i].num);
		gets(stu[i].name);
		if(i!=N-1)
		    scanf("\n%d\n%d\n",&stu[i].g1,&stu[i].g2);
		else
		    scanf("\n%d\n%d",&stu[i].g1,&stu[i].g2);
	}
	printf("\n");
	for(i=0;i<N;i++)
	{
		stu[i].gave=0.5*(stu[i].g1+stu[i].g2);
		printf("%d\n",stu[i].num);
		puts(stu[i].name);
		printf("%d\n%d\n%f\n",stu[i].g1,stu[i].g2,stu[i].gave);
	}
    return 0;
}

4.定义共用体,实现一个整型数据按字节输出(以8进制数和字符两种形式输出)。
4.Write a C program that outputs the results of an integer convert to Bytes by defining Union.

#include<stdio.h>
#include<string.h>
int main()
{
	int i;
    union
	{
		char ch[4];
		int numino;
	}num;
	
	scanf("%d",&num.numino);
	printf("八进制:\n%o\n字符:\n",num.numino);
	for(i=0;i<4;i++)
	{
		printf("\t%d\n",num.ch[i]);
	}
    return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

东北大学秦皇岛分校通信工程中外合作2020级C语言实验6 的相关文章

  • LinkedList和Set

    LinkedList和Set 1 LinkedList 1 1 LinkedList概述 底层存储数据是一个双向链表结构 自行车链子 就是一个生活中链表结构 xff0c 环环相扣 xff0c 替换 xff0c 拆除非常方便 1 2 Link
  • shiro与springboot整合

    Shiro 与 SpringBoot 的整合 1 创建SpringBoot工程 xff0c 导入依赖 span class token generics function span class token punctuation lt sp
  • Vue

    Author Thor Version 9 0 1 文章目录 一 Vue简介1 1 简介1 2 MVVM 模式的实现者 双向数据绑定模式1 3 其它 MVVM 实现者1 4 为什么要使用 Vue js1 5 Vue js 的两大核心要素1
  • android AudioRecord 音频录制 噪音消除

    android AudioRecord 音频录制 噪音消除 因为公司APP做适配 xff0c 一些低端机的噪音比较严重 xff0c 所以再一些低端机上做了简单除噪音功能 xff0c 1 xff0c 由于APP使用场景的限制 xff0c 所以
  • springboot 常用注解

    springboot 常用注解 在spring boot中 xff0c 摒弃了spring以往项目中大量繁琐的配置 xff0c 通过自身默认配置 xff0c 极大的降低了项目搭建的复杂度 在spring boot中 xff0c 大量注解的使
  • X86架构基本汇编指令详解

    文章目录 汇编指令伪指令1 MODEL2 STACK3 ENDP4 END 汇编指令1 MOV xff1a 将源操作数复制到目的操作数2 MOVZX 和 MOVSX3 XCHG 交换两个操作数内容4 INC 和 DEC5 ADD 和 SUB
  • 详解 C++ 对象模型

    文章目录 何为 C 43 43 对象模型 xff1f 基本 C 43 43 对象模型C 43 43 对象模型中加入单继承1 无重写的单继承2 有重写的单继承 C 43 43 对象模型中加入多继承C 43 43 对象模型中加入虚继承1 简单虚
  • Ubuntu 扩大/home磁盘分区

    在删除或重命名home目录之前 xff0c 千万确保你可以使用root账户 xff01 xff01 xff01 sudo 无用 xff01 xff01 xff01 根目录一共212G xff0c 已经使用了80 了 xff0c 其中130G
  • 正则表达式学习的个人小结

    正则表达式是对字符串的一种操作 xff0c 运用到JS中可以帮助我们去寻找符合要求的字符串 表单验证 http xff1a regexper com xff08 这个网站可以把正则表达式输入进去然后用图形显示出来 xff0c 因为是国外的网
  • ROS学习 一、Debian10安装ROS Noetic,解决rosdep update失败问题(更新一个可修改位置)

    目录 前言ROS安装1 添加ROS的apt源和key xff08 中科大源 xff09 2 apt安装ros noetic核心组件3 配置ROS的bash环境4 安装其他常用ROS依赖项5 解决python3 rosdep安装中出现的ros
  • windows动态链接库的使用,隐式调用(静态链接)和显示调用(动态链接)

    一 xff0c 动态链接库项目创建 dll工程内部架构 用VS2019创建动态链接库dll工程 初始会有如下几个文件 xff1a pch h和pch cpp与动态链接库功能无关 是用来保存多个文件时共同引用的头文件 xff0c 函数 xff
  • 在wsl2中安装CUDA

    1 先根据我之前的教程把wsl1升级到wsl2 wsl1升级到wsl2 夕阳之后的黑夜的博客 CSDN博客 2 打开Ubuntu xff0c 输入 uname r 确定内核 xff0c 安装CUDA需要内核 4 19 121 或更高 3 在
  • import torch 报错没有找到torch_python.dll

    conda install c anaconda intel openmp 运行上述代码就成功了
  • 在wsl2(Ubuntu20.04)中安装cudnn

    可以看cudnn的官方安装文档 xff1a 安装指南 NVIDIA 深度学习 cuDNN 文档 1 根据之前安装的cuda版本来下载安装对应的cudnn版本 cuDNN Archive NVIDIA Developer 2 比如我的cuda
  • 解决android opengl glReadPixels 慢的问题 三

    解决android opengl glReadPixels 慢的问题 三 使用2个pbo效率提上去了 xff0c 但是我手机分辨率是720p 或者1080p xff0c 我们手机相机使用一般是480x640 xff0c 这样通过gpu渲染到
  • 常用的损失函数

    pytorch的源码 xff1a torch nn PyTorch 1 11 0 documentation jittor的源码 xff1a jittor nn Jittor 1 3 2 6 文档 tsinghua edu cn paddl
  • Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.

    在环境变量中Path 那一项中添加两个路径 xff1a 在环境变量中新建一个LIB 变量 xff0c 并添加三个路径 xff08 记得加分号 xff09 xff1a 在环境变量中新建一个INCLUDE 变量 xff0c 并添加两个路径 xf
  • 尝试DCGAN+Self Attention

    先看一下DCGAN的G模型 xff1a 再看一下Self Attention的网络结构 xff1a 话不多说 xff0c 上代码 xff1a G D的model文件如下 xff1a import torch import torch nn
  • 2022基于GAN的去雾去雨论文

    目录 去雨CVPR2022 xff1a 使用双重对比学习的不成对深度图像去雨 去雨CVPR2021 xff1a 闭环 xff1a 通过解开图像转换生成和去除联合雨 去雨CVPR2021 xff1a 从雨水产生到雨水清除 去雾CVPR2020
  • Single image dehazing for a variety of hazescenarios using back projected pyramid network

    论文名 xff1a Single image dehazing for a variety of haze scenarios using back projected pyramid network 基于反投影金字塔网络的多雾场景单幅图像

随机推荐