Giter Club home page Giter Club logo

logicalinterviewprogramswithanswers-'s Introduction

1==> Given a string of digits and characters.Write a program to find the number with the maximum number of digits in a string. Note: The number may not be the greatest number in the string. for eg. If the string is "ab125cd521" then answer can be 125 or 521 as the problem is to find the number with longest length, not largest value.

Input : hello12345world2134 Output : 12345 Input : xyz4565ab234ed325 Output : 4565

#include <stdio.h> #include <stdlib.h> void main() {

char str[40],numStr[10]="",largestStr[10];
int i,len,indx = 0,arrIndx = 0,arr[20],max = 0;
printf("Enter string :");
gets(str);
len = strlen(str);

// Extract the numbers from string and store into array
for( i = 0; i <= len ; i++)
{
    if ( str[i] >= '0' && str[i] <= '9' )
    {
        while ( str[i] >= '0' && str[i] <= '9' )
        {
            numStr[indx] = str[i];
            indx++;
            i++;
        }
        numStr[indx] = '\0';
        // Convert that number string in to number and store into array
        if ( strlen(numStr) > max )
        {
            max = strlen(numStr);
            strcpy(largestStr,numStr);
        }
        indx = 0;
        strcpy(numStr,"");
    }
}

printf("Largest string = %s",largestStr);
return 0;

}

logicalinterviewprogramswithanswers-'s People

Contributors

bhagatsudheer77 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.