Printing last digit of decimal decimal part of and floating point number

Problem statement
write a c program to print the last decimal digit
i.e. in case of 3.02 your program should print 2


#include<stdio.h>
int main()
{
  int temp;
  float n;
  printf("enter the lenth and ");
  scanf("%f",&n);
  temp=n/1;
  while(n!=temp){
    n=n*10;
    temp=n/1;
  }
  printf("%d \n",temp%10);
  return 0;
}

No comments:

Post a Comment