c variable values code example
Example 1: variable parameters in c
#include <stdio.h>
#include <stdarg.h>
double average(int num,...) {
va_list valist;
double sum = 0.0;
int i;
va_start(valist, num);
for (i = 0; i < num; i++) {
sum += va_arg(valist, int);
}
va_end(valist);
return sum/num;
}
int main() {
printf("Average of 2, 3, 4, 5 = %f\n", average(4, 2,3,4,5));
printf("Average of 5, 10, 15 = %f\n", average(3, 5,10,15));
}
Example 2: declaring variables in c
int a;
int a = 5;
int b = 6;
int num = 2;
float number = 234.87;
char ch = 'p';
char name[] = {'B','i', 'l','l'}
char fav_fruit[] = "apple"