Advertisement
BorjanCrvenkov

rekurzija code

Jan 19th, 2020
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. int poramnet(int a) {
  3. if(a==0) {
  4. return 0;
  5. } else if(a%10==9) {
  6. return 7+poramnet(a/10)*10;
  7. }
  8. return (a%10)+poramnet(a/10)*10;
  9. }
  10. void sort(int *a,int n) {
  11. int i,j;
  12. for(i=0; i<n-1; i++) {
  13. for(j=i+1; j<n; j++)
  14. if(a[i]>a[j]) {
  15. int temp=a[i];
  16. a[i]=a[j];
  17. a[j]=temp;
  18. }
  19. }
  20. }
  21. int main()
  22. {
  23. int niza[100];
  24. int i=0;
  25. while(1){
  26. if(scanf("%d",&niza[i])==0){
  27. break;
  28. }
  29. i++;
  30. }
  31. int n=i;
  32. for(i=0;i<n;i++){
  33. niza[i]=poramnet(niza[i]);
  34. }
  35. sort(niza,n);
  36. if(n<5) {
  37. for(i=0; i<n; i++)
  38. printf("%d ",a[i]);
  39. } else {
  40. for(i=0; i<5; i++)
  41. printf("%d ",niza[i]);
  42. }
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement