一个字符串中的元音和辅音的Objective-C计数数量

问题描述:

#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

没人会为你编码。所以,你可以尝试以下步骤:

  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

/* 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