当前位置:网站首页>c语言编程题
c语言编程题
2022-07-02 06:34:00 【懵懂的梦花火】

#include "stdafx.h"
#include <stdio.h>
#include <malloc.h>
int main(int argc, char* argv[])
{
int i, number, *p;
scanf("%d", &number); // 输入向量长度
p = (int*)malloc(sizeof(int)*number*2); // 申请长度为number个int的连续存储空间
printf("请输入长度为%d的两个向量:\n",number);
for (i = 0; i < number*2; i++)
{
scanf("%d", &p[i]); // 获取输入流中的数据(以int进行解析)
}
int result = 0;
// 计算向量内积
for (i = 0; i < number; i++)
{
result+= (p[i] * p[i+number]);
}
printf("result is %d\n", result);
return 0;
}

#include "stdafx.h"
#include <stdio.h>
#include <malloc.h>
struct RowMin
{
int value;
int row;
int col;
};
int main(int argc, char* argv[])
{
int i, number, *p;
scanf("%d", &number);
p = (int*)malloc(sizeof(int)*number*number); // 申请内存空间n*n长度
printf("请输入长度为%d*%d的数组:\n",number,number);
for (i = 0; i < number*number; i++)
{
scanf("%d", &p[i]);
}
// 找出每一行的最小值
RowMin *pRowMin = (RowMin*)malloc(sizeof(RowMin)*number); // 存储每一行的最小值
for (i = 0; i < number; i++)
{
pRowMin[i].value = p[number*i];
pRowMin[i].row = i;
pRowMin[i].col = 0;
for (int j = 1; j < number; j++)
{
if (p[number*i+j] < pRowMin[i].value)
{
pRowMin[i].value = p[number*i+j];
pRowMin[i].col = j;
}
}
}
// 找出每一行的最大值
int max = 0;
for (i = 1; i < number; i++)
{
if (pRowMin[max].value < pRowMin[i].value)
{
max = i;
}
}
printf("result is %d,%d,%d\n", pRowMin[max].value, pRowMin[max].row, pRowMin[max].col);
return 0;
}
边栏推荐
猜你喜欢

Solution to amq4036 error in remote connection to IBM MQ

概念到方法,绝了《统计学习方法》——第三章、k近邻法

Watermelon book -- Chapter 6 Support vector machine (SVM)

每天睡觉前30分钟阅读_day4_Files

hystrix 实现请求合并

概率还不会的快看过来《统计学习方法》——第四章、朴素贝叶斯法

How to use pyqt5 to make a sensitive word detection tool

Machine learning practice: is Mermaid a love movie or an action movie? KNN announces the answer

Typora安装包分享

微服务实战|原生态实现服务的发现与调用
随机推荐
Beats (filebeat, metricbeat), kibana, logstack tutorial of elastic stack
[go practical basis] how to customize and use a middleware in gin
Safety production early warning system software - Download safety production app software
Matplotlib swordsman line - layout guide and multi map implementation (Updated)
Pool de connexion redis personnalisé
"Redis source code series" learning and thinking about source code reading
[go practical basis] how to install and use gin
Idea view bytecode configuration
西瓜书--第六章.支持向量机(SVM)
Knife4j 2.X版本文件上传无选择文件控件问题解决
记录一下初次使用Xray的有趣过程
Matplotlib剑客行——容纳百川的艺术家教程
在SQL注入中,为什么union联合查询,id必须等于0
Oracle delete tablespace and user
VIM操作命令大全
Customize redis connection pool
盘点典型错误之TypeError: X() got multiple values for argument ‘Y‘
洞见云原生|微服务及微服务架构浅析
Chrome浏览器插件-Fatkun安装和介绍
Attributes of classfile