Recent

Comments

Follow us on Facebook

Monday 1 January 2018

Write a program, that takes 16-Elements in Two-Dimensional-Array that has 4 rows & 4 columns, then display the diagonal of Matrix.

- No comments
Write a program, that takes 16-Elements in Two-Dimensional-Array that has 4 rows & 4 columns, then display the diagonal of Matrix.


#include<iostream>
using namespace std;
int main()
{
int arr[4][4],i,j;
cout<<"Enter elements of array: "<<endl;
                                           for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
cin>>arr[i][j];
}
}
cout<<"Daignal elements are :"<<endl;
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
if(i==j)
cout<<arr[i][j]<<"\t";
}
}
                             }

Take three values from the user and find discriminant then find the root if disc is greater than less than or equal to zero

- No comments
Take three values from the user and find discriminant then find the root if disc is greater than less
                                                       than or equal to zero

      #include <iostream>
#include <cmath>
using namespace std;

int main() {

    float a,b,c,R1,R2,disc,realPart,imgPart;
    cout<<"Enter value for a:";
    cin>>a;
    cout<<"Enter value for b:";
    cin>>b;
    cout<<"Enter value for c:";
    cin>>c;
 
 
    disc=b*b-4*a*c;
 
    if(disc>0)
{
        R1=(-b+sqrt(disc))/(2*a);
        R2=(-b-sqrt(disc))/(2*a);
        cout<<"Roots are real and different because discriminant is greater then zero '0'."<<endl;
        cout<<"R1 ="<<R1<<endl;
        cout<<"R2 ="<<R2<<endl;
    }
 
    else if(disc==0)
{
        cout<<"Roots are real and same because disciminant is equal to zero '0'."<<endl;
        R1=(-b/(2*a));
        cout<<"R1 = R2 ="<<R1<<endl;
    }

    else
{
        realPart=-b/(2*a);
        imgPart=sqrt(-disc)/(2*a);
        cout<<"Roots are complex and different because discriminant is less then zero '0'."<<endl;
        cout<<"R1 ="<<realPart<<"+"<<imgPart<<"i"<<endl;
        cout<<"R2 ="<<realPart<<"-"<<imgPart<<"i"<<endl;
    }

    return 0;
}

Write a program, that takes 12-Elements in Two-Dimensional-Array that has 3 rows & 4 columns, then Transpose of that Matrix & Display it.

- No comments
Write a program, that takes 12-Elements in Two-Dimensional-Array that has 3 rows & 4                             columns, then Transpose of that Matrix & Display it.

       #include <iostream>
using namespace std;

int main()
{
    int a[3][4],trans[4][3],i,j;



    cout<<endl<<"Enter elements of matrix: "<<endl;
    for(i=0; i<3; i++)
    {
    for(j=0; j<4; j++)
    {

        cin>>a[i][j];
    }
}

    cout<<endl<<"Entered Matrix: "<<endl;
    for(i=0; i<3; i++)
    {
        for(j=0; j<4; j++)
        {
            cout<<a[i][j]<<"\t";
        }
        cout<<endl;
    }
 
cout << endl << "Transpose of Matrix: " << endl;
    for(i=0; i<4; i++)
    {
        for(j=0; j<3; j++)
        {
            cout<<a[j][i]<<"\t";
        }
        cout<<endl;
}


}

Declare and define an array and sort the values in ascending order.

- No comments

Declare and define an array and sort the values in ascending order.

#include<iostream>
using namespace std;
main()
 {
 int i,a[10],temp,j;
 
 cout<<"Enter any 10 num in array: \n";
 for(i=0;i<=10;i++)
 {
 cin>>a[i];
 }
 cout<<"\nData before sorting: ";
 for(j=0;j<10;j++)
 {
 cout<<a[j];
 }
 for(i=0;i<=10;i++)
 {
 for(j=0;j<=10-i;j++)
 {
 if(a[j]>a[j+1])
 {
 temp=a[j];
 a[j]=a[j+1];
 a[j+1]=temp;
 }
 }
 }
 cout<<"\nData after sorting: ";
 for(j=0;j<10;j++)
 {
 cout<<a[j];
 }
 
 }

take a single dimensional array set the default values to 0 or -1, take choice from the user if a inser values the values for the array, if b update the values and if c delete values from the array.

- No comments
take a single dimensional array set the default values to 0 or -1, take choice from the user if a inser values  the values for the array, if b update the values and if c delete values from the array.
#include <iostream>
using namespace std;

int main()
{
int arr[5]={0},i,num;
char ss;
ii:

cout<<endl<<"OPTIONS: "<<endl;
cout<<endl<<"Press 'a' for inserting value in specific index."<<endl;
cout<<"Press 'b' for updating value in specific index."<<endl;
cout<<"Press 'c' for deleting value the specific index value."<<endl;

cout<<endl<<"Select option:";
cin>>ss;

cout<<endl;
switch(ss)
{
case 'a':
{

cout<<"enter index on which the number is to be add:";
cin>>i;
if(arr[i]==0)
{

cout<<"enter value to add: ";
cin>>num;
arr[i]=num;}

else
{
cout<<"selected index is not zero any more."<<endl<<endl;
}
}
break;

case 'b':
{

cout<<"enter index number which you want to update:";
cin>>i;
cout<<"enter updated value: ";
cin>>arr[i];
}
break;

case 'c':
{

cout<<"enter index number which you want to delet:";
cin>>i;
cout<<"enter 0 to delet value: ";
cin>>arr[i];

}
break;

default:
{
cout<<"Selected option is not correct...."<<endl;
cout<<"Choose the correct option from below menu:";
goto ii;
}
}
cout<<endl<<endl;
cout<<"Array elements are:";
for(int i=0; i<5; i++)
{
cout<<" "<<arr[i]<<"\t";
}
goto ii;
}

Write a program to pass array as an argument to the function.

- No comments
Write a program to pass array as an argument to the function.
#include<iostream>
using namespace std;
void display (int marks [5]);
int main()
{
int marks[5]={88,34,54,45,32};
display (marks);
return 0;
}
void display (int m[5])
{
cout<<"displaying marks "<<endl;
for (int i=0;i<5;++i)
{
cout<<"student"<<i+1<<"  "<<m[i]<<endl;
}
}

Write a program using array and swap first and last value of array.

- No comments

Write a program using array and swap first and last value of                                                       array.

# include<iostream>
using namespace std;
main()
{
int a[100],i,n,temp;
cout<<"Enter element of Array you want to insert "<<endl;
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter the element "<<i+1<<endl;
cin>>a[i];
}
temp=a[0];
a[0]=a[n-1];
a[n-1]=temp;

cout<<"After the swaming the Array Are "<<endl;
for(i=0;i<5;i++)

cout<<a[i]<<endl;
return 0;
}


Implement stack

- No comments
 Implement stack
#include<stdio.h>

#define MAX_SIZE 101

int A[MAX_SIZE]; // integer array to store the stack 
int top = -1;  // variable to mark top of stack in array

// Push operation to insert an element on top of stack. 
void Push(int x) 
{
  if(top == MAX_SIZE -1) { // overflow case. 
printf("Error: stack overflow\n");
return;
}
A[++top] = x;
}

// Pop operation to remove an element from top of stack.
void Pop() 
{
if(top == -1) { // If stack is empty, pop should throw error. 
printf("Error: No element to pop\n");
return;
}
top--;
}

// Top operation to return element at top of stack. 
int Top() 
{
return A[top];
}

// This function will return 1 (true) if stack is empty, 0 (false) otherwise
int IsEmpty()
{
    if(top == -1) return 1;
    return 0;
}

// This function is just to test the implementation of stack. 
// This will print all the elements in the stack at any stage. 
void Print() {
int i;
printf("Stack: ");
for(i = 0;i<=top;i++)
printf("%d ",A[i]);
printf("\n");
}

int main() {
  // Code to test the implementation. 
  // calling Print() after each push or pop to see the state of stack. 
Push(2);Print();
Push(5);Print();
Push(10);Print();
Pop();Print();
Push(12);Print();
}

Write a program to pass an array of structure to the function.

- No comments
Write a program to pass an array of structure to the function.
#include<iostream>
using namespace std;

struct student
{
char fname[50];
char sname[50];
int id;
unsigned int  phone;
};
void fun(student[]);
main()
{
student s[3];
for(int i=0; i<3; i++)
{
cout<<"enter the data of student"<<i+1<<endl;
cout<<"enter the 1st name of the student"<<endl;
cin>>s[i].fname;
cout<<"enter the 2nd name of the student"<<endl;
cin>>s[i].sname;
cout<<"enter the id of the student :"<<endl;
cin>>s[i].id;
cout<<"enter the phone number of the student:"<<endl;
cin>>s[i].phone;
}
fun(s);
 }
 void fun(student r[])
 {

 system("CLS");
cout<<"      name    \t      id       \t     phone  "<<endl;
for(int i=0; i<3; i++)
{
cout<<i+1<<"  "<<r[i].fname<<" "<<r[i].sname<<"  \t    "<<r[i].id<<"     \t    "<<r[i].phone<<endl;
}
}

Write a program to enter data into a structure variable of array type that has 10 elements and each record contains three fields.

- No comments
Write a program to enter data into a structure variable of array type that has 10 elements and                                                     each record contains three fields.

#include<iostream>
using namespace std;

struct student
{
char fname[50];
char sname[50];
int id;
unsigned int  phone;

};
main()
{
student s[3];
for(int i=0; i<3; i++)
{
cout<<"enter the data of student"<<i+1<<endl;
cout<<"enter the 1st name of the student"<<endl;
cin>>s[i].fname;
cout<<"enter the 2nd name of the student"<<endl;
cin>>s[i].sname;
cout<<"enter the id of the student :"<<endl;
cin>>s[i].id;
cout<<"enter the phone number of the student:"<<endl;
cin>>s[i].phone;

 }
 system("CLS");
cout<<"      name    \t      id       \t     phone  "<<endl;
for(int i=0; i<3; i++)
{
cout<<i+1<<"  "<<s[i].fname<<" "<<s[i].sname<<"  \t    "<<s[i].id<<"     \t    "<<s[i].phone<<endl;
}


}




Write a program, that takes 16-Elements in Two-Dimensional-Array that has 4 rows & 4 columns, then display the diagonal of Matrix.

Write a program, that takes 16-Elements in Two-Dimensional-Array that has 4 rows & 4 columns, then display the diagonal of Matrix. ...

propeller ads

PropellerAds