A C program to create an expense calculator using recursive functions and pointer to array.
#include<stdio.h>
int total_expenses(int *cost,int n);
int main()
{
int n=10;
int cost[50];
printf("Enter the expenses:\n");
for(int i=0;i<10;i++)
{
printf("Enter expense %d:\n",i+1);
scanf("%d",&cost[i]);
}
int *ptr;
ptr=cost;
int result=total_expenses(ptr,10);
printf("Your total expenses are: %d\n",result);
return 0;
}
int total_expenses(int *cost,int n)
{
if(n==0)
{
return 0;
}
else
{
return cost[n-1]+total_expenses(cost,n-1);
}
}