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);
}
#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);
}
Comments
Post a Comment