Question: I want to write an function to print an array from mth element to nth element where m<=n and if a is an array then function calling should looks like print(a+m,a+n). Noow what should be the user defined function for this case?
#include <stdio.h>
#include <iostream>
using namespace std;
/* It may be ok or not. If not then what program should write? */
void print(int a[], int n)
{
for(int i=0;; ++i){
if(a[i] == a[n]) break;
printf("%d ",a[i]);
}
}
int main()
{
int a[6] = {1,3,5,6,8,2};
/*We can use to sort this array of 1st n elements*/
sort(a,a+n);
/*if we want to use c function to sort this array 'a' for 1st 4 elements then we write*/
sort(a,a+4);
/*But if we want use to print 1st n elements than what should user defined function looks like?*/
print(a,a+3); //for this function to print 1st 3 elements what should write user defined function
return 0;
}