EXAMINATION SCAM 1
Examination Scam 1
Now a days in online examination there has been many fraudulent activities.Since online examination takes place virtualy its easy for the corrupts to gain money from it.
One such fraudulent activity is providing fake registration links to the participants and collecting the fee from them.Due to this activity the legitimate online examination boards are hindered.As they are the once held responsible for the fees collected.There is also the case of an applicant registering using fake credentials.Applying more then once for a particular examination.
To curb such bogus registration activity,the online examination board has decided to allot a random number to each applicants. This random number is valid only if it contains a specific number of 5’s. (digit 5).
Can you help them by writing a program to count the occurrences of 5 as a digit in the random number ‘n’ that is generated?
Note : Formulate a RECURSIVE Algorithm
Function name: int findDigit(int n);
Input Format:
Input consists of a single integer that corresponds to n.
Output Format:
Output consists of a single integer that corresponds to the number of times the digit 5 appears in ‘n’.
Sample Input :
52
Sample Output :
1
Sample Input :
555
Sample Output :
3
#include
int findDigit(int n);
int ctr=0,r;
int main()
{
int n;
scanf("%d",&n);
printf("%d",findDigit(n));
return 0;
}
int findDigit(int n)
{
if(n>0)
{
r=n%10;
n=n/10;
if(r==5)
{
ctr++;
return (findDigit(n));
}
else return (findDigit(n));
}
return ctr;
}
Comments
Post a Comment