Write a C function to find the kth occurrence of an even integer in a sequence of non-negative integers, and then call your function from main.
Answers
Answer:
#include<stdio.h>
void check_freq ( int a , int n )
{
int count = 0 ;
int inp=0;
printf ( " Enter numbers :- " );
for( int i=1; i<= 10; i++ )
{
scanf(" %d ", &inp);
if ( inp == a)
count ++;
if( count == n || i > n)
{
printf (" desired number of repetition found ") ;
break;
}
}
}
void main ( )
{
int a, int n;
printf (" Enter the number to be checked ");
scanf("%d" , &a );
printf (" Enter the number of frequency to be checked ");
scanf("%d" , &n );
check_freq( a , n );
}
Answer:
#include <stdio.h>
int even(int k)
{
int i=0;
int curr;
int count=0;
scanf("%d",&curr);
while(curr!=-1){
if ( curr%2==0 ) {
count++;
if(count == k){
return i;
}
}
scanf("%d",&curr);
i++;
}
return -1;
}
int main()
{
int k;
scanf("%d", &k);
printf("%d\n",even(k));
return 0;
}
Explanation: