Posts

Showing posts from March, 2024

Capitalizing Function

  #include <iostream> using namespace std; //If you know the difference between ASCII values of small and capital letters. char convert1(char name) {     char ans=name-32;     return ans; } //If you do  not know the difference between ASCII values of small and capital letters. char convert(char name) {     char ans=name-'a'+'A';     return ans; } int main() {     char name;     cout<<"Give the letter:-\n";     cin>>name;     cout<<convert1(name)<<endl;     cout<<convert(name); }

Prime Numbers and Factorial function

 #include <iostream> using namespace std; int Prime(int num) {     if (num<2)     {         return 0;     }     if (num==2)     {         return 1;     }     for (int i=2;i*i<=num;i++)     {         if (num%i==0)         {             return 0;         }     }     return 1; } int Factorial(int num) {     int fact=1;     for (int i=1;i<=num;i++)     {        fact*=i;      }     return fact; } int main() {     int a,b;     cout<<"Input two numbers:-\n";     cin>>a>>b;     cout<<a<<" is "<<(Prime(a)? "a prime":"not a prime ")<<" number."<<endl;     cout<<b<<" is ...