Results 1 to 3 of 3

Thread: C code for print odd numbers and their average

  1. #1
    Join Date
    Sep 2009
    Posts
    54
    Rep Power
    3

    Default C code for print odd numbers and their average

    I want Write C program to enter 10numbers and program will find and print odd numbers and their average. I have been trying many codes but none of them worked for me. If you guys can help me it would be great. Thanks for your replies.

  2. #2
    John Alster is offline Member
    Join Date
    Jun 2009
    Posts
    57
    Rep Power
    3

    Default

    Code:
    #include <stdio.h>
    #define NUMBERS 10
    int main(){
    	int numbers[NUMBERS];	
    int count = 0, sum = 0;  	
    int i; float avg;
    	printf("Insert numbers, one number by line:n");
    	for (i=0;i<NUMBERS;i++){
    		scanf("%d", &numbers[i]);
    	}
    	
    	for (i=0;i<NUMBERS;i++){
    		if(numbers[i] % 2 == 1){
    printf("Odd number: %dn", numbers[i]);
    			sum += numbers[i]; 		
    			count++;		}
    	}
    	printf("n");
    	avg = (float)sum / count;
    	printf("Average is %.2fn", avg);
    	return 0;
    }

  3. #3
    Mackie Carien is offline Member
    Join Date
    Jun 2009
    Posts
    52
    Rep Power
    3

    Default

    Have you tried below code? If not then try this code:
    Code:
    if( numbers[i] & 1)
    {
         printf("Odd number: %dn", numbers[i]);
         sum += numbers[i]; 
         count++; 
    }

Similar Threads

  1. AMD again with red numbers
    By Lolita Jovina in forum Latest Hardware News
    Replies: 0
    Last Post: 10-16-2010, 06:50 AM
  2. Average storage utilization much lower- analyst
    By mark_carter in forum Latest Hardware News
    Replies: 0
    Last Post: 07-28-2010, 04:47 PM
  3. Write a code for to print grouping of numbers
    By CoxWatson in forum Software Jargons
    Replies: 2
    Last Post: 05-07-2010, 01:59 PM
  4. Print grouping of numbers in C
    By CoxWatson in forum Programming
    Replies: 1
    Last Post: 03-27-2010, 01:27 PM
  5. C# program to print random numbers
    By Garcíarobine in forum Programming
    Replies: 2
    Last Post: 01-13-2010, 05:47 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48