Data Structure lab 1

Task 1:
Write a Program to enter three integers and output the smallest integer using IF.

#include <iostream>
using namespace std;
void smallest(int a,int b, int c);
int main()
{
            int a,b,c;
            cout<<"Enter 3 numbers"<<endl;
            cin>>a;
            cin>>b;
            cin>>c;
            smallest(a,b,c);
            system("pause");
}
void smallest(int a, int b, int c)
{
           

            if (a<b && a<c)
            {
                        cout<<"This is the smallest number ="<<a;
            }
             else if (b<a && b<c)
            {
                        cout<<"This is the smallest number ="<<b;
            }
            else if (c<a && c<b)
            {
                        cout<<"This is the smallest number ="<<c;
            }
            else
            {
                        cout<<"all numbers are equal";
            }

}

 Task2:Write a Program to enter 10 integers in a single-dimension array and then print out the array in ascending order.

#include<iostream>
using namespace std;
void arrayreturn(int a[3]);
int main()
{
                            int arr[5];
                            for (int i=0;i<5;i++)
                            {
                                    cout<<"enter number"<<i+1<<" ";
                                    cin>>arr[i];
                            }
                            arrayreturn(arr);
                            system("pause");
}
void arrayreturn(int a[5])
{
                            int temp;
                            for (int i=0;i<5-1;i++)
                            {
                                    for (int j=0;j<5-1;j++){
                                    if (  a[j]>a[j+1]){
                                                temp=a[j];
                                        a[j]=a[j+1];
                                                a[j+1]=temp;
                                    }
                            }

}
                            for (int k=0;k<5;k++)
                            cout<<a[k]<<endl;
}

Task 3:

Write a program to create structure named student. Take information of student from user as input (StdID, StdName, StdAge etc.) Display the output.
#include<iostream>
using namespace std;
using namespace std;
struct student{
            int id;
            string name;
            int age;
};
int main()
{
           
            student std;
           
            cout<<"ENter ID ";
            cin>>std.id;
cout<<"ENter NAme ";
            cin>>std.name;
cout<<"ENter Age ";
            cin>>std.age;
 
            cout<<" Name: "<<std.name<<endl;
    cout<<"Age: "<<std.age<<endl;
            cout<<"ID: "<<std.id<<endl;
            system ("pause");
}

Task 4:

#include<iostream>
#include <string>
using namespace std;
struct student{
                              int id;
                              string name;
                              int age;
};
int main()
{
                              int *ptr_id;
                              string *ptr_name;
                              int *ptr_age;
                              student std;
                                    cout<<"ENter ID ";
                              cin>>std.id;
                              ptr_id=&std.id;
                              cout<<"ENter NAme ";
                              cin>>std.name;
                              ptr_name=&std.name;
                              cout<<"ENter Age ";
                              cin>>std.age;
                             
    ptr_age=&std.age;
                                    cout<<" Name: "<<*ptr_name<<endl;
    cout<<"Age: "<<*ptr_age<<endl;
                              cout<<"ID: "<<*ptr_id<<endl;
                              system ("pause");
}

Comments

Popular posts from this blog

Computer Programming Lab 5

Computer Programming lab 11

Computer Programming Lab 4