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 other ways to find a logic to print whether a number is an even or odd wit out using % symbol??????? i know three different ways to print it. so i need any other different logic>>>>>
Explain how can type-insensitive macros be created?
what are two categories of clint-server application development ?
If I want to initialize the array like. int a[5] = {0}; then it gives me all element 0. but if i give int a[5] = {5}; then 5 0 0 0 0 is ans. what will I do for all element 5 5 5 5 5 in a single statement???
Tell us the difference between these two : #include"stdio.h" #include<stdio.h> define in detial.
write a programme to enter some number and find which number is maximum and which number is minimum from enterd numbers.
A MobileNumber is a VIP number if it satisfy the following conditions. The operator should be Vodafone. Atleast one 0 (Zero) should be exist in mobile number. The number should not end with 8. The single digit sum of all the digits in the number should be equal to 9. For example if the number is 9876543210, the sum is 9+8+7+...+1+0 = 45. Sum of 4+5 = 9. Write a method: private boolean isVIPMobileNumber(String mobileNum, String operator) mobileNum phone number operator mobile operator as bsnl, Vodafone
Simplify the program segment if X = B then C ← true else C ← false
Stimulate calculators to perform addition,subtraction,multiplication and division on two numbers using if/else statement?
What is the benefit of using const for declaring constants?
how to make program without <> in library.
pgm to find middle element of linklist(in efficent manner)