Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can you please solve and run the program Problem 2: in the following the C funct

ID: 3683004 • Letter: C

Question


can you please solve and run the program

Problem 2: in the following the C function named ee takes as its first argument a two dimensional charanter array named arr with NR rows and NC columns where NR and NC are symbolic constants The second argument to the function is a two dimensional integer array named locations with 2 columns and NCC rows where NCC is a symbolic constant equal to the number of elements in the array arr. The third argument to the function is a single character variable named ch. The function stores in the integer array named locations the locations (as row and column index values) of all the occurrences of the character ch in the array arr, example below the fuction sets row o of locations to the values o and i in coliaans o and l respectively. The function returns void, but uses its last arguiment to return the number of times the to searched for was found. The character array data is read frotn the file data dat The character search for is read from the kovboard. is problem follows

Explanation / Answer

#include <stdio.h>

#define NR 100
#define NC 100
#define NCC NR*NC

void cc(char arr[NR][NC], int locations[NCC][2], char ch, int* count){
   int i,j,k=0;

   for(i=0;i<NR;++i){
       for(j=0;j<NC;++j){
           locations[k][0]=i;
           locations[k][1]=j;
           k++;

           if(ch==arr[i][j])
               (*count)++;
       }
   }
}

int main(){
   char arr[NR][NC]={{'a','b','c'},{'c','a','d'},{'s','e','a'}};
   int locations[NCC][2];
   int count=0;

   char ch;
   printf("Enter the character you want to search: ");
   scanf("%c",&ch);

   cc(arr,locations,ch,&count);

   printf("Number of entered character found is: %d ",count);
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote