•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 426,127 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,731 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 878 | Replies: 5
![]() |
•
•
Join Date: Apr 2007
Posts: 2
Reputation:
Rep Power: 0
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 10: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,157
Reputation:
Rep Power: 9
Solved Threads: 150
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 1:36 pm.
•
•
Join Date: Apr 2007
Posts: 1
Reputation:
Rep Power: 0
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.........
#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 10: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: snipped#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;}
If you are going to post code, please make sure it's readable. That's what the PREVIEW button is for. And if you're going to do someone's homework for them, make sure you get the grade because he won't deserve it.
Age is unimportant -- except in cheese
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
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 ?





Linear Mode