search
HomeComputer TutorialsComputer KnowledgeWrite a program in C language, use a one-dimensional array to store the data of a two-dimensional array and write a function to complete

编写程序 c语言。用一维数组存储二维数组的数据看编写函数完成

Write a program in c language. Use a one-dimensional array to store the data of a two-dimensional array. See writing the function to complete

Code 1:

#include

int MAX,MIN;

int maxi,maxj,mini,minj;

void main()

{

void result(int x[][5],int m,int n);

int a[5][5],max,min,i,j;

for(i=0;i

for(j=0;j

scanf("%d",&a[i][j]);

MAX=MIN=a[0][0];

maxi=maxj=mini=minj=0;

result(a,5,5);

printf("MAX=%d,maxi=%d,maxj=%d\n",MAX,maxi,maxj);

printf("MIN=%d,mini=%d,minj=%d\n",MIN,mini,minj);

}

void result(int x[][5],int m,int n)

{

int i,j;

for(i=0;i

for(j=0;j

{

if(x[i][j]>MAX)

{

MAX=x[i][j];

maxi=i;

maxj=j;

}

if(x[i][j]

{

MIN=x[i][j];

mini=i;

minj=j;

}

}

}

But code 1 has a disadvantage, that is, if there are multiple maximum values, only the last one can be output. The code below is improved.

Code 2:

#include

int MAX,MIN;

int maxi,maxj,mini,minj;

void main()

{

void result(int x[][5],int m,int n);

int a[5][5],max,min,i,j;

for(i=0;i

for(j=0;j

scanf("%d",&a[i][j]);

MAX=MIN=a[0][0];

maxi=maxj=mini=minj=0;

result(a,5,5);

}

void result(int x[][5],int m,int n)

{

int i,j;

for(i=0;i

for(j=0;j

{

if(x[i][j]>MAX)

MAX=x[i][j];

if(x[i][j]

MIN=x[i][j];

}

for(i=0;i

for(j=0;j

{

if(x[i][j]==MAX)

{

MAX=x[i][j];

maxi=i;

maxj=j;

printf("MAX=%d,maxi=%d,maxj=%d\n",MAX,maxi,maxj);

}

if(x[i][j]==MIN)

{

MIN=x[i][j];

mini=i;

minj=j;

printf("MIN=%d,mini=%d,minj=%d\n",MIN,mini,minj);

}

}

}

C language two-dimensional array one-dimensional array

#include

#include

#include

int main()

{

int i,k,a[5][5],b[25],j=0;

double c=0;

srand(time(NULL));

printf("The generated random array is:\n");

for(i=0;i{

for(k=0;k{

a[i][k]=rand()� 10;

printf(" %d ",a[i][k]);

c =a[i][k];

}

printf("\n");

}

c=c/25;

//printf("%lf\n",c);

printf("\nThe new array is:\n");

for (i = 0; i {

for(k=0;kif (a[i][k] {

b[j] = a[i][k];

j ;

}

}

for(i=0;iprintf("%d",b[i]);

return 0;

}for (i = 0; i

The above is the detailed content of Write a program in C language, use a one-dimensional array to store the data of a two-dimensional array and write a function to complete. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:Excel办公网. If there is any infringement, please contact admin@php.cn delete
How to Remove the SecureBootEncodeUEFI.exe Trojan?How to Remove the SecureBootEncodeUEFI.exe Trojan?Apr 13, 2025 am 12:50 AM

Some Windows 11/10 users report that they see a cmd window open up right after a Bitdefender update and it is running SecureBootEncodeUEFI.exe. This post from php.cn introduces how to remove the SecureBootEncodeUEFI.exe Trojan.

Fix: Sysdll_win64_retail.dll Missing or Not Found Error - MiniToolFix: Sysdll_win64_retail.dll Missing or Not Found Error - MiniToolApr 13, 2025 am 12:48 AM

Sysdll_win64_retail.dll is a dynamic link library (DLL) file related to the FIFA 17 application. When that file gets missed or corrupted, a series of issues and errors will happen about that application. To resolve this issue, you can read this artic

Is Core Isolation Blocked by ew_usbccgpfilter.sys? Here Are Fixes!Is Core Isolation Blocked by ew_usbccgpfilter.sys? Here Are Fixes!Apr 13, 2025 am 12:47 AM

Many SurfaceBook users report that they meet the “core isolation blocked by ew_usbccgpfilter.sys” issue on Windows 11/10. This post from php.cn helps to fix the annoying issue. Keep on your reading.

How to Remove Options from the Ctrl   Alt   Del Screen?How to Remove Options from the Ctrl Alt Del Screen?Apr 13, 2025 am 12:46 AM

When you press Ctrl Alt Del on your computer, you will enter the Security Options window, where you might see Lock, Switch user, and Sign out options. Do you know that these options can be changed? This php.cn post will show you how to remove opt

How to Remove Virus:Win32/Grenam.VA!MSR? Here Is a Guide!How to Remove Virus:Win32/Grenam.VA!MSR? Here Is a Guide!Apr 13, 2025 am 12:45 AM

Some Windows 11/10 users report that their Windows Defender has spotted a virus named Virus:Win32/Grenam.VA!MSR. But they don’t know how to remove it. This post from php.cn teaches you how to remove Virus:Win32/Grenam.VA!MSR.

How to Save a Website as a Desktop App?How to Save a Website as a Desktop App?Apr 13, 2025 am 12:44 AM

When you need to visit a website frequently, it is quite troublesome to open a browser and search for it every time. Why don’t you try to save a website as an app? If you do this, you can open it as normal software. Here, php.cn offers you some usefu

A Full Guide to Fixing the Windows Update Error 0x00000000A Full Guide to Fixing the Windows Update Error 0x00000000Apr 13, 2025 am 12:43 AM

Some people encountered the error code 0x00000000 on Windows 11 when they installed the latest Windows update. What should you do to cope with this unexpected error? This article on the php.cn Website will give you some clues for troubleshooting.

How to Fix FileType Selected Not Supported by This AppHow to Fix FileType Selected Not Supported by This AppApr 13, 2025 am 12:41 AM

Are you suffering from the error message "FileType selected not supported by this app" when opening files in Teams or Excel? Now read this post from php.cn to get several useful solutions to this issue.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.