ccplusplus.com
Learn C, C++ Concepts
Thursday, September 22, 2011
search an element in 2 dimensional array
#include <stdio.h> #define ROW 3 #define COL 3 int main() { int i, j, nElementToSearch, nLocation=0, nLocation_1=0; int a[ROW][COL]; printf("\nseaech an element in 2-Dimensional Array using Linear Search\n"); printf("\nEneter The %d elemets Of Array:", (ROW+1)); for(i=1; i<=2; i++) { for(j=1;j<=2;j++) { scanf("%d", &a[i][j]); } } printf("\nEneter The Value To Be Serched:"); scanf("%d",&nElementToSearch); for(i=1; i<=2; i++) { for(j=1; j<=2; j++) { if(nElementToSearch == a[i][j]) { nLocation = i; nLocation_1 = j; break; } } } printf("\nThe Item is at %d Row And %d Coloumn.",nLocation,nLocation_1); printf("\n\nSearch Completed.\n"); return 0; } /* * OUTPUT * [sgupta@rhel55x86 c]$ gcc search-element-2-d-array.c -o search-element-2-d-array [sgupta@rhel55x86 c]$ ./search-element-2-d-array This Program is Used To seaech an element in 2Dimensional Array using Linear Search Eneter The 4 elemets Of Array:1 2 3 4 Eneter The Value To Be Serched:2 The Item is at 1 Row And 2 Coloumn. Search Completed. [sgupta@rhel55x86 c]$ */
See also
Other popular tricky C Sample Codes and language Concept
.
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment