please can some one guide me, to the answer
Write a C program to enter 15 numbers as an input from the
keyboard and program will find and print odd numbers and
their average.
i have studied
while and do while loop
for loop
if and else if
switch
Answers were Sorted based on User's Feedback
Answer / daniel
Here is my (hopefully) not so very complicated piece of code:
#include <stdio.h>
#define NUMBERS 15
int main(){
int numbers[NUMBERS]; // array containing the numbers introduce on the keboard
int count = 0, sum = 0; // variables used to calculate the average
int i;
float avg;
printf("Insert numbers, one number by line:\n");
for (i=0;i<NUMBERS;i++){
scanf("%d", &numbers[i]);
}
//calculate avg
for (i=0;i<NUMBERS;i++){
if(numbers[i] % 2 == 1){ // if it's an odd number print it on the stdout
printf("Odd number: %d\n", numbers[i]);
sum += numbers[i]; // sum the numbers
count++; // count the odd numbers
}
}
printf("\n");
//just one last step
avg = (float)sum / count;
printf("Average is %.2f\n", avg);
return 0;
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / lalabs
// more simple and faster
if( numbers[i] & 1)
{
printf("Odd number: %d\n", numbers[i]);
sum += numbers[i]; // sum the numbers
count++; // count the odd numbers
}
| Is This Answer Correct ? | 0 Yes | 0 No |
what is the function of .h in #include<stdio.h> in c ?
23 Answers HCL, IBM, Wipro,
Write a program to print distinct words in an input along with their count in input in decreasing order of their count
What is assert and when would I use it?
What is the most efficient way to count the number of bits which are set in a value?
What is pre-emptive data structure and explain it with example?
Explain the use of fflush() function?
What does sizeof int return?
WAP TO ACCEPT STRING AND COUNT A COMES N TIMES B COMES N TIMES C COMES N TIMES D COMES N TIMES AND SO ON......... AT LAST UNTIL Z COMES N TIMES...............
Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database
2 Answers TCS, Unisys, Webyog,
for(;;) printf("C language") What is out put of above??
2 Answers Practical Viva Questions,
Why is python slower than c?
write a program to copy a string without using a string?