| | |
Errors in counting number of elements of the array greater and lesser than average
![]() |
•
•
Join Date: Feb 2007
Posts: 31
Reputation:
Solved Threads: 0
Errors in counting number of elements of the array greater and lesser than average
0
#1 May 16th, 2007
Q.Write a program to input data in an array.Compute the sum and average.Then count the number of values greater than the average and lesser than the average.Print the average,sum and the two counts.
Solution I tried
Everything works fine but the counts computed are both wrong.Please help!
Solution I tried
C Syntax (Toggle Plain Text)
#include<stdio.h> int main(void) { int X[10],i,lesser=0,greater=0,sum=0; float avg=0; for(i=0;i<10;i++) { printf("Enter number\n"); scanf("%d",&X[i]); } for(i=0;i<10;i++) { sum=sum+X[i]; avg=sum/10.0; if((float)X[i]>avg) { greater++; } else if((float)X[i]<avg) { lesser++; } } printf("Average of numbers is %f\n",avg); printf("sum of numbers is %d\n",sum); printf("No of elements greater than avg are %d and lesser are %d",greater,lesser); return(0); }
Everything works fine but the counts computed are both wrong.Please help!
•
•
Join Date: May 2006
Posts: 38
Reputation:
Solved Threads: 2
Re: Errors in counting number of elements of the array greater and lesser than average
0
#2 May 16th, 2007
Re: Errors in counting number of elements of the array greater and lesser than average
0
#3 May 16th, 2007
![]() |
Similar Threads
- assign elements to a multi-d array (C)
- using boolean expression on an array (Java)
- Geting elements from a String Array (C++)
- Array without twice the same number? (C)
Other Threads in the C Forum
- Previous Thread: help me
- Next Thread: Linked Lists in C
| Thread Tools | Search this Thread |
* adobe api array arrays binarysearch calculate centimeter char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking hardware highest homework i/o ide inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h






