1
Answer

Write a c function that takes 2 integer parameters. The

Amani Hussam

Amani Hussam

10y
985
1
Q1) write a c function that takes 2 integer parameters. The first parameter is a 2 dimensional array of 4 columns and the second parameter is the number of rows then the function prints the count of odd numbers in each row. And use this function in a c program
Answers (1)
1
Vulpes

Vulpes

NA 163.6k 1.5m 10y
Try this:

#include <stdio.h>

void func(int a[][4], int num_rows)
{
   int i, j, count_odd;
   for(i = 0; i < num_rows; i++)
   {
      count_odd = 0;
      for(j = 0; j < 4; j++)
      {
         if(abs(a[i][j]) % 2 == 1) ++count_odd;
      }
      printf("\nOdd numbers in row %d = %d\n", i + 1, count_odd);
   }
}

int main()
{
   int i, j, num_rows;
   int a[20][4]; 
   printf("How many rows (max 20) : ");
   scanf("%d", &num_rows);
 
   for(i = 0; i < num_rows; i++)
   {
      printf("\nEnter 4 integers for row %d\n", i + 1);
      for(j = 0; j < 4; j++)
      {
         printf(" Column %d : ", j + 1);
         scanf("%d", &a[i][j]);
      } 
   }
   
   func(a, num_rows);
   return 0;