Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Saturday, 15 April 2017

C program to compute the FIRST of the Grammer

#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<ctype.h>
int n;
char a[10][20],first[10],follow[10][20];
void main()
{
char x[44];
clrscr();
int i;
printf("\nEnter no of productions ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
gets(x);
printf("\nEnter production %d ",(i+1));
gets(a[i]);
}
//FIRST
int k,j;
for(i=n-1;i>=0;i--)
{
if(isupper(a[i][2]))
{
for(j=0;j<n;j++)
if(a[j][0]==a[i][2])
first[i]=first[j];
}
else
{
first[i]=a[i][2];
}
}
for(i=0;i<n;i++)
{
printf("first of %c",a[i][0]," is %c",first[i]);
}
getch();
}

No comments:

Post a Comment