943,719 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 3032
  • C RSS
Nov 18th, 2007
0

A program to print out a word that appears the most number of times

Expand Post »
Write a program to find the number of times that a given word(i.e. a short string) occurs in the sentence(i.e. in a sentence!).

Read data from the standard input. the first line is a single word, which is followed by general text on the second line. read both up to a newline character, and insert a terminating null before processing.

Typical output should be:
The word is "the".
The sentence is "the cat sat on the mat".
The word occurs 2 times.
Similar Threads
Reputation Points: 6
Solved Threads: 0
Light Poster
kiel19 is offline Offline
36 posts
since Nov 2007
Nov 18th, 2007
0

Re: A program to print out a word that appears the most number of times

Atleast show your code (efforts) & specify where you are stuck up. You are expecting that someone will write the entire code for you. You've not even specified what your specific problem is about.


Click to Expand / Collapse  Quote originally posted by kiel19 ...
Write a program to find the number of times that a given word(i.e. a short string) occurs in the sentence(i.e. in a sentence!).

Read data from the standard input. the first line is a single word, which is followed by general text on the second line. read both up to a newline character, and insert a terminating null before processing.

Typical output should be:
The word is "the".
The sentence is "the cat sat on the mat".
The word occurs 2 times.
Reputation Points: 193
Solved Threads: 25
Posting Pro
Jishnu is offline Offline
518 posts
since Oct 2006
Nov 18th, 2007
0

Re: A program to print out a word that appears the most number of times

Click to Expand / Collapse  Quote originally posted by Jishnu ...
Atleast show your code (efforts) & specify where you are stuck up. You are expecting that someone will write the entire code for you. You've not even specified what your specific problem is about.
my code is here , you can help in modifying it to answer the question;
Help me on how to print the names , average mark and comment in descending order.

******************************************************
*******************************************************
  1. #include <stdio.h>
  2. int N;
  3. float array[3];
  4.  
  5. //declaration of structure
  6. struct marks{
  7. char first_name[20];
  8. char second_name[20];
  9. float CSC_2100;
  10. float CSC_2101;
  11. float CSC_2102;
  12. float CSC_2103;
  13. float CSC_2104;
  14. };
  15. struct marks student[5];
  16. // code to compute average
  17. float find_average( float a, float b,float c,float d,float e){
  18. float average = ((a+b+c+d+e)/5);
  19. return average;
  20. }
  21. // to sort the average marks in descending order
  22. void bubblesort(float a[], int N)
  23. {
  24. int i, swapped = 1;
  25. while(swapped)
  26. for (swapped = 0, i = 1; i<N; i++)
  27. if (a[i] > a[i-1]) {
  28. int t = a[i-1];
  29. a[i-1]=a[i];
  30. a[i]=t;
  31. }
  32. }
  33.  
  34.  
  35. int i;
  36. main()
  37. {
  38. printf("Enter marks for five students:\n\n");
  39. printf("Enter your marks as floats:");
  40. for (i = 0;i < 3; i++){
  41. printf("\n\n");
  42. printf("Enter your First name:");
  43. scanf("%s",&student[i].first_name);
  44. printf("Enter your Second Name:");
  45. scanf("%s",&student[i].second_name);
  46. printf("Enter marks for CSC 2100:");
  47. scanf("%f",&student[i].CSC_2100);
  48. printf("Enter marks for CSC 2101:");
  49. scanf("%f",&student[i].CSC_2101);
  50. printf("Enter marks for CSC 2102:");
  51. scanf("%f",&student[i].CSC_2102);
  52. printf("Enter marks for CSC 2103:");
  53. scanf("%f",&student[i].CSC_2103);
  54. printf("Enter marks for CSC 2104:");
  55. scanf("%f",&student[i].CSC_2104);
  56.  
  57. }
  58. for (i =0; i<3; i++){
  59. printf("\n\n");
  60. printf("Name :\t%s %s",student[i].second_name,student[i].first_name);
  61. printf("\nAverage: %.2f\t",find_average(student[i].CSC_2100,student[i].CSC_2101,student[i].CSC_2102,student[i].CSC_2103,student[i].CSC_2104));
  62. printf("\nRemark:\t");
  63. }
  64. for (i = 0; i<3;i++)
  65. array[i]= find_average(student[i].CSC_2100,student[i].CSC_2101,student[i].CSC_2102,student[i].CSC_2103,student[i].CSC_2104);
  66. for (i = 0; i<3;i++)
  67.  
  68.  
  69. bubblesort(array, N);
  70. printf("\n");
  71. for (i =0; i < 3; i++){
  72. printf("%.2f\t",array[i]);
  73. if (array[i]<50)
  74. printf("Sorry try next year");
  75. else
  76. printf("congratulations, you passed!");
  77. printf("\n");
  78. }
  79. return 0;
  80. }
Last edited by Ancient Dragon; Nov 18th, 2007 at 12:25 pm. Reason: add code tags
Reputation Points: 6
Solved Threads: 0
Light Poster
kiel19 is offline Offline
36 posts
since Nov 2007
Nov 18th, 2007
0

Re: A program to print out a word that appears the most number of times

I suppose you think we are that stupid? That isn't your program because it does not do anything that is required in your assignment that you originally posted. We aren't as dumb as you might think we are.

Trash that entire program and begin a new one. This time we want to see YOUR work, not someone elses.
Last edited by Ancient Dragon; Nov 18th, 2007 at 12:29 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Nov 18th, 2007
0

Re: A program to print out a word that appears the most number of times

What nonsense code have you submitted?! I fully agree with Ancient Dragon.
Reputation Points: 193
Solved Threads: 25
Posting Pro
Jishnu is offline Offline
518 posts
since Oct 2006
Nov 18th, 2007
0

Re: A program to print out a word that appears the most number of times

get serious, the re4maing part of the program is, to print the names, the average and the comment but all arranged in descending order, basing on the average
Reputation Points: 6
Solved Threads: 0
Light Poster
kiel19 is offline Offline
36 posts
since Nov 2007
Nov 18th, 2007
0

Re: A program to print out a word that appears the most number of times

teach me how to format my program befor posting
Reputation Points: 6
Solved Threads: 0
Light Poster
kiel19 is offline Offline
36 posts
since Nov 2007
Nov 18th, 2007
0

Re: A program to print out a word that appears the most number of times

Click to Expand / Collapse  Quote originally posted by kiel19 ...
teach me how to format my program befor posting
Its really simple, just put [code=c] at the top and [/code] at the bottom.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Nov 18th, 2007
0

Re: A program to print out a word that appears the most number of times

Click to Expand / Collapse  Quote originally posted by kiel19 ...
teach me how to format my program befor posting
Here you go

You might also try the post titled Read Me: Read This Before Posting as well as this announcement
Moderator
Reputation Points: 3278
Solved Threads: 890
Posting Sage
WaltP is offline Offline
7,718 posts
since May 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: functions in c
Next Thread in C Forum Timeline: help with function in C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC