Custom Search

Sunday, 15 January 2012

WAP, Write a C or C++ Program that reads a floating point number and displays the right most digit of integral part of the number with output

WAP, Write a C or C++ Program that reads a floating point number and displays the right most digit of integral part of the number with output


Program
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float a;
int ans,b;
printf("Enter the value:");
scanf("%f", &a);
b=a;
ans=b%10;
printf("ans is %d", ans);
getch();
}

Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the output

No comments:

Post a Comment

Laptops