I want Write C program to enter 10numbers and program will find and print odd numbers and their average. I have been trying many codes but none of them worked for me. If you guys can help me it would be great. Thanks for your replies.
I want Write C program to enter 10numbers and program will find and print odd numbers and their average. I have been trying many codes but none of them worked for me. If you guys can help me it would be great. Thanks for your replies.
Code:#include <stdio.h> #define NUMBERS 10 int main(){ int numbers[NUMBERS]; int count = 0, sum = 0; int i; float avg; printf("Insert numbers, one number by line:n"); for (i=0;i<NUMBERS;i++){ scanf("%d", &numbers[i]); } for (i=0;i<NUMBERS;i++){ if(numbers[i] % 2 == 1){ printf("Odd number: %dn", numbers[i]); sum += numbers[i]; count++; } } printf("n"); avg = (float)sum / count; printf("Average is %.2fn", avg); return 0; }
Have you tried below code? If not then try this code:
Code:if( numbers[i] & 1) { printf("Odd number: %dn", numbers[i]); sum += numbers[i]; count++; }
Bookmarks