Searching a presence of particular number among number of integers : C Programming

Q. WAP to search a presence of certain number among different integer entered by user

==> Code goes like this:

#include<stdio.h>
int main()
{
    int i,num,a[50],counter,times=0;
    printf("Enter size of array: ");
    scanf("%d",&num);
    printf("Enter %d elements: ",num);
    for(i=0;i<num;i++)
    {
        scanf("%d",&a[i]);
    }                        // Taking values till now

    printf("Enter a number to be searched: ");
    scanf("%d",&counter);     // Taking number to search in array
   
    for(i=0;i<num;i++)
    {
            if(a[i]==counter)          
            {
            times+=1;          //counting the integer which is entered for search
            }
    }                           
    printf("Number %d is presented for %d times ",counter, times);
return 0;   
}

Output:



















I have used Dev CPP to compile this program.
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you 
Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment