Showing posts with label array. Show all posts
Showing posts with label array. Show all posts

Monday, January 11, 2021

Transpose of a matrix in two dimensional array c++

 


#include<iostream>
using namespace std;
int main()
{
    int n[3][3];
    // Take input from user
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cout<<"Enter value of n["<<i<<"]"<<"["<<j<<"]"<<endl;
            cin>>n[i][j];
        }
    }
    // Show Matrix
    cout<<"Matriz is..."<<endl;
        for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cout<<n[i][j]<<"  ";
        }
        cout<<endl;
    }
    // Transpose is
    cout<<"Transpose is..."<<endl;
        for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cout<<n[j][i]<<"  ";
        }
        cout<<endl;
    }
    
    return 0;
}

Saturday, January 9, 2021

Bubble short in c++ with Eaglesoft programmer

 


#include<iostream>
using namespace std;
int main()
{
    int a[5]={3,2,5,7,8},tem;
    // show value of array before sorting 
    for(int i=0;i<5;i++)
    {
        cout<<"Value of array:"<<a[i]<<endl;
    }
    for(int i=0;i<5;i++)
    {
        for(int j=0;j<4-i;j++)
        {
            if(a[j]>a[j+1])
            {
                tem=a[j+1];
                a[j+1]=a[j];
                a[j]=tem;
            }
        }
    }

    // Show output of sorting array 
    for(int i=0;i<5;i++)
    {
        cout<<"Value of array :"<<a[i]<<endl;
    }
    return 0;
}

Wednesday, January 6, 2021

Delete Element from array in c++ with Eaglesoft programmers

 


#include <iostream>
using namespace std;
int main()
{
    int array[5] = {43256};
    int p;
    cout << "Before delete element" << endl;
    for (int i = 0i < 5i++)
    {
        cout << "Value of array[" << i << "] " << array[i<< endl;
    }
    cout << "Enter position of element that you want to delete:" << endl;
    cin >> p;
    for (int i = pi < 5i++)
    {
        array[i] = array[i + 1];
    }
    cout << "After delete element" << endl;
    for (int i = 0i < 4i++)
    {
        cout << "Value of array[" << i << "] " << array[i<< endl;
    }
    return 0;
}

Insertion in array in c++ with Eaglesoft Programmers

 


#include<iostream>
using namespace std;
int main()
{
    int array[100]={4,5,6,7,32};
    int pos,num;
    // take value and position
    cout<<"Enter the value that you want to insert in array:"<<endl;
    cin>>num;
    cout<<"Enter the position of array where you want to insert you entred vlue: "<<endl;
    cin>>pos;

    // insert value in array
    for(int i=4;i>=pos;i--)
    {
        array[i+1]=array[i];
    }
    array[pos]=num;

    // show array value after inserting
    cout<<"new array is : "<<endl;
    for (int i=0;i<6;i++)
    {
        cout<<"Value of array["<<i<<"]: "<<array[i]<<endl;
    }


    return 0;
}

Saturday, December 26, 2020

Insert new value in array at specific location in c++ with Eaglesoft programmers.

 


#include<iostream>
using namespace std;
int main()
{
    int array[100]={4,5,6,7,32};
    int pos,num;
    // take value and position
    cout<<"Enter the value that you want to insert in array:"<<endl;
    cin>>num;
    cout<<"Enter the position of array where you want to insert you entred vlue: "<<endl;
    cin>>pos;

    // insert value in array
    for(int i=4;i>=pos;i--)
    {
        array[i+1]=array[i];
    }
    array[pos]=num;

    // show array value after inserting
    cout<<"new array is : "<<endl;
    for (int i=0;i<6;i++)
    {
        cout<<"Value of array["<<i<<"]: "<<array[i]<<endl;
    }


    return 0;
}

Search input Data from array by using binary method with Eaglesoft programmers.

 


#include <iostream>
using namespace std;
int main()
{
    int num[10] = {345672234445776};
    int s = 0l = 10midloc = 0;
    int _input;

    // run infinty time of program
    while (true)
    {
        // take input form user
        cout << "Enter a value that you want to find in array: " << endl;
        cin >> _input;

        // search data from array
        while (s <= l)
        {
            mid = (s + l) / 2;
            if (_input == num[mid])
            {
                // cout<<"Found at position: "<<mid<<endl;
                loc = mid;
                break;
            }
            else if (_input > num[mid])
            {
                s = ++mid;
            }
            else
            {
                l = --mid;
            }
        }

        // print data on screen getting from array
        if (num[loc] == _input)
        {
            cout << "Found at position: " << loc << endl;
        }
        else
        {
            cout << "Value not found in array!" << endl;
        }
        cout << "******************************************" << endl;
    }

    return 0;
}

Wednesday, December 2, 2020

Take 10 integer inputs from user and store them in an array. Again ask user to give a number. Now, tell user whether that number is present in array or not with Eaglesoft

 


#include<iostream>
using namespace std;
int main()
{
    int _input[10],c=0,n,i=0,f=0;
    
    // Take input from user
    while(c<10)
    {
        cout<<"Enter your Number "<<c+1<<" : "<<endl;
        cin>>_input[c];
        c++;
    }
    // Take test of programmer
    cout<<"Hello Programmer we are going to take a test of your knowledge"<<endl;
    cout<<"Enter a value to guess that are present in array input or not"<<endl;
    cin>>n;
    while(i<10)
    {
        if(n==_input[i])
        f=1;
        i++;
    }
    if(f==1)
    cout<<"Great you are smart programmer"<<endl;
    else
    {
        cout<<"Sorry programmer try again after drinking a cup of tea"<<endl;
    }
    // Show output that are store in an array 
    // int k=0;
    // while(k<10)
    // {
    //     cout<<"Your entered "<<k+1<<"number is: "<<_input[k]<<endl;
    //     k++;
    // }
    cout<<"*********This is Eaglesoft programmer*********"<<endl;
    return 0;
}