hey
I would see on the screen like that UNDER THE mınumum array IT SHOULD WRITE MAX OR MIN WHATEVER YOU CHOOSE for example
if we write 2 arrays 3.4 5.6 0.6 8.6
it must write on the screen
" Arrays 3.4 5.6 0.6 8.6" MIN MUST WRITE UNDER 0.6 ( the minumum array )


it must work as well on Maximum also can anyone add that codes ?
----------------------------------------------------------------------------------------------

#include<stdio.h>



void find_min(double arr[], int n,double *min_value, int *min_position);

void find_max(double arr2[], int n,double *max_value, int *max_position);

int
main(void)
{	
	double A[20];
	double max_val;
	double min_val;
	int min_pos;
	int k,arr_siz;
	int j;
	int max_pos;

	printf("What do you want to do ?\n\n");
	printf("Enter 1 to find the maximum of the array of floating-numbers\n");
	printf("Enter 2 to find the minumum of the array of floating-numbers\n");
	scanf("%d",&j);

	printf("Enter the number of array elements\n");
	scanf("%d",&arr_siz);

	k=0;
	printf("Enter %d floating-point numbers seperated with a space,then presss ENTER:\n",arr_siz);
		
	while (k<arr_siz)
	{
			
		scanf("%lf",&A[k]);
		k++;
	}
	
	k=0;
	printf("aaaaa: ");
	while(k<arr_siz)
	{
		printf("%1f ",A[k]);
		k++;
	}
	printf("\n");		

	
	printf("Array composed of %d floating-point numbers is:\n",arr_siz);
	k=0;
	while(k<arr_siz)
	{
		printf("%1f ",A[k]);
		k++;
	}
	printf("\n\n");
	printf("Array is :\n");

	if(j==1){ 
		find_max(A,arr_siz,&max_val,&max_pos);
		printf("maximum value =%1f \n",max_val);
		printf("is at position %d\n\n",max_pos);
	}
	else
		if (j==2){ 
			find_min(A,arr_siz, &min_val, &min_pos);
			printf("minumum value =%1f \n",min_val);
			printf("is at position %d\n\n",min_pos);
	}
	
	
return 0;
}	




void find_min(double arr[], int n,double *min_value, int *min_position)

{
	int i;
	*min_value=arr[0];
	*min_position=0;
	i=1;
		while (i<n)
		{
			if (arr[i]<*min_value)
			{
				*min_value=arr[i];
				*min_position=i;
			}
				i=i+1;
		}

}

void find_max(double arr[], int n,double *max_value, int *max_position)

{
	int i;
	*max_value=arr[0];
	*max_position=0;
	i=1;
		
		while (i<n)
		{
			if (arr[i]> *max_value)
			{
				*max_value=arr[i];
				*max_position=i;
			}
				i=i+1;
		}

}

Recommended Answers

All 3 Replies

hey
I would see on the screen like that UNDER THE mınumum array IT SHOULD WRITE MAX OR MIN WHATEVER YOU CHOOSE for example
if we write 2 arrays 3.4 5.6 0.6 8.6
it must write on the screen
" Arrays 3.4 5.6 0.6 8.6" MIN MUST WRITE UNDER 0.6 ( the minumum array )

it must work as well on Maximum also can anyone add that codes ?
----------------------------------------------------------------------------------------------

#include<stdio.h>



void find_min(double arr[], int n,double *min_value, int *min_position);

void find_max(double arr2[], int n,double *max_value, int *max_position);

int
main(void)
{	
	double A[20];
	double max_val;
	double min_val;
	int min_pos;
	int k,arr_siz;
	int j;
	int max_pos;

	printf("What do you want to do ?\n\n");
	printf("Enter 1 to find the maximum of the array of floating-numbers\n");
	printf("Enter 2 to find the minumum of the array of floating-numbers\n");
	scanf("%d",&j);

	printf("Enter the number of array elements\n");
	scanf("%d",&arr_siz);

	k=0;
	printf("Enter %d floating-point numbers seperated with a space,then presss ENTER:\n",arr_siz);
		
	while (k<arr_siz)
	{
			
		scanf("%lf",&A[k]);
		k++;
	}
	
	k=0;
	printf("aaaaa: ");
	while(k<arr_siz)
	{
		printf("%1f ",A[k]);
		k++;
	}
	printf("\n");		

	
	printf("Array composed of %d floating-point numbers is:\n",arr_siz);
	k=0;
	while(k<arr_siz)
	{
		printf("%1f ",A[k]);
		k++;
	}
	printf("\n\n");
	printf("Array is :\n");

	if(j==1){ 
		find_max(A,arr_siz,&max_val,&max_pos);
		printf("maximum value =%1f \n",max_val);
		printf("is at position %d\n\n",max_pos);
	}
	else
		if (j==2){ 
			find_min(A,arr_siz, &min_val, &min_pos);
			printf("minumum value =%1f \n",min_val);
			printf("is at position %d\n\n",min_pos);
	}
	
	
return 0;
}	




void find_min(double arr[], int n,double *min_value, int *min_position)

{
	int i;
	*min_value=arr[0];
	*min_position=0;
	i=1;
		while (i<n)
		{
			if (arr[i]<*min_value)
			{
				*min_value=arr[i];
				*min_position=i;
			}
				i=i+1;
		}

}

void find_max(double arr[], int n,double *max_value, int *max_position)

{
	int i;
	*max_value=arr[0];
	*max_position=0;
	i=1;
		
		while (i<n)
		{
			if (arr[i]> *max_value)
			{
				*max_value=arr[i];
				*max_position=i;
			}
				i=i+1;
		}

}

you need to validate the value of arr_siz entered on line 26. What happens to your program if I enter 1000 on that line? Or if I enter a negative value ? Your program will die a very quick and ugly death.

>>it must work as well on Maximum also can anyone add that codes
Looks to me like it already does that.

Oufcourse it needs some protection codes like if you enter negative or 1000 but they are easy to put ,the major problem was that ablr to write "MAX OR MIN"under maximum or minumum values...I think ive already done it also, it works now !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.