Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- За даден број n, да се напише рекурзивна функција која ќе ги изброи
- појавувањата на цифрата 8. Притоа, доколку до некоја цифра 8 има уште една
- цифра 8 веднаш лево од неа, нејзиното појавување се брои двојно
- Пример:
- count8(8) -> 1
- count8(818) -> 2
- count8(8818) -> 4
- */
- #include <stdio.h>
- int count8(int broj,int predcifra){
- if(broj==0){
- return 0;
- }
- else{
- if(broj%10!=8){
- return 0+count8(broj/10,broj%10);
- }
- if(broj%10==8 && predcifra==8){
- return 2+count8(broj/10,broj%10);
- }
- if(broj%10==8){
- return 1+count8(broj/10,broj%10);
- }
- }
- }
- int main()
- {
- int a;
- scanf("%d",&a);
- printf("%d",count8(a,0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement