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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Describe the difference between = and == symbols in c programming?

1350


What is the right type to use for boolean values in c? Is there a standard type?

996


How to delete a node from linked list w/o using collectons?

2767


What is a char in c?

974


What is an example of structure?

1025


Is exit(status) truly equivalent to returning the same status from main?

1052


Write a program to generate the Fibinocci Series

1218


Why do we use return in c?

982


What is the use of static variable in c?

1080


Can we declare function inside main?

986


What is a nested formula?

1117


Why isn't any of this standardized in c? Any real program has to do some of these things.

1190


When should we use pointers in a c program?

1115


simple program of graphics and their output display

1977


Write a program to find factorial of a number using recursive function.

1109