Phone Number Validation - PRF192 - Workshop 6 Question - Contests - HackerRank
Phone Number Validation - PRF192 - Workshop 6 Question - Contests - HackerRank
NEW
PREPARE CERTIFY COMPETE APPLY Search
SE1648_He161883
All Contests
PRF192 - Workshop 6
Phone Number Validation
Given a string representing a phone number, write a program to check whether it is a valid phone number. Suppose that a valid
phone number must appear in one of the following format:
(xxx) xxx-xxxx
xxx-xxx-xxxx
Input Format
Constraints
Output Format
If the given phone number is valid, print out "valid". Otherwise, print out "not valid".
Sample Input 0
(031) 456-8823
Sample Output 0
valid
Sample Input 1
031-456-8823
Sample Output 1
valid
Sample Input 2
0314568823
Sample Output 2
https://www.hackerrank.com/contests/prf192-workshop-6/challenges/phone-number-validation 1/2
22:05, 26/10/2021 Phone Number Validation | PRF192 - Workshop 6 Question | Contests | HackerRank
not valid
Contest ends in
25 minutes
Submissions:
16
Max Score:
40
Difficulty: Easy
C
⚙
1 ▾#include <stdio.h>
2 #include <string.h>
3 #include <math.h>
4 #include <stdlib.h>
5
6 ▾int main() {
7
8 ▾ /* Enter your code here. Read input from STDIN. Print output to STDOUT */
9 ▾ char s[100];
10 gets(s);
11 ▾ if((s[0] == '(' && s[4] == ')' && s[5] == ' ') ||(s[3] == '-' && s[7] == '-'))
12 printf("valid");
13 else
14 printf("not valid");
15 return 0;
16 }
17
Line: 1
Col: 1
Contest Calendar
|
Interview Prep
|
Blog
|
Scoring
|
Environment
|
FAQ
|
About Us
|
Support
|
Careers
|
Terms Of Service
|
Privacy Policy
|
Request a Feature
https://www.hackerrank.com/contests/prf192-workshop-6/challenges/phone-number-validation 2/2