Divide by Unit Digit

The program must accept N integers as the input. The program must divide each integer by its unit digit and print the result up to two decimal places as the input. If the unit digit of the integer is 0 then the program must print the same integer with the precision up to two decimal places as the output.
Boundary Condition(s):
1 <= N <= 1000
Input Format:
The first line contains the values of N.
The second line contains N integers separated by a space.
Output Format:
The first line contains the N integer(s) separated by a space.
Example Input/Output 1:
Input:
2
10 49
Output:
10.00 5.44
Explanation:
The unit digit of 10 is 0. So the the same integer is printed as 10.00
The unit digit of 49 is 9. Here, 49 is divided by 9 the result is 5.44444444. The result is rounded up to two decimal places is 5.44.
Hence the output is 10.00 5.44
Example Input/Output 2:
Input:
10
15 522 52 511 1898 158 189 29 789 230
Output:
3.00 261.00 26.00 511.00 237.25 19.75 21.00 3.22 87.67 230.00

Solution :-
#include<stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int b;
    
    for(int i=0;i<n;i++)
    {
        scanf("%d ",&b);
        int un=b%10;
        
        if(un==0)
        {
            printf("%d.00 ",b);
        }
        else
        {
            float c=b;
            printf("%.2f ",c/un);
        }
        
        
        
        
    }


}

Comments

Popular posts from this blog

Two Matrix Spiral Print

Alphabets Positions Reversed

Odd Factors - (Error Identification) skillrack program id - 7306