(HackerRank) Write a Modular C Programming code to solve Password Validation 3, Given a password check if the passowrd is valid or invalid..
Given a password check if the passowrd is valid or invalid.
Password is valid if all the following conditions are met 1. It should have atleast eight characters in length 2. The maximum length of password must not cross 20. 3. It should have atleast one upper case character, one lower case, one digit and one special symbol.
Input Format
First Line contains a password
Constraints
1<= |password| < = 30
Output Format
Output YES if the password is valid else output NO
Sample Input 0
Sample Output 0
YES
Explanation 0
The given password meets all the three conditions given in the problem statement.
CODE:
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> int main() { int upper=0,lower=0,special=0,digit=0,i=0; char pw[30]; scanf("%s",pw); int l=strlen(pw); if(l>=8 && l<=20) { while(pw[i]) { if(pw[i]>=65 && pw[i]<=90) upper++; else if(pw[i]>=97 && pw[i]<=122) lower++; else if(pw[i]>=48 && pw[i]<=57) digit++; else special++; i++; } if(upper>0 && lower>0 && digit>0 && special>0) printf("YES"); else printf("NO"); } else{ printf("NO"); } }
OUTPUT
Congratulations, you passed the sample test case. Click the Submit Code button to run your code against all the test cases. Input (stdin) [email protected] Your Output (stdout) YES Expected Output YES
Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, Stacks, Queues, Binary Trees, MISC, Solved model question papers & Hacker Rank all solutions on the below page:
Top 100+ C Programming codes – KLE Technological University