• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Unit 5 Foc
 

Unit 5 Foc

on

  • 3,335 views

ARRAYS,FUNCTIONS AND POINTERS

ARRAYS,FUNCTIONS AND POINTERS

Statistics

Views

Total Views
3,335
Views on SlideShare
3,327
Embed Views
8

Actions

Likes
1
Downloads
319
Comments
0

1 Embed 8

http://www.ustudy.in 8

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Unit 5 Foc Unit 5 Foc Presentation Transcript

    • UNIT - 5 FUNCTIONS AND POINTERS
    • FUNCTION
      • Functions is a sub-program that contains one or more statements and it performs some task when called.
    • Types Functions User-Defined Functions Pre-Defined Functions
    • Pre-Defined Functions
      • The pre-defined functions or library functions are built-in functions.
      • The user can use the functions, but cannot modify the function.
      • Example: sqrt()
    • User-Defined Functions
      • The functions defined by the user for their requirement are called user-defined functions.
      • Whenever it is needed, The user can modify the function.
      • Example: sum(a,b)
    • Advantage of User-Defined Functions
      • The length of the source program can be reduced.
      • It is easy to locate error.
      • It avoid coding of repeated instructions.
    • Elements of User-Defined Function
      • Function declaration
      • Function definition
      • Function call
    • Function
      • Syntax
      • datatype function_name (parameters list)
      • {
      • local variable declaration;
      • …………………………
      • body of the function;
      • …………………………
      • return(expression);
      • }
    • How Function Works
      • Once a function is called the control passes to the called function.
      • The working of calling function is temporarily stopped.
      • When the execution of called function is completed then the control return back to the calling function and execute the next statement.
    •  
    • Parameters
      • Actual Parameter
      • These are the parameters transferred from the calling function to the called function.
      • Formal Parameter
      • These are the parameters which is used in the called function.
    •  
    • return Statement
      • The return statement may or may not send some values to the calling function.
      • Syntax:
      • return; (or)
      • return(expression);
    • Function Prototypes
      • Function with no arguments and no return values.
      • Function with arguments and no return values.
      • Function with arguments and return values.
      • Function with no arguments and with return values.
    • Function with no arguments and no return values
      • Here no data transfer take place between the calling function and the called function.
      • These functions act independently, i.e. they get input and display output in the same block.
    •  
    • Example
      • #include <stdio.h>
      • #include<conio.h>
      • void main() //calling function
      • {
      • void add(void);
      • add();
      • }
      • void add() //called function
      • {
      • int a,b,c;
      • printf(&quot; Enter two number:&quot;);
      • scanf(&quot;%d%d&quot;,&a,&b);
      • c=a+b;
      • printf(&quot; Sum is:%d&quot;,c);
      • }
    • Output
      • Enter two number:3
      • 4
      • Sum is:7
    • Function with arguments and no return values
      • Here data transfer take place between the calling function and the called function.
      • It is a one way data communication , i.e. the called program receives data from calling program but it does not return any value to the calling program.
    •  
    • Example
      • #include <stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int a,b;
      • void add(int,int);
      • printf(&quot; Enter two number:&quot;);
      • scanf(&quot;%d%d&quot;,&a,&b);
      • add(a,b);
      • }
      • void add(int x,int y) //function with arguments
      • {
      • int z;
      • z=x+y;
      • printf(&quot; Sum is:%d&quot;,z);
      • }
    • Output
      • Enter two number:2
      • 4
      • Sum is:6
    • Example
      • #include <stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int a,b;
      • void add(int a,int b);
      • printf(&quot; Enter two number:&quot;);
      • scanf(&quot;%d%d&quot;,&a,&b);
      • add(a,b);
      • }
      • void add(int x,int y) //function with arguments
      • {
      • int z;
      • z=x+y;
      • printf(&quot; Sum is:%d&quot;,z);
      • }
    • Output
      • Enter two number:2
      • 4
      • Sum is:6
    • Function with arguments and return values
      • Here data transfer take place between the calling function and the called function as well as between called function and calling function .
      • It is a two way data communication , i.e. the called program receives data from calling program and it return some value to the calling program.
    •  
    • Example
      • #include <stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int a,b,c;
      • int add(int,int);
      • printf(&quot; Enter two number:&quot;);
      • scanf(&quot;%d%d&quot;,&a,&b);
      • c=add(a,b);
      • printf(&quot; Sum is:%d&quot;,c);
      • }
      • int add(int x,int y)
      • {
      • int z;
      • z=x+y;
      • return(z);
      • }
    • Output
      • Enter two number:6
      • 7
      • Sum is:13
    • Function with no arguments and with return values
      • Here data transfer take place between the called function and the calling function.
      • It is a one way data communication , i.e. the called program does not receives data from calling program but it return some value to the calling program.
    •  
      • #include <stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int add(),d;
      • d=add();
      • printf(&quot; Sum is:%d&quot;,d);
      • }
      • int add() //function wit no argument
      • { int a,b,c;
      • printf(&quot; Enter two number:&quot;);
      • scanf(&quot;%d%d&quot;,&a,&b);
      • c=a+b;
      • return(c);
      • }
    • Output
      • Enter two number:5
      • 8
      • Sum is:13
    • Parameter Passing Methods
      • Call by value
      • Call by reference
    • Call by value
      • Actual argument passed to the formal argument.
      • Any changes to the formal argument does not affect the actual argument.
    • Example
      • #include <stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int x,y,change(int,int);
      • printf(&quot; Enter value of x:&quot;);
      • scanf(&quot;%d&quot;,&x);
      • printf(&quot; Enter value of y:&quot;);
      • scanf(&quot;%d&quot;,&y);
      • change(x,y);
      • printf(&quot; Values in the Main()-->x=%d,y=%d&quot;,x,y);
      • }
      • int change(int a,int b)
      • {
      • int c;
      • c=a;
      • a=b;
      • b=c;
      • printf(&quot; Values in the Fuction -->x=%d,y=%d&quot;,a,b);
      • }
    • Output
      • Enter value of x:5
      • Enter value of y:6
      • Values in the Fuction -->x=6,y=5
      • Values in the Main()-->x=5,y=6
    • Call by reference
      • Instead of passing value, the address of the argument will be passed.
      • Any changes to the formal argument will affect the actual argument.
    • Example
      • #include <stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int x,y,change(int*,int*);
      • printf(&quot; Enter value of x:&quot;);
      • scanf(&quot;%d&quot;,&x);
      • printf(&quot; Enter value of y:&quot;);
      • scanf(&quot;%d&quot;,&y);
      • change(&x,&y);
      • printf(&quot; Values in the Main()-->x=%d,y=%d&quot;,x,y);
      • }
      • int change(int *a,int *b)
      • {
      • int c;
      • c=*a;
      • *a=*b;
      • *b=c;
      • printf(&quot; Values in the Function -->x=%d,y=%d&quot;,*a,*b);
      • }
    • Output
      • Enter value of x:5
      • Enter value of y:6
      • Values in the Function -->x=6,y=5
      • Values in the Main()-->x=6,y=5
    • Recursion
      • It is a process of calling the same function itself again and again until some condition is satisfied.
      • Syntax:
      • func1()
      • {
      • ……… ..
      • func1();
      • }
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int a;
      • int rec(int);
      • printf(&quot; Enter the number:&quot;);
      • scanf(&quot;%d&quot;,&a);
      • printf(&quot;The factorial of %d! is %d&quot;,a,rec(a));
      • }
      • int rec(int x)
      • {
      • int f;
      • if(x==1)
      • return(1);
      • else
      • f=x*rec(x-1);
      • return(f);
      • }
      • Output:
      • Enter the number:5
      • The factorial of 5! is 120
    • Example: Working of 3!
    • Tower of Honoi 1 2 3 3 2 3 1 3 2 3
    • Tower of Honoi 1 2 3 3 2 3 1 3 2 3
    • Library Function
      • It is pre-defined function.
      • The library function provides functions like mathematical, string manipulation etc,.
    • Example
      • sqrt(x):
      • It is used to find the square root of x
      • Example: sqrt(36) is 6
      • abs(x):
      • It is used to find the absolute value of x
      • Example: abs(-36) is 36
      • pow(x,y):
      • It is used to find the value of x y
      • Example: pow(5,2) is 25
      • ceil(x):
      • It is used to find the smallest integer greater than or equal to x
      • Example: ceil(7.7) is 8
      • rand():
      • It is used to generate a random number.
      • sin(x):
      • It is used to find the sine value of x
      • Example: sin(30) is 0.5
      • cos(x):
      • It is used to find the cosine value of x
      • Example: cos(30) is 0.86
      • tan(x):
      • It is used to find the tan value of x
      • Example: tan(30) is 0.577
      • toascii(x):
      • It is used to find the ASCII value of x
      • Example: toascii(a) is 97
      • toupper(x):
      • It is used to convert lowercase character to uppercase.
      • Example: toupper(‘a’) is A
      • toupper(97) is A
      • tolower(x):
      • It is used to convert uppercase character to lowercase.
      • Example: tolower(‘A’) is a
    • Example:
      • #include<stdio.h>
      • #include<conio.h>
      • #include<math.h>
      • #include<ctype.h>
      • void main()
      • {
      • int x,y=2;
        • printf(&quot; Enter the number:&quot;);
        • scanf(&quot;%d&quot;,&x);
        • printf(&quot; The squareroot of %d is %f&quot;,x,sqrt(x));
      • printf(&quot; The value of %d power%dis%f &quot;,x,y,pow(6,2));
        • printf(&quot; The ceiling of 6.7 is %f&quot;,ceil(6.7));
        • printf(&quot; The floor of 6.7 is %f&quot;,floor(6.7));
        • printf(&quot; The absolute value of -6 is %d&quot;,abs(-6));
        • printf(&quot; The value of sin 45 is %f&quot;,sin(45));
        • printf(&quot; The uppercase of 'a' is %c&quot;,toupper('a'));
        • printf(&quot; The uppercase of 97 is %c&quot;,toupper(97));
      • getch();
      • }
    • Output:
      • Enter the number:6
      • The squareroot of 6 is 2.449490
      • The value of 6 power 2 is 36.000000
      • The ceiling of 6.7 is 7.000000
      • The floor of 6.7 is 6.000000
      • The absolute value of -6 is 6
      • The value of sin 45 is 0.850904
      • The uppercase of 'a' is A
      • The uppercase of 97 is A
    • Array
      • An Array is a collection of similar data items, that are stored under a common name.
      • Types
        • One-Dimensional array
        • Two-Dimensional array
        • Multi-Dimensional array
    • One-Dimensional array Array Declaration
      • Syntax:
      • data_type array_name[size];
      • Example: int x[3];
      X[0] X[1] X[2] x
    • Array initialization
      • At compile time
      • At run time
    • At compile time
      • Syntax:
      • data_type array_name[size]={variables};
      • Example: int x[3]={5,3,7};
      X[0] X[1] X[2] x 7 3 5
    • At Run time
      • Array can also initialize at the run time.
      • Example:
      • while(i<10)
      • {
      • if(i<5)
      • sum[i]=0;
      • else
      • sum[i]=sum[i]+i;
      • }
      • Example:
      • scanf(“%d%d”,&a[0],&a[1]);
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int x[2],i;
      • printf(&quot; Enter the inputs:&quot;);
      • for(i=0;i<2;i++)
      • scanf(&quot;%d&quot;,&x[i]);
      • for(i=0;i<2;i++)
      • printf(&quot; The value in x[%d] is %d&quot;,i,x[i]);
      • getch();
      • }
    • Output
      • Enter the inputs:3
      • 6
      • The value in x[0] is 3
      • The value in x[1] is 6
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int i;
      • char x[5]={'a','b','c','d','e'};
      • clrscr();
      • for(i=0;i<5;i++)
      • printf(&quot; The value in x[%d] is %c&quot;,i,x[i]);
      • getch();
      • }
    • Output
      • The value in x[0] is a
      • The value in x[1] is b
      • The value in x[2] is c
      • The value in x[3] is d
      • The value in x[4] is e
    • Two-Dimensional array Array Declaration
      • Syntax:
      • data_type array_name[row_size] [col_size];
      • Example: int x[3][2];
      X[0][0] X[1][0] X[2][0] Col 0 Col 1 row 0 row 1 row 2 X[0][1] X[1][1] X[2][1]
    • Array Initialization
      • Syntax:
      • data_type array_name[row_size] [col_size];={variables};
      • Example: int x[2][2]={1,50,2,75};
      • int x[2][2]={ {1,50},
      • {2,75}
      • };
      • (or)
      • int x[ ][2]={ {1,50},
      • {2,75}
      • };
    • row 0 row 1 Col 0 Col 1 2 1 75 50
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int i,j;
      • int x[2][2]={ {1,50},
      • {2,75}
      • };
      • clrscr();
      • for(i=0;i<2;i++)
      • for(j=0;j<2;j++)
      • printf(&quot; The value in x[%d][%d] is %d&quot;,i,j,x[i][j]);
      • getch();
      • }
    • Output
      • The value in x[0][0] is 1
      • The value in x[0][1] is 50
      • The value in x[1][0] is 2
      • The value in x[1][1] is 75
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int i,j;
      • int x[][2]={ {1,50},{2,75},{3,65}};
      • clrscr();
      • for(i=0;i<=2;i++)
      • for(j=0;j<2;j++)
      • printf(&quot; The value in x[%d][%d] is %d&quot;,i,j,x[i][j]);
      • getch();
      • }
    • Output
      • The value in x[0][0] is 1
      • The value in x[0][1] is 50
      • The value in x[1][0] is 2
      • The value in x[1][1] is 75
      • The value in x[2][0] is 3
      • The value in x[2][1] is 65
    • Matrix Addition
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int i,j,k,r1,r2,c1,c2;
      • int a[5][5],b[5][5],c[5][5];
      • clrscr();
      • step1:
      • printf(&quot; Enter the size of matrix A:&quot;);
      • scanf(&quot;%d%d&quot;,&r1,&c1);
      • printf(&quot; Enter the size of matrix B: &quot;);
      • scanf(&quot;%d%d&quot;,&r2,&c2);
      • if((c1==c2)&&(r1==r2))
      • goto step2;
      • else
      • goto step1;
      • step2:
      • printf(&quot; Enter the elements of matrix A &quot;);
      • for(i=0;i<r1;i++)
      • {
      • for(j=0;j<c1;j++)
      • {
      • scanf(&quot;%d&quot;,&a[i][j]);
      • }
      • }
      • printf(&quot; Enter the elements of matrix B &quot;);
      • for(i=0;i<r2;i++)
      • {
      • for(j=0;j<c2;j++)
      • {
      • scanf(&quot; %d&quot;,&b[i][j]);
      • }
      • }
      • for(i=0;i<r1;i++)
      • {
      • for(j=0;j<c1;j++)
      • {
      • c[i][j]=0;
      • c[i][j]=c[i][j]+a[i][j]+b[i][j];
      • }
      • }
      • printf(&quot; The resultant matrix after addition of A & B is &quot;);
      • for(i=0;i<r1;i++)
      • {
      • for(j=0;j<c1;j++)
      • printf(&quot;%d &quot;,c[i][j]);
      • printf(&quot; &quot;);
      • }
      • getch();
      • }
    • Output
      • Enter the size of matrix A: 2
      • 2
      • Enter the size of matrix B: 2
      • 2
      • Enter the elements of matrix A
      • 2
      • 2
      • 2
      • 2
      • Enter the elements of matrix B
      • 3
      • 3
      • 3
      • 3
      • The resultant matrix after addition of A&B is
      • 5 5
      • 5 5
    • Matrix Multiplication
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int i,j,k,r1,r2,c1,c2;
      • int a[5][5],b[5][5],c[5][5];
      • clrscr();
      • step1:
      • printf(&quot; Enter the size of matrix A &quot;);
      • scanf(&quot;%d%d&quot;,&r1,&c1);
      • printf(&quot; Enter the size of matrix B &quot;);
      • scanf(&quot;%d%d&quot;,&r2,&c2);
      • if(c1==r2)
      • goto step2;
      • else
      • goto step1;
      • step2:
      • printf(&quot; Enter the elements of matrix A &quot;);
      • for(i=0;i<r1;i++)
      • {
      • for(j=0;j<c1;j++)
      • {
      • scanf(&quot;%d&quot;,&a[i][j]);
      • }
      • }
      • printf(&quot; Enter the elements of matrix B &quot;);
      • for(i=0;i<r2;i++)
      • {
      • for(j=0;j<c2;j++)
      • {
      • scanf(&quot; %d&quot;,&b[i][j]);
      • }
      • }
      • for(i=0;i<r1;i++)
      • {
      • for(j=0;j<c2;j++)
      • {
      • c[i][j]=0;
      • for(k=0;k<c1;k++)
      • {
      • c[i][j]=c[i][j]+a[i][k]*b[k][j];
      • }
      • }
      • }
      • for(i=0;i<r1;i++)
      • {
      • for(j=0;j<c2;j++)
      • printf(&quot;%d &quot;,c[i][j]);
      • printf(&quot; &quot;);
      • }
      • getch();
      • }
    • Output
      • Enter the size of matrix A:2
      • 2
      • Enter the size of matrix B:2
      • 2
      • Enter the elements of matrix A
      • 4
      • 4
      • 4
      • 4
      • Enter the elements of matrix B
      • 4
      • 4
      • 4
      • 4
      • The resultant matrix is
      • 32 32
      • 32 32
      • Enter the size of matrix A:2
      • 3
      • Enter the size of matrix B:3
      • 2
      • Enter the elements of matrix A
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • Enter the elements of matrix B
      • 2
      • 4
      • 6
      • 8
      • 2
      • 4
      • 20 32
      • 50 80
    • Passing array to Function
      • Here an array is transferred as parameter to a function.
      • void main() void fun(n,b[])
      • { {
      • void fun(int,int); int x,b[5];
      • int a[5],n; …………..
      • …………… ………… ..
      • fun(n,a);
      • …………… }
      • }
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • void add(int,int b[]);
      • void main()
      • {
      • int a[5],i,n;
      • clrscr();
      • printf(&quot; Enter the Number: &quot;);
      • scanf(&quot;%d&quot;,&n);
      • printf(&quot; Enter the Values: &quot;);
      • for(i=0;i<n;i++)
      • scanf(&quot;%d&quot;,&a[i]);
      • add(n,a);
      • }
      • void add(int x,int b[])
      • {
      • int sum=0,i;
      • for(i=0;i<x;i++)
      • sum=sum+b[i];
      • printf(&quot; The sum is: %d&quot;,sum);
      • }
    • Output
      • Enter the Number: 5
      • Enter the Values: 1
      • 2
      • 3
      • 4
      • 5
      • The sum is: 15
    • Array of Characters
      • In array the characters are terminated by the null (‘’) character.
      • Example: char a[]={a,b,c};
      c b a
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int i=0;
      • char a[]=&quot;abcd&quot;;
      • clrscr();
      • while(a[i]!='')
      • {
      • printf(&quot; %c&quot;,a[i]);
      • i++;
      • }
      • }
    • Output
      • a b c d
    • Multi Dimensional Array
      • Syntax
      • datatype array_name [size1][size2]….[size n]
        • datatype - type of the data.
        • array_name -name of the array.
        • size -size of the array.
      • Example:
        • int a[3][3][3];
      Col 0 Col 1 Col 2 row 0 row 1 row 2 X[0][0] X[1][0] X[2][0] X[0][1] X[1][1] X[2][1] X[0][2] X[1][2] X[2][2]
    • String Functions
      • strlen()
      • It is used to find the length of the string.
      • syntax:
      • strlen(string)
      • strcpy()
        • It is used to copy one string to another.
      • syntax:
      • strcpy(string1,string2)
      • strcat()
      • It is used to combine two strings.
      • syntax:
      • strcat(string1,string2)
      • strcmp()
      • It is used to compare two strings.
      • syntax:
      • strcmp(string1,string2)
            • Returns 0 if two strings are equal.
            • Return value <0 if s1 is less than s2.
            • Return value >0 if s1 is greater than s2.
      • strrev()
      • It used to reverse a string.
      • syntax:
      • strrev(string)
      • strlwr(), strupr()
      • It used to change the case of a string.
      • syntax:
      • strlwr(string)
      • strupr(string)
      • strncpy()
      • It used to copy ‘n’ characters of one string to another.
      • strstr()
        • It is used to determine the first occurrence of a given string in another string.
      • strncat()
        • It Appends source string to destination string upto specified length.
      • strspn()
        • It is used t find upto what length two strings are identical.
      • strncmp()
        • It is used to compare ‘n’ character of two strings.
      • strcmpi()
        • It is used to compare two strings without regarding the case.
      • strnicmp()
        • It is used to compare first ‘n’ characters of two strings without regarding the case.
      • strchr()
        • It is used to determine the first occurrence of a given character in a string.
      • strrchr()
        • It is used to determine the last occurrence of a given character in a string.
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • #include<string.h>
      • void main()
      • {
      • char a[]=&quot;college&quot;;
      • int b;
      • clrscr();
      • b=strlen(a);
      • printf(&quot; The length of the string is %d&quot;,b);
      • getch();
      • }
      • Output:
      • The length of the string is 7
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • #include<string.h>
      • void main()
      • {
      • char a[]=&quot;IT&quot;;
      • char b[]=&quot;Dept&quot;;
      • clrscr();
      • strcpy(a,b);
      • printf(&quot; The string is %s&quot;,a);
      • getch();
      • }
      • Output:
      • The string is Dept
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • #include<string.h>
      • void main()
      • {
      • char a[]=&quot;IT&quot;;
      • char b[]=&quot;Dept&quot;;
      • clrscr();
      • strcat(a,b);
      • printf(&quot; The string is %s&quot;,a);
      • getch();
      • }
      • Output:
      • The string is ITDept
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • #include<string.h>
      • void main()
      • {
      • char a[]=&quot;itdept&quot;;
      • char b[]=&quot;it&quot;;
      • int i;
      • clrscr();
      • i=strcmp(a,b);
      • if(i==0)
      • printf(&quot; strings are equal:%d&quot;,i);
      • else if(i<0)
      • printf(&quot; string1 is less than string2:%d&quot;,i);
      • else
      • printf(&quot; string1 is greater than string2:%d&quot;,i);
      • getch();
      • }
      • Output:
      • string1 is greater than string2:100
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • #include<string.h>
      • void main()
      • {
      • char a[]=&quot;itdept&quot;;
      • clrscr();
      • printf(&quot; The string is :%s&quot;,a);
      • strupr(a);
      • printf(&quot; The string after conversion to uppercase :%s&quot;,a);
      • strlwr(a);
      • printf(&quot; The string after conversion to lowercase :%s&quot;,a);
      • getch();
      • }
    • Output
      • The string is :itdept
      • The string after conversion to uppercase :ITDEPT
      • The string after conversion to lowercase :itdept
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • #include<string.h>
      • void main()
      • {
      • char a[]=&quot;Dept&quot;;
      • clrscr();
      • printf(&quot; The string is %s&quot;,strrev(a));
      • getch();
      • }
      • Output:
      • The string is tpeD
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • #include<string.h>
      • void main()
      • {
      • char a[]=&quot;itdept&quot;;
      • char b[15];
      • int i=0;
      • clrscr();
      • strncpy(b,a,2);
      • b[2]='';
      • printf(&quot; The string is :%s&quot;,b);
      • getch();
      • }
      • Output:
      • The string is :it
    • String Palindrome
      • #include<stdio.h>
      • #include<conio.h>
      • #include<string.h>
      • void main()
      • {
      • int len,i,j;
      • char str[15];
      • clrscr();
      • printf(&quot; Enter the string:&quot;);
      • scanf(&quot;%s&quot;,str);
      • len=strlen(str);
      • for(i=0,j=len-1;i<len/2;i++,j--)
      • {
      • if(str[i]!=str[j])
      • {
      • printf(&quot; The String is not a palindrome&quot;);
      • getch();
      • exit(0);
      • }
      • }
      • printf(&quot; The String is a palindrome&quot;);
      • getch();
      • }
      • Output:
      • Enter the string:abcba
      • The String is a palindrome
    • Enumerated Data Type
      • It is user defined data type.
      • The user can create their own data type and define some values to the variables.
      • Syntax:
      • enum tag_name
      • {
      • enum1;
      • enum2;
      • ……… .
      • };
    • Example
      • #include <conio.h>
      • #include <stdio.h>
      • void main()
      • {
      • enum week {sun,mon,tue,wed,thr,fri,sat};
      • clrscr();
      • printf(&quot; Monday=%d&quot;,mon);
      • printf(&quot; Saturday=%d&quot;,sat);
      • getch();
      • }
      • Output:
      • Monday=1
      • Saturday=6
    • Example
      • #include <conio.h>
      • #include <stdio.h>
      • void main()
      • {
      • enum week {sun=10,mon,tue,wed,thr,fri,sat};
      • clrscr();
      • printf(&quot; Monday=%d&quot;,mon);
      • printf(&quot; saturday=%d&quot;,sat);
      • getch();
      • }
      • Output:
      • Monday=11
      • saturday=16
    • Structure
      • A Structure is a collection of different data items, that are stored under a common name.
      • Syntax:
      • struct structure_name
      • {
      • structure element1;
      • structure element2;
      • …………………… .
      • };
      • Example:
      • struct stud
      • {
      • int sno;
      • char name[10];
      • int mark;
      • };
      • struct stud s;
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • struct stud
      • {
      • int regno;
      • char name[10];
      • int m1;
      • int m2;
      • int m3;
      • };
      • struct stud s;
      • void main()
      • {
      • float tot,avg;
      • printf(&quot; Enter the student regno,name,m1,m2,m3:&quot;); scanf(&quot;%d%s%d%d%d&quot;,&s.regno,&s.name,&s.m1,&s.m2,&s.m3);
      • tot=s.m1+s.m2+s.m3;
      • avg=tot/3;
      • printf(&quot; The student Details are:&quot;);
      • printf(&quot; %d %s %f %f&quot;,s.regno,s.name,tot,avg);
      • }
    • Output
      • Enter the student regno,name,m1,m2,m3:100
      • aaa
      • 87
      • 98
      • 78
      • The student Details are:
      • 100 aaa 263.000000 87.666664
    • Structure assignment
      • It is possible to assign one structure information to another structure of same type using simple assignment statement.
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • struct
      • {
      • int a;
      • }x,y;
      • clrscr();
      • x.a=10;
      • y=x;
      • printf(&quot;The value of y.a is%d&quot;,y.a);
      • getch();
      • }
    • Output
      • The value of y.a is10
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • struct stud
      • {
      • int regno;
      • char name[10],grade;
      • int m1,m2,m3;
      • float avg,tot;
      • } s[10];
      • void main()
      • {
      • int i,n;
      • printf(&quot; Enter the no.of students:&quot;);
      • scanf(&quot;%d&quot;,&n);
      • for(i=0;i<n;i++)
      • {
      • printf(&quot; Enter the student regno,name,m1,m2,m3:&quot;);
      • scanf(&quot;%d%s%d%d%d&quot;,&s[i].regno,&s[i].name,&s[i].m1,
      • &s[i].m2,&s[i].m3);
      • s[i].tot=s[i].m1+s[i].m2+s[i].m3;
      • s[i].avg=s[i].tot/3;
      • if(s[i].m1<35||s[i].m2<35||s[i].m3<35)
      • s[i].grade='f';
      • else
      • {
      • if(s[i].avg>=75)
      • s[i].grade='d';
      • else if(s[i].avg>=60)
      • s[i].grade='A';
      • else if(s[i].avg>=50)
      • s[i].grade='B';
      • else if(s[i].avg>=35)
      • s[i].grade='C';
      • }
      • }
      • printf(&quot; STUDENT MARK LIST &quot;);
      • printf(&quot; REGNO NAME TOTAL Avg GRADE&quot;);
      • for(i=0;i<n;i++)
      • printf(&quot; %d %s %f %f %c&quot;,s[i].regno,s[i].name,s[i].tot,s[i].avg,s[i].grade);
      • getch();
      • }
      • Enter the no.of students:2
      • Enter the student regno,name,m1,m2,m3:101
      • aaa
      • 89
      • 98
      • 78
      • Enter the student regno,name,m1,m2,m3:102
      • bbb
      • 59
      • 68
      • 76
      • STUDENT MARK LIST
      • REGNO NAME TOTAL Avg GRADE
      • 101 aaa 265.000000 88.333336 d
      • 102 bbb 203.000000 67.666664 A
    • Union
      • An Union is a collection of different data items, that are stored under a common name. Here same memory is shared by its members.
      • Syntax:
      • union union _name
      • {
      • union element1;
      • union element2;
      • …………………
      • };
      • Example:
      • union result
      • {
      • int mark;
      • float avg;
      • char grade;
      • };
      • union result s;
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • union stud
      • {
      • int a;
      • char b[2];
      • };
      • void main()
      • {
      • union stud c;
      • c.a=256;
      • printf(&quot; c.a value is%d&quot;,c.a);
      • printf(&quot; c.b[0] value is%d&quot;,c.b[0]);
      • printf(&quot; c.b[1] value is%d&quot;,c.b[1]);
      • }
      • Output:
      • c.a value is256
      • c.b[0] value is0
      • c.b[1] value is1
      • 256 = 00000010 00000000
      Higher bit Lower bit 00000000 00000010 c.a - 2 Byte c.b[0] 1 Byte c.b[0] 1 Byte c.b[0] c.b[1]
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • struct student
      • {
      • int a;
      • int b;
      • char c;
      • }s;
      • union student1
      • {
      • int a;
      • int b;
      • char c;
      • }s1;
      • void main()
      • {
      • printf(&quot; The size of struct is %d&quot;,sizeof(s));
      • printf(&quot; The size of union is %d&quot;,sizeof(s1));
      • getch();
      • }
      • Output:
      • The size of struct is 5
      • The size of union is 2
    • Structure & Union int int char 2 Byte 2Byte 1Byte 2 Byte structure int ,int, char union
    • Preprocessor
      • It is a program that processes the source program before compilation.
      • It operates under the following directives
            • File Inclusion
            • Macro substitution
            • Conditional inclusion
    • File Inclusion
      • It is used to include some file that contains functions or some definitions.
      • Syntax:
      • #include<filename> (or)
      • #include“filename”
      • Eg: #include<stdio.h>
      • #include “ex.c”
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • #include &quot;addition.txt&quot;
      • void main()
      • {
      • int a,b;
      • printf(&quot; Enter the numbers:&quot;);
      • scanf(&quot;%d%d&quot;,&a,&b);
      • printf(&quot;The Value is %d&quot;,add(a,b));
      • getch();
      • }
    • addition.txt
      • int add(int a,int b)
      • {
      • return(a+b);
      • }
    • Output
      • Enter the numbers:7
      • 4
      • The Value is 11
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • #include &quot;fact.c&quot;
      • void main()
      • {
      • int a;
      • printf(&quot; Enter the number:&quot;);
      • scanf(&quot;%d&quot;,&a);
      • printf(&quot;The factorial of %d! is %d&quot;,a,rec(a));
      • getch();
      • }
    • fact.c
      • int rec(int x)
      • {
      • int f;
      • if(x==1)
      • return(1);
      • else
      • f=x*rec(x-1);
      • return(f);
      • }
    • Output
      • Enter the number:5
      • The factorial of 5! is 120
    • Macro Substitution
      • It is used to define and use integer, string, or identifier in the source program
      • The three forms of macros are
            • Simple Macro
            • Argumented Macro
            • Nested Macro
    • Simple Macro
      • It is used to define some constants
      • Syntax
      • # define identifier string/integer
      • Eg:
        • #define pi 3.14
        • #define CITY “chennai”
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • #define pi 3.14
      • #define CITY &quot;chennai&quot;
      • void main()
      • {
      • printf(&quot;The Value is %f&quot;,2*pi);
      • printf(&quot; The Value CITY is %s&quot;,CITY);
      • getch();
      • }
      • Output:
      • The Value is 6.280000
      • The Value CITY is chennai
    • Argumented Macro
      • It is used to define some complex forms in the source program.
      • Syntax:
      • #define identifier (v1,v2,….) string/integer
      • Eg:
      • #define cube(n) (n*n*n)
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • #define cube(n) (n*n*n)
      • void main()
      • {
      • printf(&quot;The Value of 3 cube is %d&quot;,cube(3));
      • getch();
      • }
      • Output:
      • The Value of 3 cube is 27
    • Nested Macro
      • Here one macro is used by another macro.
      • Eg:
      • #define a 3
      • #define sq a*a
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • #define a 3
      • #define sq a*a
      • void main()
      • {
      • printf(&quot;The Value is %d&quot;,sq);
      • getch();
      • }
      • Output:
      • The Value is 9
    • Conditional Inclusion
      • It is used to include some conditional statements.
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • #define a 3
      • #ifdef a
      • #define c a+5
      • #endif
      • void main()
      • {
      • printf(&quot; The value C is %d&quot;,c);
      • getch();
      • }
      • Output:
      • The value C is 8
    • Pointers
      • Pointer is a variable that contains the memory address of another variable.
      • Example:
      • x=5
      • x Variable
      • 1002 Address
      5 Value
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int x=5;
      • printf(&quot; The Address of x = %u&quot;,&x);
      • printf(&quot; The Value of x = %d&quot;,x);
      • }
      • Output
      • The Address of x = 8714
      • The Value of x = 5
    • Pointer Declaration
      • Syntax
      • data-type *pointer-name;
      • data-type - Type of the data to which the pointer points.
      • pointer-name - Name of the pointer
      • Example: int *a;
    • Accessing Variable through Pointer
      • If a pointer is declared and assigned to a variable, then the variable can be accessed through the pointer.
      • Example:
      • int *a;
      • x=5;
      • a=&x;
      • Example
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int x=5;
      • int *a;
      • a=&x;
      • printf(&quot; The Value of x = %d&quot;,x);
      • printf(&quot; The Address of x = %u&quot;,&x);
      • printf(&quot; The Value of a = %d&quot;,a);
      • printf(&quot; The Value of x = %d&quot;,*a);
      • }
    • Output
      • The Value of x = 5
      • The Address of x = 8758
      • The Value of a = 8758
      • The Value of x = 5
      • Example:
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int y=10;
      • int *a;
      • a=&y;
      • printf(&quot; The Value of y = %d&quot;,y);
      • printf(&quot; The Address of y = %u&quot;,&y);
      • printf(&quot; The Value of a = %d&quot;,a);
      • printf(&quot; The Address of a = %u&quot;,&a);
      • }
    • 5001 10 8000 a y 5001 Variable Value Address
    • Output
      • The Value of y = 10
      • The Address of y = 5001
      • The Value of a = 5001
      • The Address of a = 8000
    • Null Pointer
      • A pointer is said to be null pointer if zero is assigned to the pointer.
      • Example
      • int *a,*b;
      • a=b=0;
    • Pointer to Pointer
      • Here one pointer stores the address of another pointer variable.
      • Example:
      • int x=10,*a,**b;
      • a=&x;
      • b=&a;
    • 5001 10 8000 a x 5001 Variable Value Address 8000 9000 b
      • Example
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int a=10;
      • int *b,**c;
      • b=&a;
      • c=&b;
      • printf(&quot; The Value of a = %d&quot;,a);
      • printf(&quot; The Address of a = %u&quot;,&a);
      • printf(&quot; The Value of b = %d&quot;,b);
      • printf(&quot; The Address of b = %u&quot;,&b);
      • printf(&quot; The Value of c = %d&quot;,c);
      • printf(&quot; The Address of c = %u&quot;,&c);
      • }
    • Output
      • The Value of a = 10
      • The Address of a = 5001
      • The Value of b = 5001
      • The Address of b = 8000
      • The Value of c = 8000
      • The Address of c = 9000
    • Pointers and Functions
      • Call by Value
      • Call by Reference
    • Call by value
      • Actual argument passed to the formal argument.
      • Any changes to the formal argument does not affect the actual argument.
    • Example
      • #include <stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int x,y,swap(int,int);
      • printf(&quot; Enter value of x:&quot;);
      • scanf(&quot;%d&quot;,&x);
      • printf(&quot; Enter value of y:&quot;);
      • scanf(&quot;%d&quot;,&y);
      • change(x,y);
      • printf(&quot; Values in the Main()-->x=%d,y=%d&quot;,x,y);
      • }
      • int swap(int a,int b)
      • {
      • int c;
      • c=a;
      • a=b;
      • b=c;
      • printf(&quot; Values in the Function -->x=%d,y=%d&quot;,a,b);
      • }
    • Output
      • Enter value of x:5
      • Enter value of y:6
      • Values in the Function -->x=6,y=5
      • Values in the Main()-->x=5,y=6
    •  
    • Call by reference
      • Instead of passing value, the address of the argument will be passed.
      • Any changes to the formal argument will affect the actual argument.
    • Example
      • #include <stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int x,y,change(int*,int*);
      • printf(&quot; Enter value of x:&quot;);
      • scanf(&quot;%d&quot;,&x);
      • printf(&quot; Enter value of y:&quot;);
      • scanf(&quot;%d&quot;,&y);
      • change(&x,&y);
      • printf(&quot; Values in the Main()-->x=%d,y=%d&quot;,x,y);
      • }
      • int change(int *a,int *b)
      • {
      • int c;
      • c=*a;
      • *a=*b;
      • *b=c;
      • printf(&quot; Values in the Function -->x=%d,y=%d&quot;,*a,*b);
      • }
    • Output
      • Enter value of x:5
      • Enter value of y:6
      • Values in the Function -->x=6,y=5
      • Values in the Main()-->x=6,y=5
    • Pointer to Array
      • The elements of the array can also be accessed through a pointer.
      • Example
      • int a[3]={2,3,7};
      • int *b;
      • b=a;
      • Example:
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int a[3]={2,3,7};
      • int *b;
      • b=a;
      • printf(&quot; The Value of a[0] = %d&quot;,a[0]);
      • printf(&quot; The Address of a[0] = %u&quot;,&a[0]);
      • printf(&quot; The Value of b = %d&quot;,b);
      • }
    • 8744 2 9000 b a[0] 8744 Variable Value Address
    • Output
      • The Value of a[0] = 2
      • The Address of a[0] = 8744
      • The Value of b = 8744
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int a[5]={2,3,7,9,10};
      • int i;
      • for(i=0;i<5;i++)
      • {
      • printf(&quot; The Value of a[%d] = %d&quot;,i,a[i]);
      • printf(&quot; The Address of a[%d] = %u&quot;,i,&a[i]);
      • }
      • }
    • a[0] a[1] a[2] a[3] a[4] 8724 8726 8728 8730 8732 Array Value Address 10 9 7 3 2
    • Output
      • The Value of a[0] = 2
      • The Address of a[0] = 8724
      • The Value of a[1] = 3
      • The Address of a[1] = 8726
      • The Value of a[2] = 7
      • The Address of a[2] = 8728
      • The Value of a[3] = 9
      • The Address of a[3] = 8730
      • The Value of a[4] = 10
      • The Address of a[4] = 8732
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int a[5]={1,2,3,4,5};
      • int i,sum=0;
      • int *b;
      • b=a;
      • for(i=0;i<5;i++)
      • {
      • sum=sum + *b;
      • b++; //b=b+1
      • }
      • printf(&quot; The Sum is %d&quot;,sum);
      • }
    • Output
      • The Sum is 15
    • Pointer and Structures
      • Syntax:
      • struct structure_name
      • {
      • structure element1;
      • structure element2;
      • …………………… .
      • }variable,*ptr;
      • Example:
      • struct stud
      • {
      • int sno;
      • char name[10];
      • int mark;
      • };
      • struct stud *s;
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • struct stud
      • {
      • int regno;
      • char name[10];
      • int m1;
      • int m2;
      • int m3;
      • };
      • struct stud s;
      • struct stud *t;
      • void main()
      • {
      • float tot,avg;
      • t=&s;
      • printf(&quot; Enter the student regno,name,m1,m2,m3:&quot;);
      • scanf(&quot;%d%s%d%d%d&quot;,&s.regno,&s.name,&s.m1,&s.m2,&s.m3);
      • tot=s.m1+s.m2+s.m3;
      • avg=tot/3;
      • printf(&quot; The student Details are:&quot;);
      • printf(&quot; %d %s %f %f&quot;,s.regno,s.name,tot,avg);
      • printf(&quot; %d %s %f %f&quot;,t->regno,t->name,tot,avg);
      • }
    • Output
      • Enter the student regno,name,m1,m2,m3:1
      • aaa
      • 76
      • 89
      • 76
      • The student Details are:
      • 1 aaa 241.000000 80.333336
      • 1 aaa 241.000000 80.333336
    • Command Line Argument
      • It allows the user to pass some information to the program while running the program.
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • void main(int argc,char argv[])
      • {
      • printf(&quot; The Argument is %s&quot;,argv[0]);
      • getch();
      • }
      •  
    • Output
      • C: c>a
      • The Argument is C:TCA.EXE
    • String Palindrome
      • #include<stdio.h>
      • #include<conio.h>
      • #include<string.h>
      • void main()
      • {
      • char s1[15],s2[15];
      • printf(&quot; enter the string:&quot;);
      • scanf(&quot;%s&quot;,s1);
      • strcpy(s2,s1);
      • strrev(s1);
      • if(strcmp(s1,s2)==0)
      • printf(&quot; The string is palindrome&quot;);
      • else
      • printf(&quot; The string is not a palindrome&quot;);
      • getch();
      • }
      • Output:
      • enter the string: aba
      • The string is palindrome
    • Developing a ‘C’ Program
      • The Program development life cycle is considered as a sequence of events by the programmer to develop the program.
      • The Program development life cycle contains the following phase
        • Program Design
        • Program Coding
        • Program Testing
    • Program Design
      • Analysing the problem
      • Algorithm development
      • Selection of conditional and control structure etc,.
    • Program Coding
      • Documentation
      • Statement construction
      • Input and output format etc,.
    • Program Testing
      • It is the process of executing the program with sample data
    •  
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • #define p 3.14
      • void main()
      • {
      • #ifdef p
      • printf(&quot; Pentium&quot;);
      • #else
      • printf(&quot; Celeron&quot;);
      • #endif
      • printf(&quot; the value is %f&quot;,2*p);
      • getch();
      • }
      • Output:
      • Pentium
      • the value is 6.280000
    •  
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • struct stud
      • {
      • int regno;
      • char name[10];
      • int m1;
      • int m2;
      • int m3;
      • };
      • struct stud s;
      • void main()
      • {
      • float tot,avg;
      • int i;
      • printf(&quot; Enter the student regno,name,m1,m2,m3:&quot;);
      • for(i=0;i<2;i++)
      • {
      • scanf(&quot;%d%s%d%d%d&quot;,&s.regno,&s.name,&s.m1,&s.m2,&s.m3);
      • tot=s.m1+s.m2+s.m3;
      • avg=tot/3;
      • }
      • for(i=0;i<2;i++)
      • printf(&quot;%d %s %f %f&quot;,s.regno,s.name,tot,avg);
      • }
      • Enter the student regno,name,m1,m2,m3:100
      • aaa
      • 78
      • 67
      • 98
      • 101
      • bbb
      • 80
      • 90
      • 75
      • bbb 245.000000 81.666664
      • 101bbb 245.000000 81.666664
      • #include <string.h>
      • #include <stdio.h>
      • int main(void)
      • {
      • char string[15];
      • char *ptr, c = 'r';
      • strcpy(string, &quot;This is a string&quot;);
      • ptr = strchr(string, c);
      • if (ptr)
      • printf(&quot;The character %c is at position: %d &quot;, c, ptr-string);
      • else
      • printf(&quot;The character was not found &quot;);
      • return 0;
      • }
    • Example
      • #include<stdio.h>
      • #include<conio.h>
      • #include<string.h>
      • void main()
      • {
      • char a[]=&quot;Dept&quot;;
      • int i=0;
      • clrscr();
      • while(a[i]!='')
      • {
      • printf(&quot; The character is %c&quot;,a[i]);
      • i++;
      • }
      • getch();
      • }
      • The character is D
      • The character is e
      • The character is p
      • The character is t
    •  
    • Structure
    •  
    •  
    •  
    • Lab Exercise C Programs
    • Function-with arg & return
      • #include <stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int a,b,c;
      • int add(int,int);
      • printf(&quot; Enter two number:&quot;);
      • scanf(&quot;%d%d&quot;,&a,&b);
      • c=add(a,b);
      • printf(&quot; Sum is:%d&quot;,c);
      • }
      • int add(int x,int y)
      • {
      • int z;
      • z=x+y;
      • return(z);
      • }
    • Output
      • Enter two number:6
      • 7
      • Sum is:13
    • Example
      • #include <stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int x,y,change(int*,int*);
      • printf(&quot; Enter value of x:&quot;);
      • scanf(&quot;%d&quot;,&x);
      • printf(&quot; Enter value of y:&quot;);
      • scanf(&quot;%d&quot;,&y);
      • change(&x,&y);
      • printf(&quot; Values in the Main()-->x=%d,y=%d&quot;,x,y);
      • }
      • int change(int *a,int *b)
      • {
      • int c;
      • c=*a;
      • *a=*b;
      • *b=c;
      • printf(&quot; Values in the Function -->x=%d,y=%d&quot;,*a,*b);
      • }
    • Output
      • Enter value of x:5
      • Enter value of y:6
      • Values in the Function -->x=6,y=5
      • Values in the Main()-->x=6,y=5
    • Factorial-Recursive Fn
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int a;
      • int rec(int);
      • printf(&quot; Enter the number:&quot;);
      • scanf(&quot;%d&quot;,&a);
      • printf(&quot;The factorial of %d! is %d&quot;,a,rec(a));
      • }
      • int rec(int x)
      • {
      • int f;
      • if(x==1)
      • return(1);
      • else
      • f=x*rec(x-1);
      • return(f);
      • }
      • Output:
      • Enter the number:5
      • The factorial of 5! is 120
    • Example: Working of 3!
    • Matrix Multiplication
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int i,j,k,r1,r2,c1,c2;
      • int a[5][5],b[5][5],c[5][5];
      • clrscr();
      • step1:
      • printf(&quot; Enter the size of matrix A &quot;);
      • scanf(&quot;%d%d&quot;,&r1,&c1);
      • printf(&quot; Enter the size of matrix B &quot;);
      • scanf(&quot;%d%d&quot;,&r2,&c2);
      • if(c1==r2)
      • goto step2;
      • else
      • goto step1;
      • step2:
      • printf(&quot; Enter the elements of matrix A &quot;);
      • for(i=0;i<r1;i++)
      • {
      • for(j=0;j<c1;j++)
      • {
      • scanf(&quot;%d&quot;,&a[i][j]);
      • }
      • }
      • printf(&quot; Enter the elements of matrix B &quot;);
      • for(i=0;i<r2;i++)
      • {
      • for(j=0;j<c2;j++)
      • {
      • scanf(&quot; %d&quot;,&b[i][j]);
      • }
      • }
      • for(i=0;i<r1;i++)
      • {
      • for(j=0;j<c2;j++)
      • {
      • c[i][j]=0;
      • for(k=0;k<c1;k++)
      • {
      • c[i][j]=c[i][j]+a[i][k]*b[k][j];
      • }
      • }
      • }
      • for(i=0;i<r1;i++)
      • {
      • for(j=0;j<c2;j++)
      • printf(&quot;%d &quot;,c[i][j]);
      • printf(&quot; &quot;);
      • }
      • getch();
      • }
    • Output
      • Enter the size of matrix A:2
      • 2
      • Enter the size of matrix B:2
      • 2
      • Enter the elements of matrix A
      • 4
      • 4
      • 4
      • 4
      • Enter the elements of matrix B
      • 4
      • 4
      • 4
      • 4
      • The resultant matrix is
      • 32 32
      • 32 32
    •  
    • Lab Ex:9,Finding area, circumference of circle
      • #include<stdio.h>
      • #include <conio.h>
      • void main ( )
      • {
      • int r;
      • float area,c;
      • clrscr( );
      • printf(&quot; Enter the value of r:&quot;);
      • scanf(&quot;%d&quot;,&r);
      • area=3.14*r*r;
      • c=2*3.14*r;
      • printf(&quot; The area is :%f&quot;,area);
      • printf(&quot; The circumference is :%f&quot;,c);
      • getch( );
      • }
      • Output:
      • Enter the value of r:7
      • The area is :153.860001
      • The circumference is :43.959999
    • Lab Ex:9,Conversion of Celsius to Fahrenheit
      • #include<stdio.h>
      • #include <conio.h>
      • void main ( )
      • {
      • float c,f;
      • clrscr( );
      • printf(&quot; Enter the value of c:&quot;);
      • scanf(&quot;%f&quot;,&c);
      • f=(c*1.8)+32;
      • printf(&quot; The Fahrenheit is :%f&quot;,f);
      • getch( );
      • }
      • Enter the value of c:35
      • The fahrenheit is :95.000000
    • Lab Ex:11,Arithmetic operations
      • #include<stdio.h>
      • #include<conio.h>
      • void main()
      • {
      • int a,b,c,d,e,f;
      • clrscr();
      • printf(&quot; Enter the values of A and B:&quot;);
      • scanf(&quot;%d%d&quot;,&a,&b);
      • c=a+b;
      • d=a-b;
      • e=a*b;
      • f=a/b;
      • printf(&quot; The values of A + B:%d&quot;,c);
      • printf(&quot; The values of A - B:%d&quot;,d);
      • printf(&quot; The values of A * B:%d&quot;,e);
      • printf(&quot; The values of A / B:%d&quot;,f);
      • getch();
      • }
    • Output
      • Enter the values of A and B:6
      • 3
      • The values of A + B:9
      • The values of A - B:3
      • The values of A * B:18
      • The values of A / B:2
    • Lab.Ex13,Largest among 3 nos
      • #include<stdio.h>
      • #include <conio.h>
      • void main ( )
      • {
      • int a,b,c;
      • clrscr( );
      • printf(&quot; Enter the value of a:&quot;);
      • scanf(&quot;%d&quot;,&a);
      • printf(&quot; Enter the value of b:&quot;);
      • scanf(&quot;%d&quot;,&b);
      • printf(&quot; Enter the value of c:&quot;);
      • scanf(&quot;%d&quot;,&c);
      • if((a>b)&&(a>c))
      • {
      • printf(&quot; A is Big&quot;);
      • }
      • else
      • {
      • if(b>c)
      • printf(&quot; B is Big&quot;);
      • else
      • printf(&quot; C is Big&quot;);
      • }
      • getch( );
      • }
    • Output
      • Enter the value of a:5
      • Enter the value of b:7
      • Enter the value of c:3
      • B is Big
    • String Palindrome
      • #include<stdio.h>
      • #include<conio.h>
      • #include<string.h>
      • void main()
      • {
      • int len,i,j;
      • char str[15];
      • clrscr();
      • printf(&quot; Enter the string:&quot;);
      • scanf(&quot;%s&quot;,str);
      • len=strlen(str);
      • for(i=0,j=len-1;i<len/2;i++,j--)
      • {
      • if(str[i]!=str[j])
      • {
      • printf(&quot; The String is not a palindrome&quot;);
      • getch();
      • exit(0);
      • }
      • }
      • printf(&quot; The String is a palindrome&quot;);
      • getch();
      • }
      • Output:
      • Enter the string:abcba
      • The String is a palindrome
    • Lab.Ex:14,Quadratic Equation
      • #include<stdio.h>
      • #include <conio.h>
      • #include<math.h>
      • void main ( )
      • {
      • int a,b,c,d,r1,r2;
      • clrscr( );
      • printf(&quot; Enter the value of a:&quot;);
      • scanf(&quot;%d&quot;,&a);
      • printf(&quot; Enter the value of b:&quot;);
      • scanf(&quot;%d&quot;,&b);
      • printf(&quot; Enter the value of c:&quot;);
      • scanf(&quot;%d&quot;,&c);
      • d=b*b-4*a*c;
      • if(d>=0)
      • {
      • r1=(-b+sqrt(d))/(2*a);
      • r2=(-b-sqrt(d))/(2*a);
      • printf(&quot; The roots are %d,%d&quot;,r1,r2);
      • }
      • else
      • {
      • printf(&quot; The roots are imaginary&quot;);
      • }
      • getch( );
      • }
    • Output
      • Enter the value of a:1
      • Enter the value of b:4
      • Enter the value of c:4
      • The roots are -2,-2