Sunday, 17 February 2019

C++ Program to Find the largest and smallest element in an array using 1D array

#include <iostream>

using namespace std;

int main()
{
    int a[100],mx,mn,i,n;

    cout<<"Enter the number of elements\n";
    cin>>n;

    cout<<"\nEnter the array elements \n";
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }

    mx=mn=a[0];

    for(i=0;i<n;i++)
    {
        if(mx < a[i]) mx=a[i];
        if(mn > a[i]) mn=a[i];
    }

    cout<<"\nLargest Number is "<<mx;
    cout<<"\nSmallest Number is "<<mn;

    return 0;
}

OUTPUT:

Enter the number of elements
5

Enter the array elements
6
1
3
5
9

Largest Number is 9
Smallest Number is 1

C++ Program to Check whether the given number is palindrome or not

#include <iostream>

using namespace std;

int main()
{
    int n,num,m,r=0;
    cout<<"Enter The Number\n";
    cin>>n;
    num=n;
    do
    {
        m=n%10;
        r=(r*10)+m;
        n=n/10;
    }while(n!=0);

    if (num==r)
        cout<<"\n"<<num<<" is Palindrome\n";
    else
        cout<<"\n"<<num<<" is not Palindrome\n";
    return 0;
}

OUTPUTE:

Enter The Number
121

121 is Palindrome

C++ Program to Check Whether a given date is valid or not

#include <iostream>

using namespace std;

int main()
{
    int dd,mm,yy,v;
    cout<<"Enter the Date\n";
    cin>>dd>>mm>>yy;
    if((yy<0) || (mm<1) || (mm>12) || (dd>31) || (dd<1))
        v=0;
    else if(((mm==4) || (mm==6) || (mm==9) || (mm==11)) && (dd>30) )
    v=0;
    else if((mm==2) && (yy%4==0) && (dd>29))
    v=0;
    else if( (mm==2) && (dd>28))
        v=0;
    if(v==0)
        cout<<"\nDate is Invalid\n";
        else
            cout<<"\nDate is valid\n";

    return 0;
}

OUTPUT:-

Enter the Date
14
02
2019

Date is valid

Monday, 15 June 2015

How to add two numbers in c++ using class

This is for you my friends to learn about C/C++ amd much more

#include<iostream.h>
#include<conio.h>

class Add
       {
public:
int a,b;

void sum()
      {
cout<<a+b;
      }
void show()
       {
cout<<"Enter the value For adding\n";
cin>>a>>b;
getch();
       }
};
void main()
     {
clrscr();
Add obj;
obj.show();
obj.sum();
getch();
     }

Coding Format

Output Format

Thank You 
I hope you like it

Thursday, 4 June 2015

How to find square of a number using math.h header file in c++

#include<conio.h>
#include<iostream.h>
#include<math.h>

void main()
{
 clrscr();
 int sq,sum;
 cout<<"Enter the value for Squaring\n";
 cin>>sq;

 sum=pow(sq,2);

 cout<<"Square of the number is "<<sum;

 getch();

}
Coding Format

Output Format

Monday, 25 May 2015

How to find factorial of a number in c++

#include<iostream.h>
#include<conio.h>

void main()
  {
    clrscr();
    int n,m=1;
    cout<<"Enter the number to cal. Factorial\n";
    cin>>n;

    for(int i=1;i<=n;i++)
     {
     m=m*i;
     }

     dcout<<m;
     getch();
   }
    
Coding Format

Output Format

       

Friday, 22 May 2015

How to print numbers from 1-10 in while loop in c++

#include<conio.h>
#include<iostream.h>

void main()
{
 clrscr();
 int i;
 cout<<"Number from 1 to 10";
 i=1;

 while(i<=10)
{
 cout<<"\n"<<i;
 i++;
}
 getch();
}
Coding Format

Output Format


How to print numbers from 1-10 in do while loop in c++

#include<iostream.h>
#include<conio.h>

void main()
 {
    clrscr();
    int i;
    cout<<"Numbers from 1-10!";
    i=1;

    do
 {
    cout<<"\n"<<i;
    i++;
 }
    while(i<=10);

    getch();
 }
           
Coding Format

                                      
                                                                 Output Format










How to print numbers from 1-10 in for loop in c++

#include<iostream.h>
#include<conio.h>

void main()
{
 clrscr();
 cout<<"Number 1-10 are!";

 for(int i=1; i<=10; i++)
 cout<<"\n"<<i;

 getch();

}



Coding Format

Output Format

Wednesday, 20 May 2015

How to make calculator in c++

#include<conio.h>
#include<iostream.h>
void main()
{
 clrscr();
 int a,b;
 char c;
 cout<<"Enter the vslue for a and b\n";
 cin>>a>>b;
 cout<<"Enter the operators(+,-,* and /)\n";
          cin>>c;

 switch(c)
{
 case '+': cout<<a+b;break;
 case '-': cout<<a-b;break;
 case '*': cout<<a*b;break;
 case '/': cout<<a/b;break;
  default: cout<<"Wrong Input";break;

}

  getch();

}



                                                                     Coding Format
                                       

Output Format





How to add 2 numbers in C++

#include<conio.h>
#include<iostream.h>
void main()
{
 clrscr();

  int a,b,c;
  cout<<"Enter The Value For Adding\n";
  cin>>a>>b;

  c = a + b;
  cout<<" Answer = "<<c;

  getch();

}
                                                           
                                                                   Coding Format


                                                                 Output Format


How to make odd and even program in c++

#include<conio.h>
#include<iostream.h>

void main()
{
 clrscr();
 int a;
 cout<<"Enter the no. to check it is odd/even.\n";
 cin>>a;

    if(a%2==0)
     cout<<a<<"is even";

    else
     cout<<a<<"is odd";

 getch();

}



                                                                 Coding  Format

How to print "HELLO" in C++

#include<conio.h>
#include<iostream.h>

void main()

                 {  
                     clrscr();
                              cout<<"HELLO";

                                                       getch();                                                    

               

                 }

                                                                     Coding  Format    

Output  Format