C Programming
1. Provide an equivalent of the java class in C
class Example
{
public static int[][] question4(int n)
{
int[][] result = new int [n][n];
for(int i=1; i<=n; i+=1) for (int j=1; j<=n; j+=1)
result[i][j] = (i*n)+j;
return result;
}
public static void main(String[] args)
{
int[][] my array = question4(4);
}
}
2. Rewrite the following function using no loops, and only tail call recursion
int min (int n, int[] input) { int i; int result; for (result = input[0], i = 0; i < n; i += 1) { if (result > input[i]) result = input[i]; } return result; }
#include <stdio.h>
int **question4(int n)
{
int **result;
for(int i=1; i<=n; i+=1)
{
for (int j=1; j<=n; j+=1)
{
result[i][j] = (i*n)+j;
}
}
return result;
}
int main()
{
int **my_arrayquestion4(4);
return 0;
}
2.
int min(int n, int[] input)
{
int result;
if(n==1)
return input[0];
else {
result=min(n-1,input);
if(result<input[n-1])
return result;
else
return input[n-1];
}
}
Get Answers For Free
Most questions answered within 1 hours.