Apply for Zend Framework Certification Training

c




< First Create an code for palendrome >



Problem:
Find the longest word.
Code:
#include<stdio.h>
int main(){
    char mystring[]="c is an programming language";
    int length=0,count=0,largestWordlength=0,wordIndex=0,i;
    while(mystring[length]!='\0'){
        length++;
    }
    for(i=0;i<=length;i++){
        if(mystring[i]==' '|| mystring[i]=='\0'){
            if(largestWordlength < count){
                largestWordlength = count;
                wordIndex=i;
            }
            printf("%d \n",count);
            count=0;
        }else{
            count++;
        }
    }
    printf("Largest word index  %d and length %d\n",wordIndex,largestWordlength);
    int start= wordIndex-largestWordlength;
    printf("%d \n",start);
    for(i=start;i<wordIndex;i++){
        printf("%c",mystring[i]);
    }
}
Output 
1
2
2
11
8
Largest word index  19 and length 11
8
programming

 

< First Create an code for palendrome >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top