Basic Programs
If Else based Programs
Loop Based Programs
Array Based Programs
String Programs
Function Programs
Pointers Programs
Structure & File Handling Programs
Data Structure Programs
Array based programs
Program to search a number in an array
#include <stdio.h> #include <conio.h> void main() { int a[10], i=0, ele=0, flag=0; printf("enter array elements"); for(i=0; i<10; i++) { scanf("%d", &a[i]); } printf("enter the element to search"); scanf("%d", &ele);
// logic to find the element in the given array. for(i=0; i<10; i++) { if(a[i]==ele) { flag=1; break; } }
if(flag==1) printf("element found"); else printf("element not found"); }
Output of the above program is as following.
Video/ C Introduction
Watch video in full size