P parker
P parker

Reputation: 81

Output coming same every time

I wrote this program which takes n and k as input and then takes an array a[n] as input. The program must give the output as the total no of distinct integers in array a that are less than k and odd. But this program with every input is producing 0 as output.

    #include<stdio.h>

int main()
{
    long long int n,i,j,k,temp=-1;
    scanf("%lld %lld",&n,&k);

    long long int a[n];

    for(i=0;i<n;i++)
    scanf("%d",&a[i]);

    long long int cnt=0;

    for(i=0;i<n;i++)
    {
        if(a[i]<k)
         {
         if((a[i]%2)==1)
           cnt++;}
    }


    for(i=0;i<(n-1);i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i]==a[j])
            {
                cnt--;
                a[j]=temp;
                --temp;
            }
        }
    }

    printf("%lld",cnt);
    return 0;
}

Upvotes: 0

Views: 74

Answers (2)

Manish
Manish

Reputation: 1

check out the inner for loop, maybe you need to declare a variable and increment that and write and if statement that says, if variable==1 then print the desired value. Not sure but might work.

Upvotes: 0

David Ranieri
David Ranieri

Reputation: 41017

scanf("%d", &a[i]);

Must be:

scanf("%lld", &a[i]);

Upvotes: 1

Related Questions