Click Here- to Download
#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;
}
|
The value from first function call = 5
The value from second function call= 14 |
#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;
}
|
Program name : test
1st arg : this 2nd arg : is 3rd arg : a 4th arg : program 5th arg : (null) |
#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;
}
| truncated value of 16.99 = 16.000000 truncated value of 20.1 = 20.000000 |
#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;
}
| 2 power 4 = 16.000000 5 power 3 = 125.000000 |
#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;
}
| sqrt of 16 = 4.000000 sqrt of 2 = 1.414214 |
#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;
}
| 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 The value of exp(6.250000) : 518.012817 |
#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;
}
| ceil of 5.400000 is 6.000000 ceil of 5.600000 is 6.000000 |
#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;
}
| round of 5.400000 is 5.000000 round of 5.600000 is 6.000000 |
#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;
}
| 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 |
#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;
}
| Absolute value of m = 200 Absolute value of n = 400 |
All of this blog content copied from various books,e books and ejournals