Welcome to the World of Programming

Welcome to the World of Programming

Search this blog

Validating and Accepting Floating Point and Fixed Point Numbers

#include<stdio.h>
int main(){
    int a,i=0,count=0,l=0,flag=0;
    char s[10];
    for(i=0;i<10;i++)
        s[i]='\0';
    printf("Enter a Number :");
    scanf("%s",s);
    i=0;
    while(s[i]!='\0'){
        a=(int)s[i];
        if((a>57||a<48)&&a!=46){
            flag=1;
        }
        if(s[i]=='.')
            count++;
        i++;   
    }
    l=strlen(s);
    if(count==1&&i==l&&flag==0)
        printf("\nFloating Point Number");
    else if(count==0&&i==l&&flag==0)
        printf("\nFixed Point Number");
    else if(flag==1)
        printf("\nEnter Number Only");
    else
        printf("\nEnter Correct Decimal Places");
    return 0;
}

No comments:

Post a Comment