-->

WAp to find greatest number among ten numbers. PAss array as parameter.

in turboc++
-----------------------------------------------------------------------------------
//WAp to find greatest number among ten or more numbers. PAss array as parameter.
#include<stdio.h>
#include<conio.h>
#include<conio.h>
void max_of_array(float array[100],int size);//prototype with array and size parameters
int main()
{

float arr[100];int k;            // array declaration with maximum limit 100
int size;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
for(k=0;k<size;k++)//loop execution

{
   printf("enter element for location=%d\n",k); // for elements in particular location
   scanf("%f",&arr[k]);//data inputs
}
max_of_array(arr,size);//calling of function
getch();
return 0;
}

void max_of_array(float array[100],int size)//body line
{

int k;//declaration
int max;
max=array[0];//assigning first value to max.

for(k=0;k<size;k++)//loop execution

{
if(max<array[k])//condition testing
    {
        max=array[k];//assigning value if the condition is true
    }
}

printf("maximum element=%d",max);//printing maxmimum element

getch();

}

------------------------------------------------------------------------------------------
in codeblocks
----------------------------------------------------------------------------
//WAp to find greatest number among ten or more numbers. PAss array as parameter.
#include<stdio.h>
#include<conio.h>
void max_of_array(float array[5],int size);//prototype with array and size parameters
int main()
{

float arr[100];int k;            // array declaration with maximum limit 100
int size;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
for(k=0;k<size;k++)//loop execution

{
   printf("enter element for location=%d\n",k); // for elements in particular location
   scanf("%f",&arr[k]);//data inputs
}
max_of_array(arr,size);//calling of function
return 0;
}

void max_of_array(float array[5],int size)//body line
{

int k;//declaration
int max;
max=array[0];//assigning first value to max.

for(k=0;k<size;k++)//loop execution

{
if(max<array[k])//condition testing
    {
        max=array[k];//assigning value if the condition is true
    }
}

printf("maximum element=%d",max);//printing maxmimum element

getch();

}

No comments:

Post a Comment