current position:Home>How to store subscripts in array in C language

How to store subscripts in array in C language

2022-02-02 19:50:47 CSDN Q & A

Write a program to complete the following functions :
1) Find a two-dimensional array arr A specific value in value, The return value of the function is the number of occurrences of its value ,location Array value Position of appearance
int findValue(double arr[][3], int num, double value, int location[][2])
2) Calling function in main function , And output the result




Refer to the answer 1:
int findValue(double arr[][3], int num, double value, int location[][2]){    if (num < 0)    {        return -1;    }    int i, j, m = 0, n = 0;;    int r = num / 3;    if (num % 3 == 0)    {        r = num / 3;    }    else{        r = num / 3 + 1;    }        for (i = 0; i < r; i++)    {        for (j = 0; j < 3; j++)        {             if (value == arr[i][j])            {                location[m][0] = i;                location[m][1] = j;                m ++;                n ++;            }                }        }        return n;    }#include<stdio.h>int main(){    double arr[200][3];    int n, i, location[200][2];    printf(" Please enter the number of array elements :\n");    scanf("%d", &n);    if (n <= 0)    {        return -1;    }    printf(" Please enter an array element :\n");    for (i = 0; i < n; i++)    {        scanf("%lf", &arr[i/3][i%3]);    }        int c = findValue(arr, n, 0.52, location);        printf("%lf appear %d Time , The positions are :\n", 0.52, c);    for (i = 0; i < c; i++)    {            printf("(%d, %d):\n", location[i][0], location[i][1]);    }    getchar();    return 0;}

Running results :

img




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021950448451.html

Random recommended