我编写了这个程序,它以 n 和 k 作为输入,然后以数组 a[n] 作为输入。程序必须将输出给出为数组 a 中小于 k 且为奇数的不同整数的总数。但是这个程序的每个输入都会产生 0 作为输出。
#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;
}
最佳答案
scanf("%d", &a[i]);
必须是:
scanf("%lld", &a[i]);
关于c - 每次输出都相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28784356/