Problem 3

20 comments on “Problem 3”


  • Mandeep

    #include
    using namespace std;

    int main() {
    int i ,a[50],n,count=0,x;
    cout<>n;
    cout<<"Element of array : \n";
    for(i=0;i>a[i];
    }
    cout<>x;
    for(i=0;i<n;i++)
    {

    if(x==a[i])
    {
    count++;
    }
    }
    cout<<"\n Count : "<<count;

    return 0;
    }


  • dee.pansh18johri

    #include
    using namespace std;

    int main() {

    int n;
    cin>>n;
    map s;
    for(int i=0;i>e;
    s[e]++;
    }
    int x;
    cin>>x;
    cout<<s[x];

    return 0;
    }
    DEEPANSH JOHRI


  • Adarsh

    #include
    using namespace std;

    int main()
    {

    int n;
    cin>>n;
    vectorv(n);
    for(int i=0;i>v[i];
    }
    int t;
    cin>>t;
    int l=lower_bound(v.begin(),v.end(),t)-v.begin();
    int u=upper_bound(v.begin(),v.end(),t)-v.begin();
    cout<<(l-u==0?-1:(u-l))<<"\n";
    return 0;
    }


  • varsha

    #include
    void main()
    {
    int n,i,key,count=0;
    scanf(“%d”,&n);
    int arr[n];
    for(i=0;i<n;i++)
    {
    scanf("%d",&arr[i]);
    }
    key=3;
    for(i=0;i<n;i++)
    {
    if(key==arr[i])
    {
    count++;
    }
    }
    if(count==0)
    {
    printf("-1");
    }
    else
    {
    printf("%d",count);
    }

    }


  • GAURAV

    #include

    using namespace std;
    int left(int arr[],int n){
    int l=0;
    int h=n-1;
    int mid;
    int val=2;
    while(lval)
    h=mid;
    else if(arr[mid]<val)
    l=mid;
    else if(arr[mid]==val&&arr[mid-1]<val){
    return mid;
    }
    else if(arr[mid]==val&&arr[mid-1]==val){
    h=mid;
    }

    }
    }
    int right(int arr[],int n){
    int l=0;
    int h=n-1;
    int mid;
    int val=2;
    while(lval)
    h=mid;
    else if(arr[mid]val){
    return mid;
    }
    else if(arr[mid]==val&&arr[mid+1]==val){
    l=mid;
    }

    }
    }

    int main()
    {
    int arr[]={ 1, 2, 2, 2, 2, 3, 4, 7, 8, 8 };
    int n=sizeof(arr)/sizeof(arr[0]);
    int l=left(arr,n);
    int r=right(arr,n);
    cout<<r-l+1;

    return 0;
    }


  • Ashish

    #include
    #include
    int main()
    {
    int arr[] = {1, 1, 2, 2, 2, 2, 3,},x;
    scanf(“%d”,&x);
    int i,count=0;
    for(i=0;i<(sizeof(arr)/sizeof(int));i++)
    {
    if(arr[i]==x)
    count++;
    }
    printf("%d",count);
    return 0;
    }


  • Ankita

    package PrepInsta;

    import java.util.Scanner;

    public class Frequency2 {

    public static int countfreq(int[] arr,int n,int num)
    {
    int count=0;
    for(int i=0;i<n;i++)
    {
    if(arr[i]==num)
    count++;
    }
    return count;
    }

    public static void main(String[] args)
    {
    Scanner sc=new Scanner(System.in);

    int[] arr= {2,5,6,2,4,5,6,1,3,6};

    System.out.println("Enter number:");

    int num=sc.nextInt();

    int count=countfreq(arr,arr.length,num);
    System.out.println(count);
    }
    }


  • Rohan

    #include
    int main()
    {
    int n, a[100], count=0,i, num;
    printf(“Enter a number\n”);
    scanf(“%d”,&num);
    printf(“enter the size of the array\n”);
    scanf(“%d”,&n);
    printf(“enter the array elements\n”);
    for(i=0; i<n;i++)
    {
    scanf("%d",&a[i]);
    }

    for(i=0; i<n;i++)
    {
    if (num==a[i])
    count++;
    }

    printf("%d ocuured %d times",num, count);
    return 0;

    }