Ia 2
Ia 2
Ia 2
Answer:
Syntax
Strcat [destination string source string];
Ex
String1=”VERY”.
String2=”GOOD”
Output
Strcat(strings1,string2);
VERY GOOD
(ii).Strcat():
Strcpy() is ised to copy one string to another string.
This fuction can works like assignment operator for the given
string.
Syntax
Strcpy(string1+,string2);
Output
“GOOD”
(iii).Strcmp():
Syntax
Strcmp(string1,string2);
Ex
Char str1[]=”fresh”;
Char str2[]=”refresh”;
Int I,j,k;
I=strcmp(str1,”fresh”);
J=strcmp(str1,str2);
K=strcmp(str1,”f”);
Printf(“%d%d%d”,I,j,k);
(iv). Strlen():
Programming in C & Data Structures
Syntax
N=strlen(string1);
String1=”Welcome”;
N=strlen(string1);
N=7.
(v). Strrev():
Syntax
String2=strrev(string1);
Ex
String1=”home”;
String2=strrev(string1);
String2=”emoh”.
(vi). Strupr():
Syntax
Str2=strupr(str1);
Ex
Str1=”Welcome”
Str2=strupr(str1);
Str2=”WELCOME”.
(vii). Strlwr():
Ex
Str1=”PROGRAMMING IN C”;
Str2=strlwr(str1);
Str2=”programming in c”.
Example
#include<stdio.h>
#include<conio.h>
Void main()
{
Char str1[]=”welcome”
Char str2[]=”to cs”; char str3[20];int n;
Clrs();
Printf(“string manipulation \n”);
Programming in C & Data Structures
Answer:
Library Function
User Defined Function
Function
Library Function:
EX
include<stdio.h>
Printf,scanf functions are available in this leader file.
Syntax
EX
int add number(int a,int b);
int add number(int,int);
Both are the examples of vaild function.
Parameter names are not important in function declaration only the
type in important.
Definition Of Function:
Syntax
function-type function name(argument list)
{
Local Variable declaration;
executeble Statent 1;
executeble Statent 2;
……………………………………………………
……………………………………………………
Return(expression);
}
Programming in C & Data Structures
Rules:
EX
#include<stdio.h>
int add numbers(int a,int b);
int main()
{
Int n1,n2,sum;
Printf(“Enter two Numbers\n”);
Scanf(“%d%d”,&n1&n2);||function call sum =(add numbers(n1,n2);
Printf(“The sum is %d”,sum);
Return 0;
}
Int add numbers(int a;int b)||function definition)
{
int result;
int =a+b;
return ;
}
Void
Syntax
Void function name(argument list)
Ex
Int factorial (int x)
{
int r=1;
if(r=1)
return 1;
else
r=x*factorial(x=1);
return r;
}
Function Calls:
Syntax
Function name(argument list);
Rules:
Answer:
Syntax
Types Of Recursion:
Direct Recursion
Indirect Recursion
Direct Recursion:
A function is said to be direct recursion if its called
directly by itself.
{
……………………
recursion name();
}
EX
main()
{
printf(“tthis is direct recursion example \n”);
main();
}
Indirect Recursion:
A function is said to be indirect recursion if it call another
function and this new function calls the first calling function again.
EX
#include<stdio.h>
int factorial(int n)
{
if(n==0)
return 1;
else
return(n*factorial(n-1));
}
int main()
{
int num f;
printf(“Enter a number \n”);
scanf(“%d”,& num);
f = factorial(num);
printf(“factorial of %d = %d”num,f);
return 0;
}
Output
Enter a number Authors
5
factorial of 5 = 120
Love Devil