| | |
Frequency Counter
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2007
Posts: 2
Reputation:
Solved Threads: 0
<< split from here >>
how can i make this code to display how meany times a number appears in the array.. example... if there are 5 number 3 it will display this with asterisks..
3 *****
and so on for each number... here is my code... i almost have it
how can i make this code to display how meany times a number appears in the array.. example... if there are 5 number 3 it will display this with asterisks..
3 *****
and so on for each number... here is my code... i almost have it
c Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> #include <time.h> int num_generated[100]; int count(int x); int main(void){ int j,m,a,b,ans,x=0,z=0; srand(time(NULL)); for(j=0;j<100;j++){ num_generated[j]=rand()%11; printf("%d. %d\n ",x, num_generated[j],x++); } printf("\nhere is how meany times each number exist on the array"); for(a=1;a<=10;a++){ ans= count(a); printf("\n%d %d",z,a,z++); for(b=1;b<=ans;b++){ printf("*"); } } } int count(int x){ int cnt,j; for( j=0; j< 100;j++){ if(num_generated[j]==x) cnt++; } return cnt; }
Last edited by ~s.o.s~; Apr 20th, 2007 at 11:21 am. Reason: Added CODE tags -- you actually typed right over how to use them when you entered this post...Added the link to original thread.
•
•
Join Date: Jul 2005
Posts: 1,699
Reputation:
Solved Threads: 273
1) use code tags when posting code to the board
2) intialize cnt to 0 every time count() is called
3) it isn't polite to highjack someone elses thread. Though there is some similarity between your problem and the original problem presented, it's not the same and a new thread should be used.
2) intialize cnt to 0 every time count() is called
3) it isn't polite to highjack someone elses thread. Though there is some similarity between your problem and the original problem presented, it's not the same and a new thread should be used.
Last edited by Lerner; Apr 19th, 2007 at 2:36 pm.
•
•
Join Date: Apr 2007
Posts: 1
Reputation:
Solved Threads: 0
hi i am sending the code to count no of 5's in an array
jus see this.........
my personal id: snipped
jus see this.........
C Syntax (Toggle Plain Text)
#include<stdio.h>#define MAX 5#define LIMIT 5int main(void){int a[MAX]={51,5,855,55,5};int c=0,i,n,r;char b[LIMIT];for(i=0;i<MAX;i++) { n=a[i];while(n!=0){r=n%10;if(r==5){c=c+1;}n=n/10;} }printf("\ncount of 5's is : %d\n",c);return 0;}
Last edited by WaltP; Apr 20th, 2007 at 11:07 am. Reason: Email removed -- Do you really want to increase your SPAM count?
•
•
•
•
hi i am sending the code to count no of 5's in an array
jus see this.........
my personal id: snippedC Syntax (Toggle Plain Text)
#include<stdio.h>#define MAX 5#define LIMIT 5int main(void){int a[MAX]={51,5,855,55,5};int c=0,i,n,r;char b[LIMIT];for(i=0;i<MAX;i++) { n=a[i];while(n!=0){r=n%10;if(r==5){c=c+1;}n=n/10;} }printf("\ncount of 5's is : %d\n",c);return 0;}
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- need help on my code about word frequency counter (C++)
- Word Frequency Counter Help (Java)
- Problem in Reading Array Variable (C)
- letter and word counter (C)
Other Threads in the C Forum
- Previous Thread: strcmp doesn't work... =(
- Next Thread: Can Templates Have prototypes ?
| Thread Tools | Search this Thread |
* adobe api append array arrays bash binarysearch centimeter char character cm copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic execv feet fgets file floatingpointvalidation fork frequency function getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux highest histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer license linked linkedlist linux linuxsegmentationfault list lowest match matrix meter microsoft mqqueue multi mysql oddnumber odf open openwebfoundation overwrite pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scheduling segmentationfault send shape single socketprogramming stack standard strchr string strings suggestions test testautomation unix urboc user whythiscodecausesegmentationfault win32api windows.h








