Posts

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 ...

The Multiplication function and the Void function

  #include <iostream> using namespace std; int Mul(int a, int b) {     int ans=a*b;     return ans; } void Newfunc() {     cout<<"The problem is solved."; //used when no return type output is expected. } int main() {     int a, b;     cout<<"Give the numbers:\n";     cin>>a>>b;     cout<<"Their product is- \n";     cout<<Mul(a,b)<<endl;     Newfunc(); } --------------------------------------------------------------------------------------------------- Solution- Give the numbers: 10 8 Their product is-  80 The problem is solved.

Sum of two integers using functions

#include <iostream> using namespace std; int Sum(int p, int q) // Function declare {     int ans= p+q; //Function define     return ans; } int main() {     int a,b;     cout<<"Put any two numbers:\n";     cin>>a>>b;     cout<<"The sum is:- "<<Sum(a,b); }