In this page I have written the program to find the largest number in an array using function. For this I have supposed the maximum number at first is of zero position then I have used the concept of replacing values. I have used argument with return values. For more idea have a look.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<conio.h> | |
int m,a,b,n,max; | |
int num[100]; | |
int largest(int num[]); | |
int main() | |
{ | |
printf("how many numbers you want to check\n"); | |
scanf("%d",&n); | |
for(a=0;a<n;a++) | |
{ | |
printf("enter the number %d\n",a+1); | |
scanf("%d",&num[a]); | |
} | |
m=largest(num); | |
printf("the largest num is %d",m); | |
getch(); | |
} | |
int largest(int num[100]) | |
{ | |
int help,max=num[0]; | |
for(a=0;a<n;a++) | |
{ | |
if(max<num[a]) | |
max=num[a]; | |
} | |
return max; | |
} |
0 comments :
Post a Comment