top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can I print the longest number in a string?

+2 votes
347 views

How can I print the longest number in a string?

posted Apr 30, 2014 by Muskan

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
size_t maxlen = 0, len;
int i, maxindex = 0;

for (i = 1; i < argc; i++) {
    len = strlen(argv[i]);
    if (len > maxlen) {
        maxlen = len;
        maxindex = i;
    }
}

printf("The longest string is '%s'\n", argv[maxindex]);
answer Dec 1, 2014 by Shivaranjini
Similar Questions
+3 votes

I hope behavior would be same across languages?

+2 votes

How do I make a checkbox required on an ASP.NET form?

+2 votes

How to use String .Format for an email id?

0 votes

Given a string S and set of strings U. Find the length of longest prefix of S that can be formed using strings in U.

For example you have following -

S= “absolute”
U={“abs”,”xyz”,”ol”,”te”}

Answer: 5 i.e "absol"

Now the task is to have the algorithm/program for the above problem, please help me with this?

...