Tutorials, Free Online Tutorials,It Challengers provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, core java, sql, php, c language etc. for beginners and professionals.

Breaking

C Program to Search an element in Array

C Program to Search an element in Array

#include<stdio.h> int main() { int arr[30], ele, num, i;
printf("\nEnter no of elements :"); scanf("%d", &num); printf("\nEnter the values :"); for (i = 0; i < num; i++) { scanf("%d", &arr[i]); }
//Read the element to be searched printf("\nEnter the elements to be searched :"); scanf("%d", &ele);
//Search starts from the zeroth location i = 0; while (i < num && ele != arr[i]) { i++; } //If i < num then Match found if (i < num) { printf("Number found at the location = %d", i + 1); } else { printf("Number not found"); } return (0); }

No comments:

Post a Comment