当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

破茧|一文说透什么是真正的云原生

Troubleshooting and handling of an online problem caused by redis zadd
![[go practical basis] how to verify request parameters in gin](/img/de/50db131d6993e5d955e3416c667c4c.png)
[go practical basis] how to verify request parameters in gin

Supplier selection and prequalification of Oracle project management system

From concept to method, the statistical learning method -- Chapter 3, k-nearest neighbor method

"Redis source code series" learning and thinking about source code reading

Machine learning practice: is Mermaid a love movie or an action movie? KNN announces the answer
![[staff] the lines and spaces of the staff (the nth line and the nth space in the staff | the plus N line and the plus N space on the staff | the plus N line and the plus N space below the staff | the](/img/dc/c0ea188ef353ded86759dbe9b29df3.jpg)
[staff] the lines and spaces of the staff (the nth line and the nth space in the staff | the plus N line and the plus N space on the staff | the plus N line and the plus N space below the staff | the

Matplotlib剑客行——没有工具用代码也能画图的造型师

自定義Redis連接池
随机推荐
Customize redis connection pool
DTM distributed transaction manager PHP collaboration client V0.1 beta release!!!
Mysql 多列IN操作
View the port of the application published by was
[go practical basis] how to set the route in gin
Elastic Stack之Beats(Filebeat、Metricbeat)、Kibana、Logstash教程
Operation and application of stack and queue
Taking the upgrade of ByteDance internal data catalog architecture as an example, talk about the performance optimization of business system
《统计学习方法》——第五章、决策树模型与学习(上)
Beats (filebeat, metricbeat), kibana, logstack tutorial of elastic stack
JVM instruction mnemonic
Machine learning practice: is Mermaid a love movie or an action movie? KNN announces the answer
Redis 序列化 GenericJackson2JsonRedisSerializer和Jackson2JsonRedisSerializer的区别
Watermelon book -- Chapter 6 Support vector machine (SVM)
CKEditor 4.10.1 上传图片提示“不正确的服务器响应” 问题解决
[staff] time sign and note duration (full note | half note | quarter note | eighth note | sixteenth note | thirty second note)
双非本科生进大厂,而我还在底层默默地爬树(上)
Required request body is missing:(跨域问题)
Alibaba /热门json解析开源项目 fastjson2
Matplotlib剑客行——没有工具用代码也能画图的造型师