2015-02-11 61 views
-5
#import <Foundation/Foundation.h> 

int main(int argc, const char * argv[]) 
{ 
    NSString * iphone= @"The designs of the iPhone 6 and iPhone 6 Plus were influenced by that of the iPad Air, with a glass front that is curved around the edges of the display, and an aluminum rear that contains two plastic strips for the antenna; both models come in gold, silver, and space gray finishes"; 

    return 0; 
} 

請幫助我找到不使用數組的Objective-C。一個字符串中的元音和輔音的Objective-C計數數量

+4

告訴我們,你已經取得了一些努力,這種自己動手解決。 – 2015-02-11 05:24:49

+1

我看到這個確切的字符串在其他問題中彈出...這是一些某種大型機構的作業嗎?哈哈 – Fonix 2015-02-11 06:02:49

+0

請幫我做到這一點 – appintosh 2015-02-11 06:05:48

回答

0

沒人會爲你編碼。所以,你可以嘗試以下步驟:

  1. 遍歷字符串
  2. 寫元音的條件,並通過1

    增加計數如果(元音) { 計數++ }

  3. 最後從字符串長度減去元音計數得到輔音

    NSString * string = @「This是測試字符串「; int count = 0; for(int index = 0; index < string.length; index ++){ char ch = [string characterAtIndex:index]; if(ch =='a'|| ch =='e'|| ch =='i'|| ch =='o'|| ch =='u'){ count ++; (@「元音:%d」,count); NSLog(@「consonants:%d」,string.length - count);

+0

我是編程新手,所以請幫我做這個 – appintosh 2015-02-11 06:06:30

+0

找到編輯的答案,我不是爲什麼我不能使用代碼塊來構造它 – 2015-02-11 06:15:24

+0

謝謝先生您的幫助 – appintosh 2015-02-11 09:13:53

0
/* you may check this code may be it will be helpful for you*/ 
#include<stdio.h> 
#include<string.h> 
#include<ctype.h> 
int main() 
{ 
char s[100],ch;/*here declare s[100] as array of character and ch defines the character*/ 
int i,vowel_count,con_count;/* vowel_count and con_count(consonant count) declared here as a integer*/ 
printf("Enter the string\n"); 
gets(s); 
vowel_count = con_count = 0; 
for(i=0;i<strlen(s);i++) 
{ 
    if(isalpha(s[i]))/*here we check that string is alphabet or not*/ 
    { 
     ch = tolower(s[i]);/*conversion of character to small letter*/ 
     if (ch=='a'||ch=='e'|| ch=='i'||ch=='o'||ch=='u')/* check whether the character is vowel or not,(a,e,i,o,u) is vowel*/ 
     vowel_count++;/*if a,e,i,o,u will found in string then vowel count is increased*/ 
     else 
     con_count++;/* if consonant is found then count of consonant will incresde*/ 
    } 
} 
printf("No.of vowels = %d\n",vowel_count); 
printf("No.of consonants=%d\n",con_count); 
} 
+2

你能解釋你的答案嗎?僅有代碼的答案是不可接受的,因爲它們絕不會像解釋清楚的代碼一樣幫助提問者(和其他人)。 – 2015-05-29 08:53:37

+1

我非常同意@WaiHaLee! – Leandros 2015-05-29 08:57:01

+0

@WaiHaLee我做了一些修改,請仔細閱讀並感謝您的回覆。@ Leandros – Manmohan 2015-05-29 12:39:00