Untitled 1
Untitled 1
Write a program to determine wether the given input is a valid identifier or not(with and
without regular expression)
i)input : sam , output: Valid identifier
ii)input: 3_ab output: Invalid identifier
C PROGRAM:
#include <stdio.h>
#include <regex.h>
return !result;
}
int main() {
char input[100];
if (isValidIdentifier(input)) {
printf("Input: %s, Output: Valid identifier\n", input);
} else {
printf("Input: %s, Output: Invalid identifier\n", input);
}
return 0;
}
OUTPUT:
return 1;
}
int main() {
char input[100];
if (isValidIdentifier(input)) {
printf("Input: %s, Output: Valid identifier\n", input);
} else {
printf("Input: %s, Output: Invalid identifier\n", input);
}
printf("Submitted by Rupesh_22BCE1909");
return 0;
}
2.Write a program to check wether a given string will get occupied for the below regular
expression
i)ab
CODE:
#include <stdio.h>
#include <string.h>
int main() {
char input[100];
printf("Enter a string: ");
scanf("%s", input);
if (matchesAB(input)) {
printf("Input: %s, Output: String is matching with the regular expression 'ab'\n", input);
} else {
printf("Input: %s, Output: String is not matching with the regular expression 'ab'\n", input);
}
return 0;
}
OUTPUT:
ii)(a)*abb
CODE:
#include <stdio.h>
#include <string.h>
int main() {
char input[100];
printf("Enter a string: ");
scanf("%s", input);
if (matchesAStarABB(input)) {
printf("Input: %s, Output: String is matching with the regular expression '(a)*abb'\n", input);
} else {
printf("Input: %s, Output: String is not matching with the regular expression '(a)*abb'\n",
input);
}
printf("Submitted by RUPESH_22BCE1909");
return 0;
}
OUTPUT:
For valid inputs:
i)abb
ii)aabb
Faor invalid inputs:
i)aaaaabbb
ii)Rupesh
iii)(ab)*a
CODE:
#include <stdio.h>
#include <string.h>
int main() {
char input[100];
printf("Enter a string: ");
scanf("%s", input);
if (matchesABStarA(input)) {
printf("Input: %s, Output: String matches the regular expression '(ab)*a'\n", input);
} else {
printf("Input: %s, Output: String does not match the regular expression '(ab)*a'\n", input);
}
printf("submitted by Rupesh(22bce1909)");
return 0;
}
OUTPUT:
VALID:
INVALID:
iv)b(a)+b
CODE:
#include <stdio.h>
#include <string.h>
int main() {
char input[100];
printf("Enter a string: ");
scanf("%s", input);
if (matchesBAplusB(input)) {
printf("Input: %s, Output: String is matching with the regular expression 'b(a)+b'\n", input);
} else {
printf("Input: %s, Output: String is not matching with the regular expression 'b(a)+b'\n",
input);
}
printf("Submited by RUPES(22BCE1909)");
return 0;
}
OUTPUT:
VALID:
INVALID: