@MD_ItteshamItte/

User Defined Input Function

C

No description

fork
loading
Files
  • main.c
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
  
/*1. WHAT IS C FUNCTION?
A large C program is divided into basic building blocks called C function. C function contains set of instructions enclosed by “{  }” which performs specific operation in a C program. Actually, Collection of these functions creates a C program.*/

/*2. USES OF C FUNCTIONS:
C functions are used to avoid rewriting same logic/code again and again in a program.

There is no limit in calling C functions to make use of same functionality wherever required.

We can call functions any number of times in a program and from any place in a program.

A large C program can easily be tracked when it is divided into functions.

The core concept of C functions are, re-usability, dividing a big task into small pieces to achieve the functionality and to improve understandability of very large C programs.*/

/*3. C FUNCTION DECLARATION, FUNCTION CALL AND FUNCTION DEFINITION:

There are 3 aspects in each C function. They are,

C Functions aspect ---------------------------------------------- Syntax

1) Function declaration or prototype  ---- This informs compiler about the function name, 
                                          function parameters and  return value's data type.

2) Function definition ---------------      This contains all the statements to be executed.

3) Function call -------------------       This calls the actual function


function declaration	-----------      return_type function_name (argument list);

function definition ----------------  function definition	Return_type function_name (arguments list)
                                      { Body of function; }

function call	--------------------     function_name (arguments list);

SIMPLE EXAMPLE PROGRAM FOR C FUNCTION:
As you know, functions should be declared and defined before calling in a C program.
In the below program, function “square” is called from main function.
The value of “m” is passed as argument to the function “square”. This value is multiplied by itself in this function and multiplied value “p” is returned to main function from function “square”.*/

/*#include<stdio.h>
// function prototype, also called function declaration
float square ( float z );                               
// main function, program starts from here

int main( )               
{
    float k, g ;
    printf ( "\nEnter some number for finding square \n");
    scanf ( "%f", &k ) ;
    // function call
    n = square ( g ) ;                      
    printf ( "\nSquare of the given number %f is %f",k,g );
}

float square ( float z )   // function definition
{
    float b ;
    b = z * z ;
    return ( b ) ;
}

COMPILE & RUN
OUTPUT:
Enter some number for finding square
15
Square of the given number 15.000000 is 225.00000*/

/*4. HOW TO CALL C FUNCTIONS IN A PROGRAM?

There are two ways that a C function can be called from a program. They are,
Call by value
Call by reference*/

/*1. CALL BY VALUE:
In call by value method, the value of the variable is passed to the function as parameter.
The value of the actual parameter can not be modified by formal parameter.
Different Memory is allocated for both actual and formal parameters. Because, value of actual parameter is copied to formal parameter.

Note:
Actual parameter – This is the argument which is used in function call.
Formal parameter – This is the argument which is used in function definition
EXAMPLE PROGRAM FOR C FUNCTION (USING CALL BY VALUE):
In this program, the values of the variables “m” and “n” are passed to the function “swap”.
These values are copied to formal parameters “a” and “b” in swap function and used.*/


/*#include<stdio.h>
// function prototype, also called function declaration
void swap(int a, int b);          
 
int main()
{
    int m = 123, n = 146;
    // calling swap function by value
    printf(" values before swap  m = %d \nand n = %d", m, n);
    swap(m, n);                         
}
 
void swap(int a, int b)
{ 
    int tmp;
    tmp = a;
    a = b;
    b = tmp;
    printf(" \nvalues after swap m = %d\n and n = %d", a, b);
}

COMPILE & RUN
OUTPUT:
values before swap m = 123
and n = 146
values after swap m = 146
and n = 123*/

/*2. CALL BY REFERENCE:
In call by reference method, the address of the variable is passed to the function as parameter.
The value of the actual parameter can be modified by formal parameter.
Same memory is used for both actual and formal parameters since only address is used by both parameters.
EXAMPLE PROGRAM FOR C FUNCTION (USING CALL BY REFERENCE):
In this program, the address of the variables “m” and “n” are passed to the function “swap”.
These values are not copied to formal parameters “a” and “b” in swap function.
Because, they are just holding the address of those variables.
This address is used to access and change the values of the variables.*/




/*#include<stdio.h>
// function prototype, also called function declaration
void swap(int *c, int *d); 
 
int main()
{
    int m = 105, n = 315;
    //  calling swap function by reference
    printf("values before swap m = %d \n and n = %d",m,n);
    swap(&m, &n);         
}
 
void swap(int *c, int *d)
{
    int tmp;
    tmp = *c;
    *c = *d;
    *d = tmp;
    printf("\n values after swap a = %d \nand b = %d", *c, *d);
}
COMPILE & RUN
OUTPUT:
values before swap m = 105
and n = 315
values after swap a = 315
and b = 105*/

/*C – function arguments and return values
C – Argument, return value
    
All C functions can be called either with arguments or without arguments in a C program. These functions may or may not return values to the calling function. Simple examples of C programs for 4 differnt scenerios of functions.

1) C function with arguments (parameters) and with return value.
2) C function with arguments (parameters) and without return value.
3) C function without arguments (parameters) and without return value.
4) C function without arguments (parameters) and with return value.
5) C functions aspects*/

//syntax//
/*1. With arguments and ------------  with return values	
function declaration:
int function ( int );function call: function ( a );
function definition:       
int function( int a )
{
statements;
return a;
}*/

/*2. With arguments and ------------- without return values	function declaration:
void function ( int );function call: function( a );
function definition:
void function( int a )
{
statements;
}*/

/*3. Without arguments and --------- without return values	function declaration:
void function();function call: function();
function definition:
void function()
{
statements;
}*/

/*4. Without arguments and  ----------- with return values	function declaration:
int function ( );function call: function ( );
function definition:
int function( )
{
statements;
return a;
}*/

/*NOTE:
If the return data type of a function is “void”, then, it can’t return any values to the calling function.
If the return data type of the function is other than void such as “int, float, double etc”, then, it can return values to the calling function.

1. EXAMPLE PROGRAM FOR WITH ARGUMENTS & WITH RETURN VALUE:
In this program, integer, array and string are passed as arguments to the function. The return type of this function is “int” and value of the variable “a” is returned from the function. The values for array and string are modified inside the function itself.*/

/*#include <stdio.h>
#include <string.h>

int function(int, int[], char[]);
 
int main()
{
      int i, a = 37;
      int arr[7] = {11,22,33,44,55,66,77};  
      char str[45] = "\"Faiaz Tutoring INC\"";
 
      printf("\n values of a are shown below\n");  
      printf("value of a is %d\n",a);  
 
      for (i=0;i<7;i++)
      {
         // Accessing each variable
         printf("value of arr[%d] is %d\n",i,arr[i]);  
      }
      printf("name of str is %s\n",str);

      printf("\n Notice how the values of aand arr changes after adjustment\n"); 

      a = function(a, &arr[0], &str[0]);
      printf("value of a is %d\n",a);  

      for (i=0;i<7;i++)
      {
         // Accessing each variable
         printf("value of arr[%d] is %d\n",i,arr[i]);  
      }
      printf("name of str is %s\n",str); 
      return 0;
}
 
int function(int a, int *arr, char *str)
{
    int i;
 
    a = a+35;
    arr[0] = arr[0]+15;
    arr[1] = arr[1]+25;
    arr[2] = arr[2]+35;
    arr[3] = arr[3]+45;
    arr[4] = arr[4]+55;
    arr[5] = arr[5]+65;
    arr[6] = arr[6]+75;

    strcpy(str,"\"Faiaz Tutoring INC is Excellent\"");
 
    return a;
 
}*/
/*Lets RUN the program 
OUTPUT:
***values before modification***
value of a is 37
value of arr[0] is 11
value of arr[1] is 22
value of arr[2] is 33
value of arr[3] is 44
value of arr[4] is 55
value of arr[5] is 66
value of arr[6] is 77

name of str is Faiaz Tutoring INC
Notice how the values of a change after adjustment

value of a is 72
value of arr[0] is 26
value of arr[1] is 47
value of arr[2] is 68
value of arr[3] is 89
value of arr[4] is 110
value of arr[5] is 131
value of arr[6] is 152


name of str is Faiaz Tutoring INC was Excellent
works*/

/*2. EXAMPLE PROGRAM FOR WITH ARGUMENTS & WITHOUT RETURN VALUE:
In this program, integer, array and string are passed as arguments to the function. The return type of this function is “void” and no values can be returned from the function. All the values of integer, array and string are manipulated and displayed inside the function itself.


 

#include<stdio.h>

void function(int, int[], char[]);
 
int main()
{
      int a = 40;
      int arr[7] = {15,25,35,45,55,65,75};  
      char str[45] = "\"Faiaz Tutoring INC\"";
 
      function(a, &arr[0], &str[0]);
      return 0;
}
 
void function(int a, int *arr, char *str)
{
    int i;
    printf("value of a is %d\n\n",a);  
    for (i=0;i<5;i++)
      {
         // Accessing each variable
         printf("value of arr[%d] is %d\n",i,arr[i]);  
      }
    printf("\nvalue of str is %s\n",str);  
}
COMPILE & RUN
OUTPUT:
value of a is 40
 
value of arr[0] is 15
value of arr[1] is 25
value of arr[2] is 35
value of arr[3] is 45
value of arr[4] is 55
 
value of str is “Faiaz Tutoring INC”*/

/*3. EXAMPLE PROGRAM FOR WITHOUT ARGUMENTS & WITHOUT RETURN VALUE:
In this program, no values are passed to the function “test” and no values are returned from this function to main function.



#include<stdio.h>
void test();          
 
int main()
{
    test();                         
    return 0;
}
 
void test()  
{ 
    int a = 60, b = 90;   
    printf("\nvalues : a = %d and b = %d", a, b);
}
COMPILE & RUN
OUTPUT:
values : a = 60 and b = 90

4. EXAMPLE PROGRAM FOR WITHOUT ARGUMENTS & WITH RETURN VALUE:
In this program, no arguments are passed to the function “sum”. But, values are returned from this function to main function. Values of the variable a and b are summed up in the function “sum” and the sum of these value is returned to the main function.

#include<stdio.h>
 
int sum();          
 
int main()
{
    int addition;
    addition = sum();                  
    printf("\nSum of two given values = %d", addition);
    return 0;
}
 
int sum()  
{ 
    int a = 50, b = 80, sum;   
    sum = a + b;
    return sum;       
}
COMPILE & RUN
OUTPUT:
Sum of two given values = 130

DO YOU KNOW HOW MANY VALUES CAN BE RETURN FROM C FUNCTIONS?
Always, Only one value can be returned from a function.
If you try to return more than one values from a function, only one value will be returned that appears at the right most place of the return statement.
For example, if you use “return a,b,c” in your function, value for c only will be returned and values a, b won’t be returned to the program.
In case, if you want to return more than one values, pointers can be used to directly change the values in address instead of returning those values to the function.

C – Summary of C functions

As you know, C functions are basic building blocks in every C program. We have given key points those to be kept in mind for using existing C library functions and writing our own functions in a C program efficiently.

KEY POINTS TO REMEMBER WHILE WRITING FUNCTIONS IN C LANGUAGE:
1) All C programs contain main() function which is mandatory.
2) main() function is the function from where every C program is started to execute.
3) Name of the function is unique in a C program.
4) C Functions can be invoked from anywhere within a C program.
5) There can any number of functions be created in a program. There is no limit on this.
6) There is no limit in calling C functions in a program.
7) All functions are called in sequence manner specified in main() function.

One function can be called within another function.
C functions can be called with or without arguments/parameters. These arguments are nothing but inputs to the functions.

C functions may or may not return values to calling functions. These values are nothing but output of the functions.
When a function completes its task, program control is returned to the function from where it is called.
There can be functions within functions.
Before calling and defining a function, we have to declare function prototype in order to inform the compiler about the function name, function parameters and return value type.
C function can return only one value to the calling function.
When return data type of a function is “void”, then, it won’t return any values
When return data type of a function is other than void such as “int, float, double”, it returns value to the calling function.
main() program comes to an end when there is no functions or commands to execute.

There are 2 types of functions in C. They are, 1. Library functions 2. User defined functions
There are many inbuilt C functions which are offered by C compiler. You can check list of all C functions and simple example programs with outputs below.


 
1. C – Arithmetic functions

2

C – Library functions

Library functions in C language are inbuilt functions which are grouped together and placed in a common place called library.
Each library function in C performs specific operation.
We can make use of these library functions to get the pre-defined output instead of writing our own code to get those outputs.
These library functions are created by the persons who designed and created C compilers.
All C standard library functions are declared in many header files which are saved as file_name.h.
Actually, function declaration, definition for macros are given in all header files.
We are including these header files in our C program using “#include<file_name.h>” command to make use of the functions those are declared in the header files.

When we include header files in our C program using “#include<filename.h>” command, all C code of the header files are included in C program. Then, this C program is compiled by compiler and executed.
Please check the below links for actual C source code for the respective C header files.


C – math.h library functions

All C inbuilt functions which are declared in math.h header file are given below. 
 
LIST OF INBUILT C FUNCTIONS IN MATH.H FILE:
“math.h” header file supports all the mathematical related functions in C language. All the arithmetic functions used in C language are given below.
Click on each function name below for detail description and example programs.

Function --------------- Description

abs ( )	This function returns the absolute value of an integer. The absolute value of a number is always positive. Only integer values are supported in C.
C – abs() function
PREV     NEXT
abs( ) function in C returns the absolute value of an integer. The absolute value of a number is always positive. Only integer values are supported in C.
“stdlib.h” header file supports abs( ) function in C language. Syntax for abs( ) function in C is given below.
int abs ( int n );

EXAMPLE PROGRAM FOR ABS( ) FUNCTION IN C:


#include <stdio.h>
#include <stdlib.h>
int main()
{
   int m = abs(200);     // m is assigned to 200
   int n = abs(-400);    // n is assigned to -400
 
   printf("Absolute value of m = %d\n", m);
   printf("Absolute value of n = %d \n",n);
   return 0;
}
COMPILE & RUN
OUTPUT:
Absolute value of m = 200
Absolute value of n = 400
 
floor ( )	This function returns the nearest integer which is less than or equal to the argument passed to this function.
C – floor() function
PREV     NEXT
floor( ) function in C returns the nearest integer value which is less than or equal to the floating point argument passed to this function.
”math.h” header file supports floor( ) function in C language. Syntax for floor( ) function in C is given below.
double floor ( double x );
EXAMPLE PROGRAM FOR FLOOR( ) FUNCTION IN C:

#include <stdio.h>
#include <math.h>
 int main()
{
       float i=5.1, j=5.9, k=-5.4, l=-6.9;
       printf("floor of  %f is  %f\n", i, floor(i));
       printf("floor of  %f is  %f\n", j, floor(j));
       printf("floor of  %f is  %f\n", k, floor(k));
       printf("floor of  %f is  %f\n", l, floor(l));
       return 0;
}
COMPILE & RUN
OUTPUT:
floor of 5.100000 is 5.000000
floor of 5.900000 is 5.000000
floor of -5.400000 is -6.000000
floor of -6.900000 is -7.000000

round ( )	This function returns the nearest integer value of the float/double/long double argument passed to this function. If decimal value is from “.1 to .5”, it returns integer value less than the argument. If decimal value is from “.6 to .9”, it returns the integer value greater than the argument.

 C round() function

round( ) function in C returns the nearest integer value of the float/double/long double argument passed to this function.
If decimal value is from ”.1 to .5″, it returns integer value less than the argument. If decimal value is from “.6 to .9″, it returns the integer value greater than the argument.
”math.h” header file supports round( ) function in C language. Syntax for round( ) function in C is given below.
double round (double a);
float roundf (float a);
long double roundl (long double a);
EXAMPLE PROGRAM FOR ROUND() FUNCTION IN C:

 #include <stdio.h>
#include <math.h>
 int main()
{
       float i=5.4, j=5.6;
       printf("round of  %f is  %f\n", i, round(i));
       printf("round of  %f is  %f\n", j, round(j));
       return 0;
}
Output: round of 5.4 is 5
round of 5.6 is 6
ceil ( )	This function returns nearest integer value which is greater than or equal to the argument passed to this function.
C – ceil() function
PREV     NEXT
ceil( ) function in C returns nearest integer value which is greater than or equal to the argument passed to this function.
”math.h” header file supports ceil( ) function in C language. Syntax for ceil( ) function in C is given below.
double ceil (double x);
EXAMPLE PROGRAM FOR CEIL() FUNCTION IN C:

 #include <stdio.h>
#include <math.h>
 int main()
{
       float i=5.4, j=5.6;
       printf("ceil of  %f is  %f\n", i, ceil(i));
       printf("ceil of  %f is  %f\n", j, ceil(j));
       return 0;
}
COMPILE & RUN
OUTPUT:
ceil of 5.400000 is 6.000000
Ceil of 5.600000 is 6.000000
sin ( )	This function is used to calculate sine value.
cos ( )	This function is used to calculate cosine.
cosh ( )	This function is used to calculate hyperbolic cosine.
exp ( )	This function is used to calculate the exponential “e” to the xth power.
tan ( )	This function is used to calculate tangent.
tanh ( )	This function is used to calculate hyperbolic tangent.
sinh ( )	This function is used to calculate hyperbolic sine.
log ( )	This function is used to calculates natural logarithm.
C – sin() cos() tan() exp() log() function
PREV     NEXT
sin( ), cos( ) and tan( ) functions in C are used to calculate sine, cosine and  tangent values.
sinh( ), cosh( ) and tanh( ) functions are used to calculate hyperbolic sine, cosine and tangent values.
exp( ) function is used to calculate the exponential “e” to the xth power. log( ) function is used to calculates natural logarithm and log10( ) function is used to calculates base 10 logarithm.
”math.h” header file supports all these functions in C language.
EXAMPLE PROGRAM FOR SIN(), COS(), TAN(), EXP() AND LOG()  IN C:

  
#include <stdio.h>
 
#include <math.h>
 
int main()
 
{
       float i = 0.314;
       float j = 0.25;
       float k = 6.25;
       float sin_value = sin(i);
       float cos_value = cos(i);
       float tan_value = tan(i);
       float sinh_value = sinh(j);
       float cosh_value = cosh(j);
       float tanh_value = tanh(j);
       float log_value = log(k);
       float log10_value = log10(k);
       float exp_value = exp(k);
 
       printf("The value of sin(%f) : %f \n", i, sin_value);
       printf("The value of cos(%f) : %f \n", i, cos_value);
       printf("The value of tan(%f) : %f \n", i, tan_value);
       printf("The value of sinh(%f) : %f \n", j, sinh_value);
       printf("The value of cosh(%f) : %f \n", j, cosh_value);
       printf("The value of tanh(%f) : %f \n", j, tanh_value);
       printf("The value of log(%f) : %f \n", k, log_value);
       printf("The value of log10(%f) : %f \n",k,log10_value);
       printf("The value of exp(%f) : %f \n",k, exp_value);
       return 0;
}
COMPILE & RUN
OUTPUT:
The value of sin(0.314000) : 0.308866
The value of cos(0.314000) : 0.951106
The value of tan(0.314000) : 0.324744

The value of sinh(0.250000) : 0.252612

The value of cosh(0.250000) : 1.031413

The value of tanh(0.250000) : 0.244919

The value of log(6.250000) : 1.832582

The value of log10(6.250000) : 0.795880



log10 ( )	This function is used to calculates base 10 logarithm.

sqrt ( )	This function is used to find square root of the argument passed to this function.
C – sqrt() function
PREV     NEXT
sqrt( ) function in C is used to find the square root of the given number.
”math.h” header file supports sqrt( ) function in C language. Syntax for sqrt( ) function in C is given below.
double sqrt (double x);
EXAMPLE PROGRAM FOR SQRT() FUNCTION IN C:
    

#include <stdio.h>      
#include <math.h>      
 
int main()
{
   printf ("sqrt of 16 = %f\n", sqrt (16) );
   printf ("sqrt of  2 = %f\n", sqrt (2) );
   return 0;
}
Output:
sqrt of 6 is 4.00000
sqrt of 2 = 1.414214

pow ( )	This is used to find the power of the given number.
C – pow() function
EXAMPLE PROGRAM FOR POW() FUNCTION IN C:

#include <stdio.h>      
#include <math.h>      
 
int main()
{
   printf ("2 power 4 = %f\n", pow (2.0, 4.0) );
   printf ("5 power 3 = %f\n", pow (5, 3) );
   return 0;
}
COMPILE & RUN
OUTPUT:
2 power 4 = 16.000000
5 power 3 is 125.0000
pow( ) function in C is used to find the power of the given number.
”math.h” header file supports pow( ) function in C language. Syntax for pow( ) function in C is given below.
double pow (double base, double exponent);


trunc.(.)	This function truncates the decimal value from floating point value and returns integer value.
C – trunc() function
PREV     NEXT
trunc( ) function in C truncates the decimal value from floating point value and returns integer value.
”math.h” header file supports trunc( ) function in C language. Syntax for trunc( ) function in C is given below.
double trunc (double a);
float truncf (float a);
long double truncl (long double a);

EXAMPLE PROGRAM FOR TRUNC( ) FUNCTION IN C:    

#include <stdio.h>      
#include <math.h>      
 
int main()
{
   printf ("truncated value of 16.99 = %f\n", trunc (16.99) );
   printf ("truncated value of 20.1  = %f\n", trunc (20.1) );
   return 0;
}
OUTPUT:
truncated value of 16.99 = 16.000000
truncated value of 20.1 = 20.000000

LIST OF INBUILT C FUNCTIONS IN STDIO.H FILE:

Function	------------------------  Description

printf() -------------------------	This function is used to print the character, string, float, integer, octal                                                       and hexadecimal values onto the output screen
scanf()	-------------------------- This function is used to read a character, string, numeric data from keyboard.
getc()	-------------------------- It reads character from file
gets()	-------------------------- It reads line from keyboard
getchar()	------------------------ It reads character from keyboard
puts()	-------------------------- It writes line to o/p screen
putchar()	------------------------ It writes a character to screen
clearerr()	---------------------- This function clears the error indicators
f open()	------------------------ All file handling functions are defined in stdio.h header file
f close()	------------------------ closes an opened file
getw()	-------------------------- reads an integer from file
putw()	-------------------------- writes an integer to file
f getc()	------------------------ reads a character from file
putc()	-------------------------- writes a character to file
f putc()	------------------------ writes a character to file
f gets()	------------------------ reads string from a file, one line at a time
f puts()	------------------------ writes string to a file
f eof()	-------------------------- finds end of file
f getchar	------------------------ reads a character from keyboard
f getc()	------------------------ reads a character from file
f printf()	---------------------- writes formatted data to a file
f scanf()	------------------------ reads formatted data from a file
f getchar	------------------------ reads a character from keyboard
f putchar	------------------------ writes a character from keyboard
f seek()	------------------------ moves file pointer position to given location
SEEK_SET	------------------------ moves file pointer position to the beginning of the file
SEEK_CUR	------------------------ moves file pointer position to given location
SEEK_END	------------------------ moves file pointer position to the end of file.
f tell()	------------------------ gives current position of file pointer
rewind()	------------------------ moves file pointer position to the beginning of the file
putc()	-------------------------- writes a character to file
sprint()	------------------------ writes formatted output to string
sscanf()	------------------------ Reads formatted input from a string
remove()	------------------------ deletes a file
fflush()	------------------------ flushes a file

C – conio.h library functions

All C inbuilt functions which are declared in conio.h header file are given below. The source code for conio.h header file is also given below for your reference.


 

 
LIST OF INBUILT C FUNCTIONS IN CONIO.H FILE:
Functions ---------------------------- Description
clrscr()	---------------------------- This function is used to clear the output screen.
getch()	------------------------------ It reads character from keyboard
getche() ----------------------------- It reads character from keyboard and echoes to o/p screen
textcolor()	-------------------------- This function is used to change the text color
textbackground()	-------------------- This function is used to change text background

Example of clrscr() in built function:
C – string.h library functions

All C inbuilt functions which are declared in string.h header file are given below. The source code for string.h header file is also given below for your reference.


 

 
LIST OF INBUILT C FUNCTIONS IN STRING.H FILE:
String functions ----------------------- Description
strcat ( )	--------------------- Concatenates str2 at the end of str1
strncat ( )	--------------------- Appends a portion of string to another
strcpy ( )	--------------------- Copies str2 into str1
strncpy ( )	--------------------- Copies given number of characters of one string to another
strlen ( )	--------------------- Gives the length of str1
strcmp ( )	--------------------- Returns 0 if str1 is same as str2. Returns <0 if strl < str2. Returns >0                                    if str1 > str2
strcmpi ( )	----------------------Same as strcmp() function. But, this function negotiates case.  “A” and                                     “a” are treated as same.
strchr ( )	--------------------- Returns pointer to first occurrence of char in str1
strrchr ( )	--------------------- last occurrence of given character in a string is found
strstr ( )	--------------------- Returns pointer to first occurrence of str2 in str1
strrstr ( )	--------------------- Returns pointer to last occurrence of str2 in str1
strdup ( )	--------------------- Duplicates the string
strlwr ( )	--------------------- Converts string to lowercase
strupr ( )	--------------------- Converts string to uppercase
strrev ( )	--------------------- Reverses the given string
strset ( )	--------------------- Sets all character in a string to given character
strnset ( )	--------------------- It sets the portion of characters in a string to given character
strtok ( )	--------------------- Tokenizing given string using delimiter
memset ( ) ---------------------- It is used to initialize a specified number of bytes to null or any                                            other value in the buffer
memcpy ( ) ----------------------	It is used to copy a specified number of bytes from one memory to another
memmove ( )	----------------------It is used to copy a specified number of bytes from one memory to another                                       or to overlap on same memory.
memcmp ( )	--------------------- It is used to compare specified number of characters from two buffers
memicmp ( )	--------------------- It is used to compare specified number of characters from two buffers                                         regardless of the case of the characters
memchr ( )	It is used to locate the first occurrence of the character in the specified string

C – stdlib.h library functions

All C inbuilt functions which are declared in stdlib.h header file are given below. The source code for stdlib.h header file is also given below for your reference.


LIST OF INBUILT C FUNCTIONS IN STDLIB.H FILE:
Function ---------------- Description
malloc()	--------------- This function is used to allocate space in memory during the execution of the program.
calloc()	--------------- This function is also like malloc () function. But calloc () initializes the allocated
                          memory to zero. But, malloc() doesn’t
realloc()	--------------- This function modifies the allocated memory size by malloc () and calloc ()
                          functions to a new size
free()	----------------- This function frees the allocated memory by malloc (), calloc (), realloc () functions
                          and returns the memory to the system.
abs()	------------------- This function returns the absolute value of an integer . The absolute value of a
                          number is always positive. Only integer values are supported in C.
div()	------------------- This function performs division operation
abort()	----------------- It terminates the C program
exit()	----------------- This function terminates the program and does not return any value
system()	--------------- This function is used to execute commands outside the C program.
atoi()	----------------- Converts string to int
atol()	----------------- Converts string to long
atof()	----------------- Converts string to float
strtod()	--------------- Converts string to double
strtol()	--------------- Converts string to long
getenv()	--------------- This function gets the current value of the environment variable
setenv()	--------------- This function sets the value for environment variable
putenv()	--------------- This function modifies the value for environment variable
perror()	--------------- This function displays most recent error that happened during library function call.
rand()	----------------- This function returns the random integer numbers
delay()	----------------- This function Suspends the execution of the program for particular time

C - Time.h library functions

All C inbuilt functions which are declared in time.h header file are given below. The source code for time.h header file is also given below for your reference.
LIST OF INBUILT C FUNCTIONS IN TIME.H FILE:
Below are the list of time related fuctions in C programming language. Please refer C – time related functions page for sample program and output for each below functions.

Functions	----------------- Description
setdate()	----------------- This function used to modify the system date
getdate()	----------------- This function is used to get the CPU time
clock()	------------------- This function is used to get current system time
time()	------------------- This function is used to get current system time as structure
difftime()	--------------- This function is used to get the difference between two given times
strftime()	--------------- This function is used to modify the actual time format
mktime()	----------------- This function interprets tm structure as calendar time
localtime()	--------------- This function shares the tm structure that contains date and time informations
gmtime()	----------------- This function shares the tm structure that contains date and time informations
ctime()	------------------- This function is used to return string that contains date and time informations
asctime()	----------------- Tm structure contents are interpreted by this function as calendar time. This                               time is converted into string.

C – ctype.h library functions

All C inbuilt functions which are declared in stdlib.h header file are given below. The source code for stdlib.h header file is also given below for your reference.


LIST OF INBUILT C FUNCTIONS IN CTYPE.H FILE:
“ctype.h” header file support all the below functions in C language. Click on each function name below for detail description and example programs.

Functions ---------------------- 	Description
isalpha() ---------------------- checks whether character is alphabetic
C – isalpha() function
PREV     NEXT
isalpha( ) function in C language checks whether given character is alphabetic or not. Syntax for isalpha( ) function is given below.
int isalpha ( int x );
EXAMPLE PROGRAM FOR ISALPHA( ) FUNCTION IN C:
1
#include <stdio.h>
 
int main()
{
   char ch;
 
   printf("Enter any character\n");
   scanf("%c", &ch);
   if ( isalpha ( ch ) )
      printf ( "\nEntered character is alphabetic" ) ;
   else
      printf ( "\nEntered character is not alphabetic" ) ;
}
COMPILE & RUN
 OUTPUT:
Enter any character
1
Entered character is not alphabetic

isdigit() ---------------------  checks whether character is digit
C – isdigit() function
PREV     NEXT
isdigit( ) function in C language checks whether given character is digit or not. Syntax for isdigit( ) function is given below.
int isdigit ( int x );

EXAMPLE PROGRAM FOR ISDIGIT() FUNCTION IN C:

#include <stdio.h>
 
int main()
{
   char ch;
 
   printf("Enter any character\n");
   scanf("%c", &ch);
   if ( isdigit ( ch ) )
      printf ( "\nEntered character is digit" ) ;
   else
      printf ( "\nEntered character is not digit" ) ;
}
COMPILE & RUN
OUTPUT:
Enter any character
200
Entered character is digit
isalnum()	---------------------- Checks whether character is alphanumeric
C – isalnum() function
PREV     NEXT
isalnum() function in C language checks whether given character is alphanumeric or not. Syntax for isalnum( ) function is given below.
int isalnum ( int x );
EXAMPLE PROGRAM FOR ISALNUM() FUNCTION IN C:

#include <stdio.h>
 
int main()
{
   char ch;
   printf("Enter any character\n");
   scanf("%c", &ch);
 
   if ( isalnum ( ch ) )
      printf ( "\nEntered character is alphanumeric" ) ;
   else
      printf ( "\nEntered character is not alphanumeric" ) ;
}
COMPILE & RUN
OUTPUT:
Enter any character
@
isspace()	---------------------- Checks whether character is space
C – isspace() function
PREV     NEXT
isspace( ) function in C language checks whether given character is space or not. Syntax for isspace( ) function is given below.
int isspace( int x );

EXAMPLE PROGRAM FOR ISSPACE() FUNCTION IN C:
C
#include <stdio.h>

int main()
{
   char ch;
   printf("Enter any character\n");
   scanf("%c", &ch);

   if ( isspace ( ch ) )
      printf ( "\nEntered character is space" ) ;
   else
      printf ( "\nEntered character is not space" ) ;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
 
int main()
{
   char ch;
   printf("Enter any character\n");
   scanf("%c", &ch);
 
   if ( isspace ( ch ) )
      printf ( "\nEntered character is space" ) ;
   else
      printf ( "\nEntered character is not space" ) ;
}
COMPILE & RUN
OUTPUT:
Enter any character
a
Entered character is not space

islower()	---------------------- Checks whether character is lower case
C – islower() function
PREV     NEXT
islower( ) function in C language checks whether given character is lower case or not. Syntax for islower( ) function is given below.
int islower( int x );
EXAMPLE PROGRAM FOR ISLOWER() FUNCTION IN C:

#include <stdio.h>
 
int main()
{
   char ch;
   printf("Enter any character\n");
   scanf("%c", &ch);
 
   if ( islower ( ch ) )
   printf ( "\nEntered character is lower case character") ;
   else
   printf("\nEntered character is not lower case character");
}
COMPILE & RUN
OUTPUT:
Enter any character
a
Entered character is lower case character

isupper()	---------------------- Checks whether character is upper case
supper() function
PREV     NEXT
isupper( ) function in C language checks whether given character is upper case or not. Syntax for isupper( ) function is given below.
int isupper ( int x );
EXAMPLE PROGRAM FOR ISUPPER() FUNCTION IN C:

#include <stdio.h>
 
int main()
{
   char ch;
   printf("Enter any character\n");
   scanf("%c", &ch);
 
   if ( isupper ( ch ) )
      printf ("\nEntered character is uppercase character");
   else
      printf("\nEntered character is not uppercase character");
}
COMPILE & RUN
OUTPUT:
Enter any character
A
Entered character is upper case character

isxdigit()	-------------------- Checks whether character is hexadecimal
iscntrl()	---------------------- Checks whether character is a control character
isprint()	---------------------- Checks whether character is a printable character
ispunct() ---------------------- Checks whether character is a punctuation
isgraph()	---------------------- Checks whether character is a graphical character
tolower()	---------------------- Checks whether character is alphabetic & converts to lower case
toupper()	---------------------- Checks whether character is alphabetic & converts to upper case


C – Command line arguments

COMMAND LINE ARGUMENTS IN C:
main() function of a C program accepts arguments from command line or from other shell scripts by following commands. They are,
argc
argv[]
where,

argc    – Number of arguments in the command line including program name
argv[]   – This is carrying all the arguments

In real time application, it will happen to pass arguments to the main program itself.  These arguments are passed to the main () function while executing binary file from command line.
For example, when we compile a program (test.c), we get executable file in the name “test”.
Now, we run the executable “test” along with 4 arguments in command line like below.
./test this is a program

Where,
argc             =       5
argv[0]         =       “test”
argv[1]         =       “this”
argv[2]         =       “is”
argv[3]         =       “a”
argv[4]         =       “program”
argv[5]         =       NULL

EXAMPLE PROGRAM FOR ARGC() AND ARGV() FUNCTIONS IN C:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])   //  command line arguments
{
if(argc!=5) 
{
   printf("Arguments passed through command line " \
          "not equal to 5");
   return 1;
}

   printf("\n Program name  : %s \n", argv[0]);
   printf("1st arg  : %s \n", argv[1]);
   printf("2nd arg  : %s \n", argv[2]);
   printf("3rd arg  : %s \n", argv[3]);
   printf("4th arg  : %s \n", argv[4]);
   printf("5th arg  : %s \n", argv[5]);

return 0;
}

#include <stdio.h>
#include <stdlib.h>
 
int main(int argc, char *argv[])   //  command line arguments
{
if(argc!=5) 
{
   printf("Arguments passed through command line " \
          "not equal to 5");
   return 1;
}
 
   printf("\n Program name  : %s \n", argv[0]);
   printf("1st arg  : %s \n", argv[1]);
   printf("2nd arg  : %s \n", argv[2]);
   printf("3rd arg  : %s \n", argv[3]);
   printf("4th arg  : %s \n", argv[4]);
   printf("5th arg  : %s \n", argv[5]);
 
return 0;
}
COMPILE & RUN 
OUTPUT:
Program name : test
1st arg : this
2nd arg : is
3rd arg : a
4th arg : program
5th arg : (null)
C – Variable length argument

Variable length arguments is an advanced concept in C language offered by c99 standard. In c89 standard, fixed arguments only can be passed to the functions.
When a function gets number of arguments that changes at run time, we can go for variable length arguments.
It is denoted as … (3 dots)
stdarg.h header file should be included to make use of variable length argument functions.
EXAMPLE PROGRAM FOR VARIABLE LENGTH ARGUMENTS IN C:
C
#include <stdio.h>
#include <stdarg.h>

int add(int num,...);

int main()
{
     printf("The value from first function call = " \
            "%d\n", add(2,2,3));
     printf("The value from second function call= " \
            "%d \n", add(4,2,3,4,5));

     /*Note - In function add(2,2,3), 
                   first 2 is total number of arguments
                   2,3 are variable length arguments
              In function add(4,2,3,4,5), 
                   4 is total number of arguments
                   2,3,4,5 are variable length arguments
     */

     return 0;
}

int add(int num,...)
{
     va_list valist;
     int sum = 0;
     int i;

     va_start(valist, num);
     for (i = 0; i < num; i++)
     {
         sum += va_arg(valist, int);
     }
     va_end(valist);
     return sum;
}

#include <stdio.h>
#include <stdarg.h>
 
int add(int num,...);
 
int main()
{
     printf("The value from first function call = " \
            "%d\n", add(2,2,3));
     printf("The value from second function call= " \
            "%d \n", add(4,2,3,4,5));
 
     /*Note - In function add(2,2,3), 
                   first 2 is total number of arguments
                   2,3 are variable length arguments
              In function add(4,2,3,4,5), 
                   4 is total number of arguments
                   2,3,4,5 are variable length arguments
     */
 
     return 0;
}
 
int add(int num,...)
{
     va_list valist;
     int sum = 0;
     int i;
 
     va_start(valist, num);
     for (i = 0; i < num; i++)
     {
         sum += va_arg(valist, int);
     }
     va_end(valist);
     return sum;
}
COMPILE & RUN
OUTPUT:
The value from first function call = 5
The value from second function call= 14
In the above program, function “add” is called twice. But, number of arguments passed to the function gets varies for each. So, 3 dots (…) are mentioned for function ‘add” that indicates that this function will get any number of arguments at run time*/

https://fresh2refresh.com/c-programming/c-function/c-summary-of-c-functions/

 
/*Continue on C – Library functions….

Continue on C – User defined functions & adding them in C library….

Continue on C – Command line arguments….

Continue on C – Variable length arguments….*/



//https://fresh2refresh.com/c-programming/c-function///