0% found this document useful (0 votes)
25 views

C Pograming

Uploaded by

nur20us02eud
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)
25 views

C Pograming

Uploaded by

nur20us02eud
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/ 84

AN INTRODUCTION TO

PROGRAMMING IN
C - LANGUAGE
(THEORY AND PRACTICAL]
MATHEMATICS (HONS) - 3RD SEM

Online videos are also available

Prof.Rohan Mandal
9734875427
Berhampur : Murshidabad (W.B)
1
( )

( )

() ( ) (
)( ) ( ) ( )
( )

( )

( )

( )
2

( )

( )
( )

( ) ( )
( )
3

( )

( )

( )

( )
( )
4
( ) ( )

( ) (
)
( ) (
)
( )

( )

( )

( )

( )
5
( )

() ()

( ) ( )

( ) ( )
( )
( ) ( )

( ) ( )

( )

( )

() ( )

( )
6|
( )

( )

( )
( )

( )
( )

( ) ( )
( )
( )
( )
( )

( )
7|

Start /end the program

Input / Output instruction

Processing

Decision making/
branching

Joining the two parts of a program

( ) ( )

start

Enter the value of m

S=0,t=1

s=(s+t)

YES
t=(t+1)

If t<=m
NO

Print the value of s

End
8|
( ) ( )
expressions In ‘C’ language expressions In ‘C’ language
sin(x) sin(x) sinh(x) sinh(x)
cos(x) cos(x) sinh-1(x) asinh(x)
tan(x) tan(x) loge(x) log(x)
cot(x) cot(x) log10(x) log10(x)
sin-1(x) asin(x) log10(x) ( ) ( )
= ( )
cos-1(x) acos(x) ex exp(x)
tan-1(x) atan(x) |x| fabs(x)
Square root of x sqrt(x) xy pow(x,y)

() ( )

expressions In ‘C’ language


( ) ( ) ( )

√ ( ) ( ( )) ( )

( ) ( ( ( )) )
( )
( ) ( ) ( ( ) ( ))

( )

( )

( )
( )
9|
0 1 0 0 0 1 1 0

( ) ( )
( ) ( )
( )

()
*
( )
+

( )

( )

() ()

( )

( )

( ) () ()* +

( ) ( ) ()

( ) (* ) ()
( +)
( )
10 |
()
*
()
( )
+

( )
( )
() ()

( ) ()

( )

( ) () ( )

( )

( )
( ) ( ) ( )
( ) ( )
( )
( )
( )
( )
( )

Data Type

Fundamental User Defined Derined Empty


11 |

Fundamental data type

Integer Character Float Double

( )

( )
( )
( )

( ) ( )

16th bit …. …. …. …. …. … 9th bit 8th bit ….. …. … …. … 2nd bit 1st bit

( )

( )

0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1

( )

()
*

( )
12 |

( )
+

( )

( )
( )

() ()
( )
( )
( ).

( )

( )

( )

()
*

( )
( )
+
13 |

( )

()
*

( )
+

(
)

( )

()
*

()

( )

( )
()
}
14 |

( )

( )

,-

( )

( ) ( )
( )

( )
( )

()
*

()

( )
( )
+

The value of the first variable= 293.398547


The value of the second variable= 2.000000
15 |
( )

( )
( )

( )
( ) ( )

( )

()
()

( )
16 |
( )

Conversion Character Explain

( )

( )

()
*

()
( )
( )
( )
()
}

( )

( )
17 |

( )

()
*

()
( )
( )
+

( )

()
*

( )
( )

( )
+

( )

()
18 |
*

()
( )
+

( )

( )

( )
*

Condition ?
19 |
( )

()
*

( )
( )
( )
( )
( )
( )
()
+

( )

( )

( )
( )

If a>=60

( ) ( )
Print- You are a senior memberer

If a<60

Print- You are not a senior memberer


20 |
( )

( )
{
( )
{

}
}

()
*
( )
( () )
*
( () )
*
( )
+
+
+
21 |

()
*

()
( ( ) ( ) )
( )
( )
*
( )
*
( )
+
+
+
( ) ( )

𝐈𝐟 𝐦𝐦 𝟖𝟎

𝐈𝐟 𝐭𝐦 𝟒𝟎𝟎

Print- 𝐲𝐨𝐮 𝐚𝐫𝐞 𝐞𝐥𝐢𝐠𝐢𝐛𝐥𝐞 𝐟𝐨𝐫 𝐌𝐚𝐭𝐡𝐞𝐦𝐚𝐭𝐢𝐜𝐬 𝐇𝐨𝐧𝐬


22 |
( )

( )
*

𝐈𝐟 𝐜𝐨𝐧𝐝𝐢𝐭𝐢𝐨𝐧 ?

True Block False Block

Next Block
23 |
( )( )

()
*

( )
( )
( )
( )

( )
()
+

( )

( )
*

+
( )
*

+
( )
*

+
24 |

( )

( )

( )

()
*

, -
()
( )
( )
( )
( )
( )
( )
( )
( )

( )
( )
()
+

( )
, -
( )
25 |
( )

( )
* ( )

( )

()
*

( )
( )
( )
*
26 |
( )

( )

( )

( )

+
()
+
( )

( )

( )
27 |
( )

………………………………………….. ……………………………………………………………
……………………………………………. …………………………………………………………

…………………
……………….. …………………

………………….

……………………………………..
……………………………………………

( )

( )

( )

( )

( )

( )
( )

() ( ) ( ) ( )
28 |
………………………………
( )
*

}
…………………………………
( )

()
*

( )
( )
()
+

/* first execution */
/* second execution */
/* third execution */
/* forth execution */
(
)
( )

( )

( )

( )

( )
29 |

()
*

( )
( )
*
( )

( )
+
()
}

( )

( )

( )

( )
30 |

()
*

( )
*
( )
*
( )
( )
+
( )
+
()
+

…………………………………..
………………………………..
( )
*
( )
+
…………………………………
31 |
( )

( )
*

( )

()
*

( )
*
( )

+
()
}

( )
( )
32 |

( )

()
*

( )
*
( )

+
()
}

( )

+
( )
33 |
( )

()
*

*
( )

+
( )
()
}

( ) ( )

( )

()
*

*
( )

+
( )
()
+
34 |
( )

( ) ( )

( )
( )

, -
( )

, -

, - , - , - , - , -

x[0] x[1] x[2] x[3] x[4]

( )
( )
( ) , -
( )

( )

() ( ) ( )
35 |
()

, - * +
, - , -
, - , -

,- * + ,- * +
,-

( ) (
) , - * + , - , -
, - , - , - * + , -
, - , - , -

, - * +
( )

()
*

, -
()
( )
( )
( )
( )
*
( , -)
+
36 |
( )
*
( )
*
( ,- , -)
*
,-
,- , -
, -
+

+
+
( )
( )
*
( , -)
+
+

( )

( )

, -, -
37 |
, -, -

, -, - , -, -
, -, - , -, -
, -, - , -, -

, -, -

, -, - * +
, -, - , -, - , -, - , -, -
, -, - , -, -
, -, - {* +* +* +}

, -, - * + , -, -

, -, - {* + * + * +}

()
*

, -, -
()
( )
( )
*
( )
*
38 |
( , - )
( , -, -)
+
+
( )
( )
*
( )
*
( , -, -)
+
( )
+

( )
*
( )
*
, -, -
+
+
( )
()
+

, -
, -
, -
, -
, -
, -
, -
, -
, -
39 |
( )

() ( )

()

( ) ( )
( ) ( )
( )
( )

( )

( )
40 |

Operators

Mathematical assignment Logical Relational Conditional Bitwise Special


(OR arithmetic)

Binary Unary (OR increment and decrement)


( )

( )

( )
( )

( )
To obtain floating value of we have to write ( )
Similarly .

( ) ( )
41 |

( )
( )

()

( )

( )

( )
( )

( )
42 |

( )

(( ) ( ))

( ) ( )
( ) ( )

( )

( )
43 |
( )

()

( )

( )

( ) ( )( )

( ) ⁄

( )

( )
()
( )
44 |

()
, -

()
( ( ) ( ) ( ) ( ))
()
+

( )

( )

|
^

( )
45 |
( )

()
( )
() ( )

()

( )
( ) ()

()
( )

( )

( )
( )

( )

( )
*

( )
+
46 |

()
*

( )

+
( )
*

( )
+

( )
*
( )
+
( )

( )

( )
47 |

( )
( )

( )

( ) ( ) ( ) ( ( ))
( )

()
*

( )⁄( ( ) ( ))
( )
+
( )
*

( )

( )
+
( )

( )
48 |

()
( )
()
( )
( )
( ( ))
()
+
( )
*
( )
( )

( ( ))
+

( )

( )
( )

( ) ( )

( )
( )
49 |

( )
( )
( )

( )

* +

( )

()
*
50 |
51
( )

( ) ( ) ( ) ( )

( )

( )

( )
( )
( )

( )
(
)

( )

2 75
2 37 1
2 18 1
2 9 0
2 4 1
2 2 0
1 0

( ) ( )
52

( )

( )

( ) ( )

( ) ( )

( ) ( )
( )
( )
( )

( )

8 1093
8 136 5
8 17 0
2 1

( ) ( )
53

( ) ( )
( ) ( )
( )
( ) ( )
( )

Binary-number Decimal-number Octal-number

( )

( )

16 23719
16 1482 7
16 92 A
5 C

( ) ( )

( ) ( )
( ) ( ) ( )
( )
( ) ( )
( ) ( )
54

Hexadecimal number

Decimal number

Binary Octal
number number
( )

( )

sum carry
0 + 0 = 0 0
1 + 0 = 1 0
0 + 1 = 1 0
1 + 1 = 0 1

() ( ) ( ) ( ) ( )
First problem :
1 1 0 1 1 . 0 1 0 0
+ 1 0 1 .1 1 0 1

1 0 0 0 0 1 .0 0 0 1

( )
Second problem :
1 0 0 1 1
+1 0 0 1 0 1
1 1 1 0 0 0
( )
55
( )
( )
( ) ( )
( )

( )

() ( ) ( )
( ) ( )
( )

0.1 0 1 1 0 0
0.1 0 1 1 0 0
1 0.0 1 1 0 0 0
Carry Sum
( )
( ) ( )

( ) ( ) ( )
( ) ( )
( )

1 0 1 0 0.0 1
0 0 1 0 0.0 1
0 1 1 0 0 0.1 0
Carry Sum

( )
( )
( )

( )
(
)
56
() ( ) ( )
( ) ( )
( ) ( )

1 0 1 0 0 . 0 1
+ + 1 0 0 . 1 0
0 1 1 0 0 0 . 1 1

Carry sum

( ) ( )
( )
( ) ( ) ( )
( ) ( )
( ) ( )

0 .1 0 1 1 0 0
+ 0.1 0 1 1 0 1
1 0 .0 1 1 0 0 1

Carry sum

( )

( )

( )

() ( ) ( ) -
(+2=3) (+2=2)

1 1 1 0 1 1 0
1 0(+1=1) 1(+1=2) 1 1 0 0
0 0 1 1 0 1 0
( )
57
( ) ( )

( ) ( ) ( ) -

1 1 0 0 1 1 . 0 0
1 0 0 1 0 . 1 1
1 0 0 0 0 0 . 0 1
( )

( )

() ( ) ( )
1 1 0 1 0
× 1 0 1
1 1 0 1 0
0 0 0 0 0 ×
1 1 0 1 0 ×
1 0 0 0 0 0 1 0

( )
( ) ( ) ( )
1 1 0 1
1 0 1 1
1 1 0 1
1 1 0 1 ×
0 0 0 0 ×
1 1 0 1 ×
1 0 0 0 1 1 1 1
( )
( )
()

101 ) 1 1 1 1 ( 11
1 0 1
1 0 1
1 0 1
58

( ) .
101 ) 1 1 1 0 1 1 ( 1011.11001
1 0 1
1 0 0 1
1 0 1
1 0 0 1
1 0 1
1 0 0 0
1 0 1
1 1 0
1 0 1
1 0 0 0
1 0 1
1 1 (stop)

( )

( )

( )

( )

( )

( )

( )
59
( )
/*Sum of n- natural numbers : Dated : */
#include<math.h>
#include<conio.h>
#include<stdio.h>
void main()
{
int i,n,sum ;
printf(“\n\n Enter the value of ‘n’\n\n”);
scanf(“%d”,&n);
sum=0;
for(i=1; i<=n ; i++)
{
sum=sum+i ;
}
printf(“----------------------------------------------------“);
printf(“\n The sum of %d natural number is=%d”,n,sum);
printf(“\n-------------------------------------------------“);
}

Enter the value of ‘n’

10
----------------------------------------------------
The sum of 10 natural number is=55
-------------------------------------------------
( )
/*Sum of m-even natural numbers : Dated : */
#include<math.h>
#include<conio.h>
#include<stdio.h>
void main()
{
int i,m,sum;
printf(“\n\n Enter the value of ‘n’\n”);
scanf(“%d”,&m);
sum=0;
for(i=2; i<=m; i=i+2)
{
60
sum=sum+i ;
}
printf(“----------------------------------------------------“);
printf(“\n The sum of %d even-natural number is = %d”,m,sum);
printf(“\n-------------------------------------------------“);
}

Enter the value of ‘n’


11
----------------------------------------------------
The sum of 11 even-natural number is = 30
-------------------------------------------------

( )

()
*

()
( )
( )

( )
⁄( )
( )
()
+
61
( )

/*Arrange the number in descending order : Dated : */


#include<math.h>
#include<conio.h>
#include<stdio.h>
main()
{
int i,n,j;
float a,b[100];
clrscr();
printf(“\nEnter how many values are to be taken \n”);
scanf(“%d”,&n);
printf(“\n Enter the values\n”);
for(i=1;i<=n;i++)
{
scanf(“%f”,&b[i]);
}
for(i=1; i<=n ; i++)
{
for(j=i+1 ; j<=n ; j++)
{
if( b[i] < b[j] )
{
a=b[i]; inner loop outer loop
b[i]=b[j ];
b[j]=a;
}
}
}
Printf(“\n The descending order of the giver numbers is : \n”);
for(i=1;i<=n;i++)
{
printff(“%4.2f \t \t”,b[i]);
}
}
62

Enter how many values are to be taken


6
Enter the values
2
5
1234
643
567.234
123.45
The descending order of the giver numbers is :
1234.000000 643.000000 567.234000 123.450000 5.000000 2.000000
( ) ( )
/* Bisection Method : Dated : */

( )
*
( ( ) ( )) Function declaration
+
()
*

()
( ( ) )
( )
( ( ) ( ) * ( ) ( )+⁄ ,* ( ) ( )+⁄ - )

( ( ) ) /* Error level is taken as 0.000001 */


*
( )⁄
(( ) ( ) )

( ( )⁄ (( )⁄ ))
63

( )
()
+

( )

( ) ( ) * ( ) ( )+/2 ,* ( ) ( )+/2]

0.000000 0.500000 0.250000 0.294410


0.250000 0.500000 0.375000 0.010099
0.250000 0.375000 0.312500 0.137084
……….. ………….. …………. ……………..
……….. ………….. …………. ……………..
……….. ………….. …………. ……………..
0.370558 0.370560 0.370559 0.000001
0.370558 0.370559 0.370558 0.000001

( )
/*Newton Raphson Method : Dated : */

( )
*
( ( ) ) Function
+
( )
*
( ( ) ) Derivative of function
+
()
*
64
()
( )
( )
( ( ) ( ) ( ) )

( ) ( )⁄( ) ( )
( )
( )
( ( ) )
*

( )
()
+

( ) ( ) ( )

1.000000 0.333333 1.333333


1.333333 0.097525 1.235808
1.235808 0.014749 1.221059
1.221059 0.000315 1.220744
1.220744 0.000000 1.220744

( ) ( )
/* Regula Falsi Method : Dated : */

( )
*
( ( ) )
+
65
()
*

()
( ( ) )
( )
( ( ) ( ) ( ) , ( )- )

( ( ) ) /* Error level is taken as 0.000001 */


*
( )( ( ) ( ))⁄( )( ( ) ( ))
(( ) ( ) )

( ( ))

( )
()
+

( )

𝐒𝐨𝐥𝐯𝐞 𝐭𝐡𝐞 𝐬𝐲𝐬𝐭𝐞𝐦 𝐨𝐟 𝐥𝐢𝐧𝐞𝐫𝐚


𝐞𝐪𝐮𝐚𝐭𝐢𝐨𝐧𝐬 𝐛𝐲 𝐆𝐚𝐮𝐬𝐬 𝐞𝐥𝐢𝐦𝐢𝐧𝐚𝐭𝐢𝐨𝐧
𝐱 𝐲 𝐳 𝟎 𝟐𝐱 𝟐𝟗𝐲 𝟑𝐳 𝟏
()
𝟏𝟎𝐱 𝟐𝟎𝐲 𝟐𝟎𝐳 𝟑𝟎
*

, -, - , - , -
()
( )
66
( )
( )
( )
( , -)
( )
( )
*
( )
( , -, -)
+
( )
*
( )
*
( )
*
, -, - , -, - ( , -, - , -, -) , -, -
+
,- ,- ( , -, - , -, -) , -
+
+
, - , - , -, -
( )
( , - , -)
( )
*

( )
,- ,- ( , -, - , -)
,- , - , -, -
( , - , -)
+
()
+
67

, -
, -
, -
( )

( )
*
(( ) )
+
( )
*
(( ) )
68
+
( )
*
(( ) )
+
()
*
()

( )
( )

( )
( )
( )
( )
(( ( ) ) ( ( ) ) ( ( )
))
( )

+
()
+
69

( )

( )
*
(( ) )
+
( )
*
(( ) )
+
( )
*
(( ) )
+
()
*
()

( )
( )
70

( )
( )
( )
( )
(( ( ) ) ( ( ) ) ( ( )
))
( )

+
()
+

( ) ( )

( )

/* Lagrange’s interpolation formula : Dated : */

()
*

, - , - , -
()
( )
( )
( )
71
( )
*
( , - , - )
( ,- ,-)
}
( )
( )
( )
( )
( , -)
( )
( )
*
,- ( , -)
( )
*
( )
,- ,- ( ,- , -)
+
+
( )
( ) , - ⁄( ) ,-
( ( ) )
()
+

, - , -

, - , -
72

, - , -

, - , -

, - , -

( )
73
( ) ( )

( )

/*Newton’s divided difference : Dated : */

()
*
()

, - , - , - , - , - , -

()
( )
( )
( )
( )
*
( , - , - )
( ,- ,-)
}
( )
( )
( )
,- ( ,- , -) ( , - , -)
( )
,- ( ,- , -) ( , - , -)
( )
,- ( ,- , -) ( , - , -)
( )
,- ( ,- , -) ( , - , -)
74
, - ( , -) , - ( , -) ( , -) , -
( , -) ( , -) ( , -) , -
( , -) ( , -) ( , -) ( , -) , -

( ( ) )
()
+

, - , -

, - , -

, - , -

, - , -

, - , -

( )
75

( ) ∫

/*Trapezoidal Rule : Dated : */

( )
*
( ( ( )))
}
()
*

()
( ( ) ( ) ( ) )
( )
( )( )⁄( )
( ( ) ( ) )
( )
( ( ))
( )
*

( )
( ( ))
+
( ( ))
( )
( ( ) ( ( ) ( ) ))
()
+
76

( ) ( ) ( )

( ) ( )

( ) ∫

/*Simpson’s 1/3 Rule : Dated : */

( )
*
( ( ( )))
}
()
*

()
( ( ) ( ) ( ) )
77
( )
( )( )⁄( )
( ( ) ( ) )
( )
( ( ))
( )
*

( )
( )

( )
( ( ))
+
( ( ))
( )
( ( ) ( ( ) ( ) ))
()
+

( ) ( ) ( )

( ) ( )
78
( ) ∫

/*Weddle’s Rule : Dated : */

( )
*
( ( ))
}
()
*

()
( ( ) ( ) ( ) )
( )
( )( )⁄( )

( )
*
( ) ( ) ( ) ( ) ( )
( ) ( )

+
( ( ) )
()
+

( ) ( ) ( )
79
( )

/* Euler’s Method : Dated : */

( )
*
(( )( ) ⁄( )( ))
}
()
*

()
( )
( )
( )
( )
( )
( )
*
( )

( )
+
( )
( ( ) )
()
+
80

( )
( )

( )

/*Runge-Kutta Method : Dated : */


#include<math.h>
#include<conio.h>
#include<stdio.h>
( )
*
( )
+
()
*

()
( )
( )
( )
( )
( )
81
( )
*
( )
( ⁄ )
( ⁄ )
( )
( )

( )
+
( )
+

( ) ( )

( )
82
()
*

, -, - , - , -
()
( )
( )
( )
( )
( , -)
( )
( )
*
( )
*
( , -, -)
+
+

( )
*
,-
( )
,- ,- , -, - ,-
+

( )
*
( ,- )
,-
+
( )
,- ,-
83
( ( ) )

( )
()
+

You might also like