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

本文介绍了四个C语言编程练习,包括利用指针输入数组并找到最大值及其下标,删除字符串中的空格,反向输出字符串以及处理二维数组的主次对角线元素之和。此外,还探讨了使用指针数组解决组合问题的方法。这些练习旨在提升对C语言中指针和数组操作的理解。
摘要由CSDN通过智能技术生成

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.

#
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值