Oop 4
Oop 4
1.Imagine you are developing a software module for a financial application that deals with large
sets of numerical data. As part of the functionality, you need to determine the number of digits in
each financial transaction amount. You decide to implement a recursive function to achieve this.
if(num==0)
{
return 0;
}
else
{
return 1+digicount(num/10);
}
}
void main()
{
int num=0,digit=0;
printf("Enter the number");
scanf("%d",&num);
digit=digicount(num);
printf("The number of digits is %d",digit);
}
SAMPLE OUTPUT:
1. Enter the number3456
The number of digits is 4
#include <stdio.h>
int power(int a, int n);
void main()
{
int a,n,res;
printf("Enter value of a\n");
scanf("%d",&a);
printf("Enter value of n\n");
scanf("%d",&n);
res=power(a,n);
printf("The value of %d power %d is %d",a,n,res);
}
int power(int a,int n)
{
if(n==0)
{
return 1;
}
else
{
return a*power(a,n-1);
}
}
SAMPLE OUTPUT
Enter value of a
2
Enter value of n
8
The value of 2 power 8 is 256
SAMPLE OUTPUT 2
Enter x
2
Enter n (must be odd)
7
The result of the series pattern is 0.907937