Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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



please can some one guide me, to the answer Write a C program to enter 15 numbers as an input fro..

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

please can some one guide me, to the answer Write a C program to enter 15 numbers as an input fro..

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

Post New Answer

More C Interview Questions

Tell me a C program to display the following Output? 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5

3 Answers  


How can this be legal c?

0 Answers  


Describe the order of precedence with regards to operators in C.

0 Answers  


Write a c program using for loop to print typical pattern if number of rows is entered by keyboard. ABCBA AB BA A A

1 Answers  


main() { char ch='356'; Printf("%d",ch); } *OUTPUT*:- -18 *Why?*

1 Answers  


Which programming language is best for getting job 2020?

0 Answers  


how to generate the length of a string without using len funtion?

4 Answers  


I have seen function declarations that look like this

0 Answers  


Is there sort function in c?

0 Answers  


Write a program to swap two numbers without using a temporary variable?

0 Answers   Infosys,


Can an array be an Ivalue?

0 Answers   EXL,


c language supports bitwise operations, why a) 'c' language is system oriented b) 'c' language is problem oriented c) 'c' language is middle level language d) all the above

0 Answers  


Categories