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

Write a program to swap two numbers without using third variable in c?

1180


Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

1146


Is r written in c?

1189


What is substring in c?

1257


What are near, far and huge pointers?

1112


When should the volatile modifier be used?

1232


What is memcpy() function?

1167


How we can insert comments in a c program?

1187


Can we use any name in place of argv and argc as command line arguments?

1125


What is extern keyword in c?

1184


Is it possible to initialize a variable at the time it was declared?

1255


the maximum length of a character constant can be a) 1 character b) 8 characters c) 256 chaacters d) 125 characters

2343


What is indirection in c?

1116


process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,

2473


The performance of an operation in several steps with each step using the output of the preceding step a) recursion b) search c) call by value d) call by reference

1287