Please help me>>>>

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alfarah
    New Member
    • Oct 2008
    • 2

    Please help me>>>>

    how to wirte C program to calculate and print the number of different symbols used in a given string. A blank space counts as one symbol.

    Input: Any string. The length is limited to 60 characters. For example:

    Enter a string: Mississipi

    Test data:
    #1. “Say good bye!”
    #2. “The world is round”

    Output: The number of different symbols. For example, the output for the string “Mississipi” is

    Number of symbols for the string “Mississippi” is: 4
    --------------------------------------------------------------------------------
    can you help me....
  • curiously enough
    New Member
    • Aug 2008
    • 79

    #2
    Declare one array of charachters for storing unique symbols and called symbols[100], and declare one integer n for storing the number of symbols and set it intially to zero, and an integer called test to check if a symbol in the string is repeated, and ofcourse declare an array string[100] to store the string.
    Now start with this for loop: for(int i=0 ; i<strlen(string ) ; i++) so you can check every symbol in the string, then set the integer test to 0 inside this for loop, then also inside this for loop use another for loop which is: for(int j=0 ; j<n ; j++) to check if this symbol is repeated by using the array symbols[] where j is its index(symbols[j]), and if this symbol(which is string[i]) is found in the array symbols[] then set the integer test to 1 and break from the second loop, and if it is not found set it to 0. Now after the second for loop is finished(either way) check the integer test, if it is equal to 0 put this symbol(which is symbol[i]) in the the array symbols(i.e: write symbols[n] = string[i]) and then increment n( meaning n++ ). But if test is equal to 1 do nothing(meaning the charachter string[i] is present more than once in the string), and here the first for loop is repeated.
    And now you have the number of symbols, which is n.

    Comment

    • alfarah
      New Member
      • Oct 2008
      • 2

      #3
      thanks very much........... ...............

      Comment

      Working...