#include < stdio.h >
#include < conio.h >
#include < stdlib.h >
#include < string.h >
#include < ctype.h >
#include < process.h >
void check(char * s1)
{
/*checking floating point number or not */
int i,flag=0,c=0;
for(i=0;s1[i]!='\0';i++)
{
if(s1[i]=='.')
c++;
}
for(i=0;s1[i]!='\0';i++)
{
if(isdigit(s1[i])==0)
{
if(s1[i]!='.')
{flag=1;
break;
}} }
if(flag==1 ||c>1)
{
printf("Error! Invalid");
getch();
exit(0);
}
else
return;
}
void main()
{
char s1[15],s2[15];
float f1,f2;
int i,flag=0;
clrscr();
printf("Enter two floating point numbers:");
scanf("%s%s",s1,s2);
check(s1);
check(s2);
if(atof(s2)==0)
printf("The secondno. must not zero");
f1=atof(s1);
f2=atof(s2);
printf("\n%.2f + %.2f=%.2f",f1,f2,(f1+f2));
printf("\n%.2f - %.2f=%.2f",f1,f2,(f1-f2));
printf("\n%.2f * %.2f=%.2f",f1,f2,(f1*f2));
if(f2==0)
printf("The second number must not be zero");
printf("\n%.2f / %.2f=%.2f",f1,f2,(f1/f2));
getch();
}
No comments:
Post a Comment