In: Computer Science
Write a C program that counts the number of odd numbers with using function count() within the set. The set has only one negative number which determines the end of set.
#include <stdio.h>
#include <ctype.h>
#include <math.h>
using namespace std;
int count(int set[])
{
int a, num = 0, i;
for (i = 0; i != -1; i++)
{
a = set[i] % 2;
if (a = !0)
num++;
}
return num;
}
int main()
{
int i,set[] = {
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,-1 };
cout << "total elements in set are";
for (i = 0; set[i] != -1; i++)
{
cout <<
set[i]<<endl;
}
cout <<endl<< "Total odd numbers in set
is: "<<count(set);
system("pause");
return 0;
}
COMMENT DOWN BELOW FOR ANY QUERIES AND,
LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.