Sunday, 24 April 2022

3. Write a user defined function which will return the length of the string declared locally in the main function.

 



#include<stdio.h>
#include<conio.h>

int length(char *);

void main()
{
    int len;
    char str[99];
    clrscr();

    printf("enter string: ");
    gets(str);

    len = length(str);

    printf("\n\nyour string length is: %d",len);
    getch();
}

int length(char *l)
{
    int i,k=0;

    for(i=0; l[i] != '\0'; i++)
    {
        k++;
    }

    return k;
}

/*  output:

enter string: vrushal pandav


your string length is: 14

*/

No comments:

Post a Comment

python programs

1. sum of two number