Write a program in c++ to check if entered 3x3 matrix is a diagonal matrix

 


Write a program in c++ to check if entered 3x3 matrix is a diagonal matrix


#include <iostream>
using namespace std;
int main()
{
    int a[3][3], flag = 0;
//Loop to enter elements of matrix    
    cout << "Enter Elements of Array : ";
    for (int i = 0i < 3i++)
    {
        for (int j = 0j < 3j++)
        {
            cin >> a[i][j];
        }
    }
// Loop to print matrix    
    cout<<"Entered Matrix : "
    for (int i = 0i < 3i++)
    {
        cout << endl;
        for (int j = 0j < 3j++)
        {
            cout << a[i][j<< " ";
        }
    }
//Loop to check for diagonal matix    
    for (int i = 0i < 3i++)
    {
        for (int j = 0j < 3j++)
        {
            if (i == j && a[i][j] == 0)
            {
                flag = 1;
                break;
            }
            else if (i != j && a[i][j] != 0)
            {
                flag = 1;
                break;
            }
        }
    }
    if (flag == 1)
    {
        cout << "\n This is not a Diagonal Matrix ";
    }
    else
        cout << "\n This is  Diagonal Matrix ";

    return 0;
}

OUTPUT

Enter Elements of Array : 12
34
23
56
45
11
67
76
54
Entered Matrix : 
12 34 23
56 45 11
67 76 54
This is not a Diagonal Matrix
Share:

Write a program in c++ to input and print 3X3 Matrix

 


Write a program in c++ to input and print 3X3 Matrix

#include <iostream>
using namespace std;
int main()
{
    int a[3][3];
    cout << "Enter Elements of Array : ";
//Loo-p to Enter Elements    
    for (int i = 0i < 3i++)
    {
        for (int j = 0j < 3j++)
        {
            cin >> a[i][j];
        }
    }
// Loop to print Matrix    
    cout<<"3x3 Matrix :"<<endl;
    for (int i = 0i < 3i++)
    {
        cout << endl;
        for (int j = 0j < 3j++)
        {
            cout << a[i][j<< " ";
        }
    }
    return 0;
}

OUTPUT

Enter Elements of Array : 12
34
56
23
45
67
11
32
87

3x3 Matrix :
12 34 56
23 45 67
11 32 87


Share:

Write a program in c++ to input 5 number and find the largest

   

Write a program in c++ to input 5 number and find the largest


#include <iostream>
using namespace std;
int main()
{
    int i;
    float a[5], sum = 0;
    cout << "Enter 5 Number : " << endl;
    for (i = 0i < 5i++)
    {
        cout << i+1 << ". ";
        cin >> a[i];
    }
    for (i = 0i < 5i++)
    {
        if (a[0]<a[i])
     
           a[0]=a[i] ;
      
    }

    cout << "\n largest number = " <<a[0];
    return 0;
}

OUTPUT

Enter 10 Number : 
1. 23
2. 56
3. 102
4. 78.4
5. 34.67

largest number = 102













Share:

Write a program in c++ to input 5 number and find the sum

  

Write a program in c++ to input 5 number and find the sum


#include <iostream>
using namespace std;
int main()
{  float a[5], sum = 0;
    int i;
    cout << "Enter 5 Number : " << endl;
    for (i = 0i < 5i++)
    {
        cout << i+1 << ". ";
        cin >> a[i];
        sum+=a[i];
    }
    
   
    cout << "\n sum = " << sum;
    return 0;
}

OUTPUT

Enter 5 Number : 
1. 23
2. 56
3. 102
4. 78.4
5. 34.67

 sum = 294.07













Share:

Write a program in c++ to input a number and check if it is prime or not

    

Write a program  in c++ to input a number and check if it is  prime or not

Prime Number : A number that is divisible only by itself and 1 (e.g. 2, 3, 5, 7, 11).

#include <iostream>
using namespace std;

int main()
{
    int numprime = 0;
    cout << "\t PROGRAM TO CHECK PRIME NUMBER";
    cout << "\n Enter A Number : ";
    cin >> num;
    if (num < 1)
        cout << "\n Number should be greater than 0";
    else if (num == 1)
        cout << "\n 1 is neither Prime nor Composite, It is a Neutral Number";
    else
    {

        for (int i = 2i <= num / 2; ++i)
        {
            if (num % i == 0)
            {
                prime = 1;
                cout << " It is not a Prime Number";
                break;
            }
        }

        if (prime == 0)
            cout << " It is a Prime Number";
        return 0;
    }
}


OUTPUT

1. 
        PROGRAM TO CHECK PRIME NUMBER
   Enter A Number : 45
   It is not a Prime Number

2. 
     PROGRAM TO CHECK PRIME NUMBER
   Enter A Number : 47
   It is a Prime Number


Share:

Write a program in c++ to input a number and print reverse of this number

   

Write a program  in c++ to input a number and PRINT REVERSE OF THIS NUMBER


#include <iostream>
using namespace std;
int main()
{
    int numrevldigit;
    cout << "Enter a Number : ";
    cin >> num;
    while (num != 0)
    {
        ldigit = num % 10;
        rev = rev * 10 + ldigit;
        num /= 10;
    }
    cout << "Reversed number is :" << rev;
   
}


OUTPUT

1. 
     Enter a Number : 23465
     Reversed number is :56432

2. 
     Enter a Number : 78654
     Reversed number is :45687



Share:

Write a program in c++ to input a number and check if it is palindrome or not

   

Write a program  in c++ to input a number and check if it is  palindrome or not

Palindrome : palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar.

#include <iostream>
using namespace std;
int main()
{
    int nnumldigitrev = 0;
    cout << "Enter a Number : ";
    cin >> n;
    num = n;
    while (num != 0)
    {
        ldigit = num % 10;
        rev = rev * 10 + ldigit;
        num /= 10;
    }
    if (rev == n)
    {
        cout << n << " is palindrome";
    }
    else
        cout << n << " is not palindrome";
}

OUTPUT

1. 
     Enter a Number : 123454321
     123454321 is palindrome

2. 
     Enter a Number : 345232
     345232 is not palindrome



Share:

Write a program in c++ to input a number and check if it is armstrong or not

  

Write a program  in c++ to input a number and check if it is  armstrong or not

Armstrong Number : Armstrong number is a number that is equal to the sum of cubes of its digits. For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers

#include <iostream>
using namespace std;
int main()
{
    int numaldigitcube = 0;
    cout << "Enter A Number : ";
    cin >> num;
    a = num;
    while (a != 0)
    {
        ldigit = a % 10;
        cube += ldigit * ldigit * ldigit;
        a /= 10;
    }
    if (cube == num)
        cout << num << " is armstrong number ";
    else
        cout << num << " is not a armstrong number";
    return 0;
}


OUTPUT

1. 
     Enter A Number : 371
     371 is armstrong number 

2. 
     Enter A Number : 476
     476 is not a armstrong number



Share:

Write a program in c++ to input a number and check for odd or even

 

Write a program in c++ to input a number and check for odd or even


#include <iostream>
using namespace std;
int main()
{
  int num;
  cout << "Enter A Number To check for EVEN or ODD : ";
  cin >> num;
  if (num % 2 == 0)
    cout << num << " is even";
  else
    cout << num << " is odd";
  return 0;
}


OUTPUT


Enter A Number To check for EVEN or ODD : 56
56 is even













Share:

Write a program in c++ to input three number and find the largest

 

Write a program in c++ to input three number and find the largest

#include <iostream>
using namespace std;
int main()
{
    int abc;
    cout << "Enter Three Number : ";
    cin >> a >> b >> c;
    if (a > b && a > c)
        cout << a << " is Largest Number ";
    else if (b > c)
        cout << b << " is Largest Number ";
    else
        cout << c << " is Largest Number ";
}


OUTPUT OF PROGRAM

Enter Three Number : 45
67
32

67 is Largest Number 


Share:

Pageviews