function and recursion in c programs
#include <stdio.h>
float average(int a, int b, int c); //prototype
int main()
{
int number1, number2, number3;
float results;
printf("enter the number \n");
scanf("%d%d%d", &number1, &number2, &number3);
results = average(number1, number2, number3);
printf("The value of average is %f", results);
return 0;
}
float average(int a, int b, int c)
{
float d;
d = (float)(a + b + c) / 3;
return d;
}
# include<stdio.h>
float convertor(float a);
int main(){
float celsius,farheint;
printf("Enter the Temperature in celsuis: \n");
scanf("%f",&celsius);
farheint=convertor(celsius);
printf("%f is Farheint Temperatre",farheint);
return 0;
}
float convertor(float a){
float c;
c=(a*9/5)+32;
return c;
}
# include<stdio.h>
float force(int mass);
int main(){
int mass;
float c;
printf("enter the mass \n ");
scanf("%d",&mass);
c= force(mass);
printf("force is %f",c);
return 0;
}
float force(int mass ){
float c;
c=mass*9.8;
return c;
}
#include <stdio.h>
int fibonacci(int a);
int main()
{
int number,results;
printf("enter the number u want fibonacci:");
scanf("%d",&number);
results= fibonacci(number);
printf("fibonacci of %d is %d",number,results);
return 0;
}
int fibonacci(int a){
if(a<=1)
{return a;}
else{
return fibonacci(a-1)+fibonacci(a-2);
}
}
#include <stdio.h>
int main()
{
int number, i;
printf("enter the number of n to star print \n");
scanf("%d", &number);
for (int j = 1; j <= number; j++)
{
for (int i = 1; i <= j; i++)
{
printf("*");
}
printf("\n");
}
return 0;
}
#include <stdio.h>
void printpattern(int n); // function prototype
int main()
{
int number;
printf("enter the number of star \n");
scanf("%d", &number);
printpattern(number);
return 0;
}
void printpattern(int n)
{
if (n == 1)
{
printf("*\n");
return;
}
printf("calling function %d \n", n);
printpattern(n - 1);
for (int i = 0; i < n; i++)
{
printf("*");
}
printf("\n");
}
#include <stdio.h>
void print_table(int n);
int main()
{
int number;
printf("enter the natural number 1-n \n");
scanf("%d", &number);
print_table(number);
return 0;
}
void print_table(int n)
{
if (n == 1)
{
printf("%d\n", n);
return;
}
printf("calling function %d\n", n);
print_table(n - 1);
printf("%d\n", n);
}