write function in c code example
Example 1: write in file in c
#include<stdio.h>
int main(){
FILE *out=fopen("name_of_file.txt","w");
fputs("Hello File",out);
fclose(out);
return 0;
}
Example 2: function in c
#include <stdio.h>
void function(){
printf("I am a function!");
}
int main(void) {
function();
}
Example 3: how to write function in c
#include <stdio.h>
int MyAge() {
return 25;
}
int main(void) {
MyAge();
}
Example 4: functions in c programming
#include <stdio.h>
void introduction()
{
printf("Hi\n");
printf("My name is Chaitanya\n");
printf("How are you?");
}
int main()
{
introduction();
return 0;
}
Example 5: functions in c programming
#include <stdio.h>
int addition(int num1, int num2)
{
int sum;
sum = num1+num2;
return sum;
}
int main()
{
int var1, var2;
printf("Enter number 1: ");
scanf("%d",&var1);
printf("Enter number 2: ");
scanf("%d",&var2);
int res = addition(var1, var2);
printf ("Output: %d", res);
return 0;
}