So I was pondering about this problem in C using only stdio.h
-
I have to write a program that reads an integer p
and then reads p
integers. Now I have to use these p
integers and perform another operation on them to get a final answer, which my main program will return.
The problem is I don't know how to perform an operation on a variable number of integers. I tried using pointers but they don't seem to work.
Can anyone help please?
#include <stdio.h>
int main(){
int i, p, n;
scanf ("%d", &p);
for (n=0; n<p; n++){
int a;
scanf ("%d", &a);
int *k=&a;
}
for (n=0; n<p; n++){
int a=*k;
if (a==0)
i=0;
else i=1;
}
return i;
}
What I want to do here is to read a certain integer p
, then read p
integers a
, and if at least one of these a
s is 0
, my answer is 0
. Otherwise it's 1
.
But the compiler says *k
is not defined for the second for loop. What should I do?