From b68918430bca3b55b7a8157311263c3443971640 Mon Sep 17 00:00:00 2001 From: Rajat Khichee <31896403+rajat9045@users.noreply.github.com> Date: Fri, 5 Oct 2018 12:09:44 +0530 Subject: [PATCH] Update c-linear-search-2.c Reducing number of variables and conditional checks by use of two return statements. --- c-linear-search/c-linear-search-2.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/c-linear-search/c-linear-search-2.c b/c-linear-search/c-linear-search-2.c index 24e15c2..b85591c 100644 --- a/c-linear-search/c-linear-search-2.c +++ b/c-linear-search/c-linear-search-2.c @@ -2,7 +2,7 @@ int main() { - int arr[100], i, num, n, c=0, pos; + int arr[100], i, num, n; printf("Enter the array size : "); scanf("%d", &n); printf("Enter the Array Elements : "); @@ -16,19 +16,11 @@ int main() { if(arr[i]==num) { - c=1; - pos=i+1; - break; + printf("%d found at the position %d", num, i+1); + return 0; } } - if(c==0) - { - printf("Number cannot be found..!!"); - } - else - { - printf("%d found at the position %d", num, pos); - } - + + printf("Number cannot be found..!!"); return 0; }