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

2023-05-16

1.编写程序,定义整型指针变量p,初始化整型一维数组a的首地址(数组a的长度为10),利用指针变量p实现从键盘输入10个整型数据到一维数组a中,并输出该数组中最大值和最大值元素的下标。
1.Write a C program that declares an integer type pointer variable initialized the initial address of array a (the length is 10). You’re your program use the pointer variable p to store the numbers to the one-dimensional array a form the keyboard inputting and output the maximum and it’s subscript of the array a.

#include<stdio.h>
int main()
{
    int i,max,sub=0,a[10];
    int *p=a;
    for(i=0;i<10;i++)
        scanf("%d",p+i);
    max=a[0];
    for(i=0;i<10;i++,p++)
    {
	    if(*p>max)
		{ 
		max=*p;
		sub=i+1;
		} 
    }
    printf("MAX=%d,subscript=%d",max,sub);
    return 0;
}

2.编写程序,实现删除字符串s中的所有空格,其中实现字符串空格删除功能要求定义一个形式参数为字符指针的函数。
2.Write a C program that defines a function with a character pointer as formal parameter to delete the blank space in the string s.

#include<stdio.h>
void offspace(char *p)
{
    int i,j;
    for(i=0,j=0;p[i];i++)
    {
        if(p[i]!=' ')
        {
            p[j]=p[i];
            j++;
        }
    }
    p[j]='\0';
}

int main()
{
    char s[101];
    gets(s);
    offspace(s);
    puts(s);
    return 0;
}

3.编写程序,定义字符指针变量p,实现输入一个字符串,按相反次序输出其中的所有字符。
3.Write a C program that initially accepts a string by defining the character pointer variable p. Have your program output every character in reverse order.

#include<stdio.h>
int main()
{
	char s[101],*p=s;
	int i=0,j;
	gets(s);
	for(;*p;){
		i++;
		p++;
	}
	p=s;
    for(j=i-1;j>=0;j--)
        putchar(*(p+j));
    return 0;
}
#include<stdio.h>
int main()
{
	char s[101],*p=s;
	gets(s);
	for(;*p;){
		p++;
	}
	p--;
    for(;p>=s;p--)
        putchar(*p);
    return 0;
}

4.指针与二维数组。下面程序的功能是求行列长度为5的二维数组方阵m的主对角线元素之和以及次对角线元素之和,请完善以下程序,并上机调试。
4.Pointer and Two-dimensional array. The function of the following C program that calculates the sums of the main diagonal line and the secondary diagonal line of the two-dimensional array (the lengths of the row and column are 5). Fill the vacant positions and debug the following program.
题目图片
在这里插入图片描述

#include<stdio.h>
main()
{
    int i,j;
    int sum1=0,sum2=0;
    int m[5][5];
    printf("input:\n");
    for(i=0;i<5;i++)
	    for(j=0;j<5;j++)
		    scanf("%d",*(m+i)+j);
    printf("\n");
    for(i=0;i<5;i++)
    { 
	sum1=sum1+*(*(m+i)+i);
    sum2=sum2+*(*(m+4-i)+i);
    }
printf("sum1=%d,sum2=%d\n",sum1,sum2);
}

5.指针数组示例。使用指针数组求解组合问题,已知1个不透明的布袋里装有红、蓝、黄同样大小的圆球各1个,现从中1次抓出2个,问可能抓出的球颜色组合有哪些,完善程序,并上机调试,将输出结果截图。
5.Pointer arrays. Write a C program that calculates the combinatorial problem using the pointer array. There are the same size balls with red, blue and yellow in a nontransparent bag. Every color includes only one ball. When take out two balls at a time, how many combinations of possible ball colors? Fill the vacant positions and debug the following program.
在这里插入图片描述

#include<stdio.h>
main()
{
char *color[3]={"red","blue","yellow"};
int count=0,i,j;
for(i=0;i<3;i++)
	for(j=0;j<3;j++)
	{
		if(i==j)
		    continue;
		count++;
		printf("%6d",count);
		printf("%10s%10s\n",color[i],color[j]);
	}
}

因时间仓促,后三题是在CSDN用户qq_52027107的指导下完成,特此表示感谢。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

  • 学生管理系统2.0 (可对学生数组扩容)

    学生管理系统2 0 可对学生数组扩容 1 用户可初始化数组长度 xff0c 不够用时可以扩充数组容量 尝试完成以下功能 实体类 学生类 id 姓名 xff0c 年龄 xff0c 性别 xff0c 成绩 需要使用数组保存学生信息 Studen
  • 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

随机推荐