Write A Program To Count How Many Positive, Negative, Positive Fraction And Negative Fraction Numbers In Our File

 


Input Text File


1,23,-4,5.3,-8.4,4,6,-8,3.5,-5.9

Code


%{
#include<stdio.h>
int p=0;
int n=0;
int pf=0;
int nf=0;
%}
DIGIT [0-9]
%%

\+?{DIGIT}+ p++;
[-]{DIGIT}+ n++;
\+?{DIGIT}*\.{DIGIT}+ pf++;
-{DIGIT}*\.{DIGIT}+ nf++;
.;

%%
main()
{
extern FILE *yyin;
yyin=fopen("Numbers.txt","r");
if(yyin==NULL){
printf("File Not Found");
}
yylex();
printf("\n count of Positive Numbers:%d",p);
printf("\n count of Negative Numbers:%d",n);
printf("\n count of Positive Fractions Numbers:%d",pf);
printf("\n count of Negative Fractions Numbers:%d",nf);
}
int yywrap(){
return (1);
}


Output







Comments

Popular posts from this blog

Write A Program To Print Hello World Using Lex

Create a Student registration form using following tags form,input,textarea,button,select,optio. The registration form must consist of following information: first name,Middle name,last name, gender(use radio button),address,phone no,email id,hobbies(use checkbox),city,state,country,collage name (use dropdown menu).