0% found this document useful (0 votes)
542 views6 pages

FLOW and ALGO 10

The document describes functions to implement string operations like compare, concatenate, and length. It includes algorithms and functions for each operation, passing parameters between them. The length function returns the length of a string. The compare function compares two strings and returns if they are equal, string1 is greater, or string1 is less. The concatenate function combines two strings by iterating through each and copying characters.

Uploaded by

Radhika Ajadka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
542 views6 pages

FLOW and ALGO 10

The document describes functions to implement string operations like compare, concatenate, and length. It includes algorithms and functions for each operation, passing parameters between them. The length function returns the length of a string. The compare function compares two strings and returns if they are equal, string1 is greater, or string1 is less. The concatenate function combines two strings by iterating through each and copying characters.

Uploaded by

Radhika Ajadka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

10.

Write functions to implement string operations such as compare,


concatenate, string length. Convince the parameter passing techniques.

Algorithm:
Step1:[Start]
Begin
Step 2: [Read the input- two strings]
Read str1, str2
Step 3: [invoke the string length function with one parameter]
Len(str1)
[Invoke the string compare function with two parameters]
Comp(str1,str2);
[invoke the string concatenate function with two
parameters]
Concat(str1,str2);
Step 4: [Stop]
End
Function- Len()

Step1: [start]
begin
Step2: [Iterate through the string till the Null character and increment
the count]
Str1[length]!=’\0’
length++;
Step3:[Print the length]
Print length
Step4: [Stop]
End

Function- Comp()
Step1: [Start]
begin
Step2: [iterate through the string1 and string2 till they are equal]
Str1[i]==str2[i]
Step3: [till the end of the first string increment the counter]
If str1[i]==’\0’ then increment counter
Else
Break
Step 4: [find the difference between the characters]
Res = str1[i]-str2[i]
Step5: [check the value of the res to decide string are equal, greater or
lesser]
If res==0
Print strings are equal
Else if res<0
Print string1 is less than string 2
Else
Print string1 is greater than string2
Step6: [stop]
End

Function- concat()
Step 1: [Start]
Begin
Step 2: [iterate till the end of first string]
Str1[i]!=’\0’, Increment i
Step3: [iterate till the end of the second string and copy the characters
from string
2 to string 1]
str2[j]!='\0'
str1[i]=str2[j];
increment j
increment i
Step4: [Print the output]
Attach the null character to the end of first string
Print str1
Step5: [Stop]
End

Flowchart:
Program:
#include<stdio.h>
#include<string.h>
int length = 0,i=0,j=0,res; // Initialization
void len(char[]); //Function Declaration
void concat(char[],char[]);
void comp(char[],char[]);

void main()
{
char str1[100], str2[100];

printf("\nEnter the first String : ");


gets(str1);
printf("\nEnter the Second String : ");
gets(str2);

len(str1);
comp(str1,str2); //Function Calling
concat(str1,str2);
}

void len(char str1[]) //Function Defination


{
while (str1[length] != '\0')
length++;

printf("\nLength of the String1 is : %d", length);

void concat(char str1[],char str2[])


{
while(str1[i]!='\0')
i++;
while(str2[j]!='\0')
{
str1[i]=str2[j];
j++;
i++;
}
str1[i]='\0';
printf("\n Concatenated String is %s\n",str1);
}

void comp(char str1[],char str2[])


{
int i=0;
while(str1[i]==str2[i])
{
if(str1[i]=='\0') break;
i++;
}
res=str1[i]-str2[i];

if(res==0)
printf("\n%s is equal to %s\n",str1,str2);
else if(res>0)
printf("\n%s is greater than %s \n",str1,str2);
else printf("\n %s is less than %s \n",str1,str2);
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy