-1
#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.

1 Answers1

0
  • In your first program, your loop starts from 0, and you cant divide by zero.
  • As to your second program, you are correct, you changed the number to zero so you cant use it in the second loop, simply create a temporary variable and set it = a, use it in the do- while loop instead of a itself.
  • also in the do-while loop, let the condition be while (a>0).
    Help this helps!
YosefAhab
  • 64
  • 10