You are on page 1of 2

Find 3 digit greatest number.

Validate a password having total characters bet 8-10,having


#include <iostream> #include <string> Using namespace std; no special character
Int main() {
Int I, n;
Atleast one uppercase alphabet or one integer.
String s; #include <bits/stdc++.h>
Cin >> s; Using namespace std;
N = (int)s.size(); Void checkpassword(string& password)
If(n<3){ {
Cout<<-1; Int n = password.length();
Return 0; Bool hasLower = false, hasUpper = false, hasDigit = false;
} For (int I = 0; I < n; i++) {
Int maxans = (s[0]-‘0’)*100 + (s[1]-‘0’)*10 + (s[2]-‘0’); If (islower(password[i]))
Int prev = maxans; hasLower = true;
For(I = 3;i<n;i++){ if (isupper(password[i]))
Int cur = (prev%100)*10 + (s[i]-‘0’); hasUpper = true;
Maxans = max(maxans, cur); if (isdigit(password[i]))
Prev = cur; hasDigit = true;
} }
Cout<<maxans; // Displaying the strength of password
Return 0;} Cout << “Strength of password you have entered is :-“;
---------------------------------------------------------------------------------------------------------------- If ( hasUpper && hasDigit && hasLower && (n >= 6)) // considering a strong must be of
length 6 or more
GCD of set of integers in a two formats or find gcd Cout << “Strong” << endl;
recursively according to d condition..(gcd(a,b)=a if a==b else Else if ((hasLower || hasUpper) && hasDigit && (n >=6))
gcd(a,b)=gcd(a-b,b) if a>b else gcd(a,b)=gcd(a,b-a) if b>a). //when at least a lower case or uppercase is used along with digit
#include<iostream> Using namespace std; Cout << “Moderate” << endl;
Int gcd(int a, int b) { Else
If (a == 0 || b == 0) Cout << “Weak” << endl;
Return 0; }
Else if (a == b) Int main()
Return a; { cout << “Welcome, lets check your password “ << endl;
Else if (a > b) Cout << “Considering average length of a strong password should be more then 6
Return gcd(a-b, b); character “ << endl;
Else return gcd(a, b-a); Cout << “Please enter a password which should contain :- “ << endl;
} Cout << “ * at least one upper and lowercase letter “ << endl;
Int main() { Cout << “ * and also at least one digit “ << endl;
Int a = 63, b = 42; String password;
Cout<<”GCD of “<< a <<” and “<< b <<” is “<< gcd(a, b); Cout <<”Enter password”<<endl;
Return 0;} Getline(cin,password);
Checkpassword(password);
Return 0; }

Check Palindrome Number


#include <iostream> Using namespace std;
write a program to reverse a given number in c++
Int main(){
#include <iostream> Using namespace std;
Int n, num, digit, rev = 0;
Int main() {
Cout << “Enter a positive number: “;
Int n, reversed_number = 0, remainder; Cin >> num;
Cout << “Enter an integer: “; N = num;
Cin >> n; Do {
While(n != 0) { Digit = num % 10;
Remainder = n % 10; Rev = (rev * 10) + digit;
Reversed_number = reversed_number * 10 + remainder; Num = num / 10;
N /= 10; } while (num != 0);
} Cout << “ The reverse of the number is: “ << rev << endl;
Cout << “Reversed Number = “ << reversed_number; If (n == rev)
Return 0; Cout << “ The number is a palindrome.”;
} Else
Cout << “ The number is not a palindrome.”;
*Swap Numbers (Using Temporary Variable)* Return 0; }
#include <iostream> Using namespace std; Fibonacci sequence
Int main() #include <iostream> Using namespace std;
{ Int a = 5, b = 10, temp; Int main() {
Cout << “Before swapping.” << endl; Int n, t1 = 0, t2 = 1, nextTerm = 0;
Cout << “a = “ << a << “, b = “ << b << endl; Cout << “Enter the number of terms: “;
Temp = a; Cin >> n;
A = b; Cout << “Fibonacci Series: “;
B = temp; For (int I = 1; I <= n; ++i) {
Cout << “\nAfter swapping.” << endl; If(I == 1) {
Cout << “a = “ << a << “, b = “ << b << endl; Cout << t1 << “, “;
Return 0; } Continue;
}
Check Whether Number is Even or Odd using if else If(I == 2) {
Cout << t2 << “, “;
#include <iostream> Using namespace std; Continue;
}
Int main() {
nextTerm = t1 + t2;
Int n; t1 = t2;
Cout << “Enter an integer: “; t2 = nextTerm;
Cin >> n; cout << nextTerm << “, “;
If ( n % 2 == 0) }
Cout << n << “ is even.”; Return 0;}
Else
Cout << n << “ is odd.”;
Return 0;}
If(found == 0)
{
Not_found = 1;
Array Break;
#include <bits/stdc++.h> }}
Using namespace std; If(not_found == 1)
Void solve(vector<int> A) { Cout<<”\nStrings are not Anagram”;
Int b[1200], vis[1200], x = 0; Else
Cout<<”\nStrings are Anagram”;
Int n = A.size(); }
For (int I = n – 1; I >= 0; i--) { Else
If (!vis[A[i]]) { Cout<<”\nCharacter count Mismatched!”;
B[x] = A[i]; Cout<<endl;
Return 0;}
X++;
Vis[A[i]] = 1; Reverse string
} #include <bits/stdc++.h>
} Using namespace std;
For (int I = x – 1; I >= 0; i--) Void reverse(string str)
Cout << b[i] << “, “; {
} If(str.size() == 0)
Int main() { {
Vector<int> A = { 1, 5, 5, 1, 6, 1 }; Return;
Solve(A); }
} Reverse(str.substr(1));
Anagram code Cout << str[0];
#include<iostream> }
#include<string.h>
Using namespace std;
Int main(){ Int main()
Char str1[20], str2[20]; {
Int len1, len2, I, j, found=0, not_found=0; String a = “Geeks for Geeks”;
Cout<<”Enter the First String: “; Reverse(a);
Cin>>str1; Return 0;
Cout<<”Enter the Second String: “;
Cin>>str2; }
Len1 = strlen(str1);
Len2 = strlen(str2);
If(len1 == len2) Take Integer Array Input and do the following.
{ a) Print array
For(i=0; i<len1; i++)
{
Found = 0;
For(j=0; j<len1; j++)
{
If(str1[i] == str2[j])
{
Found = 1;
Break;
} }

B ) separate even and odd number in an array


#include <iostream> Using namespace std;
Int main() {
Const int size = 10;
Int values[size] = {2, 3, 4, 6, 8, 5, 1, 10, 7, 9}; Check two strings are equal or not ?
Int temp; #include <iostream> Using namespace std;
For(int I = 0; I < size; i++) { Int main ()
If(values[i] % 2 == 0) { {
Continue; // declare string variables
} String str1;
For(int j = I + 1; j < size; j++){ String str2;
If(values[j] % 2 == 0) Cout << “ Enter the String 1: “ << endl;
{ Temp = values[i]; Cin >> str1;
Values[i] = values[j]; Cout << “ Enter the String 2: “ << endl;
Values[j] = temp; Cin >> str2;
} } }
// use ‘==’ equal to operator to check the equality of the string
If ( str1 == str2)
For(int I = 0; I < size; i++)
{
{ Cout << “ String is equal.” << endl;
Cout << values[i] << “ “; }
} Else
Return 0;} {
Cout << “ String is not equal.” << endl;
Program to count occurrence of a given character in a string }
#include <iostream> #include <string> Using namespace std; Return 0; }
Int count(string s, char c){
Int res = 0;
For (int i=0;i<s.length();i++)
If (s[i] == c)
Res++;
Return res;}
Int main(){
String str= “geeksforgeeks”;
Char c = ‘e’;
Cout << count(str, c) << endl;
Return 0;}

You might also like