#include<stdio.h>
#include<math.h>
float ar(int a);
int main()
{
int a;
scanf("%d",&a);
printf("%.2f",ar(a));
return 0;
}
float ar(int a)
{
int i,br=0,uk=0;
float ar;
for(i=0;i<=a;i++)
{
if(a%i==0)
{
br++;
uk=uk+i;
}
}
ar=uk/br;
return ar;
}
I'm trying to return the arithmetic value of all of the divisors of the number I enter. Why isn't anything getting printed back?
#include<stdio.h>
#include<math.h>
int razlika(int a);
int main(){
printf("%d",razlika(26931));
return 0;
}
int razlika(int a)
{
int i,min=10000000,max=0,br=0,p,z;
do{
a=a/10;
br++;
}
while (a!=0);
for(i=0;i<br;i++)
{
p=a%10;
a=a/10;
if(p<min) min=p;
if(p>max) max=p;
}
z=max-min;
return z;
}
In this one im supposed to find the difference between the largest and the smallest digit of the number but it always prints out 0. I think it is because of the do while loop where i think i turn my number into 0? But I dont know how to count the number of the digits without making that mistake.