当前位置:网站首页>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;
}
边栏推荐
- [go practical basis] how to bind and use URL parameters in gin
- Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
- 在SQL注入中,为什么union联合查询,id必须等于0
- Jd.com interviewer asked: what is the difference between using on or where in the left join association table and conditions
- Long summary (code with comments) number structure (C language) -- Chapter 4, string (Part 1)
- Chrome浏览器标签管理插件–OneTab
- Thinkphp5 how to determine whether a table exists
- Matplotlib swordsman line - first acquaintance with Matplotlib
- Micro service practice | introduction and practice of zuul, a micro service gateway
- Microservice practice | fuse hytrix initial experience
猜你喜欢

Solution to amq4036 error in remote connection to IBM MQ

JDBC回顾

Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer

上班第一天的报错(AWVS卸载不彻底)

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

Microservice practice | Eureka registration center and cluster construction

Say goodbye to 996. What are the necessary plug-ins in idea?

Matplotlib剑客行——布局指南与多图实现(更新)

机器学习实战:《美人鱼》属于爱情片还是动作片?KNN揭晓答案

洞见云原生|微服务及微服务架构浅析
随机推荐
How to choose between efficiency and correctness of these three implementation methods of distributed locks?
每天睡觉前30分钟阅读_day4_Files
C语言之数据插入
Ora-12514 problem solving method
Knife4j 2. Solution to the problem of file control without selection when uploading x version files
AMQ 4043 solution for errors when using IBM MQ remote connection
Programmers with ten years of development experience tell you, what core competitiveness do you lack?
微服务实战|手把手教你开发负载均衡组件
Chrome user script manager tempermonkey monkey
What are the differences between TP5 and laravel
Knowledge points are very detailed (code is annotated) number structure (C language) -- Chapter 3, stack and queue
How to use PHP spoole to implement millisecond scheduled tasks
Complete solution of servlet: inheritance relationship, life cycle, container, request forwarding and redirection, etc
一篇详解带你再次重现《统计学习方法》——第二章、感知机模型
记录下对游戏主机配置的个人理解与心得
Solutions to Chinese garbled code in CMD window
数构(C语言--代码有注释)——第二章、线性表(更新版)
[go practical basis] how to install and use gin
Talk about the secret of high performance of message queue -- zero copy technology
互联网API接口幂等设计