当前位置:网站首页>C language instance_ four
C language instance_ four
2022-07-07 01:24:00 【Vicky__ three thousand and twenty-one】
1. Scheduling problem
Arrange the ten numbers from large to small .
#include<stdio.h>
int main(void)
{
int i,j,t,a[11];
for(i=1;i<11;i++){
scanf("%d",&a[i]);
}
for(i=1;i<=9;i++){
for(j=i+1;j<=10;j++){
if(a[i]<a[j]){
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
for(i=1;i<=10;i++){
printf("%d ", a[i]);
}
printf("\n");
return 0;
}
2. Look up integers
Give a containing n A sequence of integers , Ask for integers a The first occurrence in a sequence is the number of .
#include<stdio.h>
int main(void)
{
int m,n,i,j;
scanf("%d",&m);
int a[m];
for(j=0;j<m;j++){
scanf("%d ",&a[j]);
}
scanf("%d",&n);
for(i=0;i<=m;i++){
if(a[i]==n){
printf("%d",i+1);
return 0;
}
}
printf("-1");
return 0;
}
3. Calculate the maximum value of the element in the array and its row and column subscript value
Press the function prototype below to program and input a from the keyboard m That's ok n Two dimensional array of columns , Then calculate the maximum value of the elements in the array and the subscript value of the row and column . among m and n The value of is entered by the user keyboard . It is known that m and n No more than 10.
#include<stdio.h>
int main(void)
{
int a[10][10];
int max,row,col,i,j,m,n;
row = col - 1;
printf("Input m, n:");
scanf("%d,%d",&m,&n);
printf("Input %d*%d array:\n",m,n);
for(i=0;i<m;i++){
for(j=0;j<n;j++){
scanf("%d",&a[i][j]);
}
}
max = a[0][0];
for(i=0;i<m;i++){
for(j=0;j<n;j++){
if(a[i][j]>max){
max=a[i][j];
row=i+1;
col=j+1;
}
}
}
if(m==1){
max=1;
row=1;
col=1;
}
printf("max=%d, row=%d, col=%d",max,row,col);
return 0;
}
4. Delete maximum
Input 10 Different integers are stored in the array , Find the largest element and delete it , Output the deleted array
#include<stdio.h>
#define N 10
int a[N];
int main(void){
int i;
for(i = 0;i < N;i++){
scanf("%d",&a[i]);
}
int maxa = a[0], k = 0;
for(i = 1;i < N;i++){
if(a[i]>maxa) maxa = a[i], k=i;
}
for(i = 0;i < N;i++){
if(i != k){
printf("%d ",a[i]);
}
}
printf("\n");
return 0;
}
5. Yang hui triangle
Remember the Yanghui triangle I learned in middle school ? The specific definition will not be described here , You can refer to the figure below :
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
#include<stdio.h>
int a[10][10];
int main()
{
int num = 1;
for(int i = 0; i < 10; i ++) a[i][0] = 1;
for(int i = 1; i < 10; i ++)
{
for(int j = 1; j < 10; j ++)
{
if(j == num)
{
num ++;
a[i][j] = 1;
break;
}
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
}
}
num = 1;
for(int i = 0; i < 10; i ++)
{
for(int j = 0; j < 10; j ++)
{
if(j == num)
{
num ++;
break;
}
if(j == num - 1) printf("%d", a[i][j]);
else printf("%d ", a[i][j]);
}
printf("\n");
}
return 0;
}
边栏推荐
- Case development of landlord fighting game
- 负载均衡性能参数如何测评?
- ClickHouse字段分组聚合、按照任意时间段粒度查询SQL
- Oracle:CDB限制PDB资源实战
- NEON优化:矩阵转置的指令优化案例
- Grc: personal information protection law, personal privacy, corporate risk compliance governance
- Docker method to install MySQL
- Taro applet enables wxml code compression
- 1123. 最深叶节点的最近公共祖先
- Table table setting fillet
猜你喜欢

Wood extraction in Halcon

Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which

【C语言进阶篇】指针的8道笔试题

子网划分、构造超网 典型题

Come on, don't spread it out. Fashion cloud secretly takes you to collect "cloud" wool, and then secretly builds a personal website to be the king of scrolls, hehe

Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform

2022 Google CTF SEGFAULT LABYRINTH wp

Lldp compatible CDP function configuration
![[case sharing] basic function configuration of network loop detection](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[case sharing] basic function configuration of network loop detection

Body mass index program, entry to write dead applet project
随机推荐
【js】获取当前时间的前后n天或前后n个月(时分秒年月日都可)
Atomic in golang and CAS operations
SuperSocket 1.6 创建一个简易的报文长度在头部的Socket服务器
Eventbus source code analysis
1123. The nearest common ancestor of the deepest leaf node
Spark TPCDS Data Gen
[Niuke] [noip2015] jumping stone
Informatics Orsay Ibn YBT 1172: find the factorial of n within 10000 | 1.6 14: find the factorial of n within 10000
MySQL script batch queries all tables containing specified field types in the database
NEON优化:性能优化常见问题QA
云呐-工单管理制度及流程,工单管理规范
What does security capability mean? What are the protection capabilities of different levels of ISO?
LeetCode:1175. 质数排列
JTAG principle of arm bare board debugging
Openjudge noi 1.7 08: character substitution
NEON优化:关于交叉存取与反向交叉存取
Can the system hibernation file be deleted? How to delete the system hibernation file
Implementation principle of waitgroup in golang
736. Lisp 语法解析 : DFS 模拟题
黑马笔记---异常处理