Algorithm which will find total number of odd integers in the set and sum of all integers.
Q3. Given a set of 125 integers, write an algorithm which will find
- The total number of odd integers in the set
- The sum of all integers.
Ans.
Integer count, sum, i, num;
sum<-0;
count<-0;
i<-0;
while(i<125)
{
print ‘ Enter number’;
read num;
if (num%2!=0)
{
sum<-sum+num;
count<-count+1;
}
i<-i+1;
}
print ‘Count of odd numbers: ‘,count;
print ‘Sum of odd numbers: ‘,sum;