Write a program using any programming language that reads five numbers from keyboard and display the smaller,larger and average of those numbers.

Write a program using any programming language that reads five numbers from keyboard and display the smaller,larger and average of those numbers.

Bangladesh Development Bank

Senior Officer (IT)

Written Test – 2017

#include <iostream>
#include<stdio.h>

using namespace std;

int main()
{
    int i,n,max,min,total,sum;
    float avg;
    printf("Enter Total number of elements \n");
    cin>>total;
    cout<<"Enter number \n";
    cin>>n;
    max=n;
    min=n;
    sum=n;
    for(i=1;i<=total-1;i++)
    {
        cin>>n;
        if(n>max)
        max=n;
        else if(n<min)
        min=n;
        sum+=n;
    }
    printf("\n The largest number is %d",max);
    printf("\n The smallest number is %d",min);
    printf("\n The average number is %f",avg=(sum/total));
    return 0;
    
}

Enter Total number of elements

4

Enter numbers

22,33,23,31

The largest number is 33

The smallest number is 223

The avg number is 27.000000

Write a program using any programming language that reads five numbers from keyboard and display the smaller,larger and average of those numbers.

A program sorts an array of integer. Write down the code that tests the sorting algorithm of written in a program.

Combined Bank(HBFC and KB)

Assistant Programmer-2018

Description: given array of size number, write a program to check if it is sorted in Ascending order or not.

Description: given array of size number, write a program to check if it is sorted in Ascending order or not.

Input: 10, 11,12,13,14

Output: True

Input: 20, 21,22,23,24

Output: True

Input: 20, 11.19,13,12

Output: False

Source code

#include <bits/stdc++. h>

#include <iostream>

using namespace std;

int sortTest (int arraList[], int nunber)

{

    int i;

        if(nunber==1 || nunber==0)

        return true;

        for(i=0;i<nunber;i++)

        if(arraList[i-1]>arraList[i])

        return false;

    return true;

}

int main()

{

    int arraList[5] = {1,2,4,6,7};

    int number=5;

    if(sortTest(arraList,number))

    cout<<“True”;

    else

    cout<<“True”;

}
Anaconda 3: Opencv installation and solution during installation.

Anaconda 3: Opencv installation and solution during installation.

The uses of OpenCv

  • To Load and read image on Notebook
  • extract feature from an image
  • extract features from images under a given root path
  • How to make a prediction under reference images

The steps to import cv2 library on jupyter Notebook

  1. Open Jupyter Notebook
  2. import cv2 (if this show error)

Then try to open CMD and check your python version.

command:

python -v

for conda version command as :

conda -V

install opencv2 command it:

conda install -c conda-forge opencv

hit enter and wait for some times…

If there is no problem during installation no error will show and need to restart to import cv2 and work…

but if show any environmental problem then following the tutorial update conda command in cmd like:

conda update conda

This installation takes several times so need to wait till download and install .

Next, again command as :

conda install -c-forge opencv

Hit Enter key !

This also take several times!

Finally, install opencv2 again go to jupyter notebook and import again cv2.

bravo !! Works finely.

TCP and UDP concept with real example in computer network.

TCP and UDP concept with real example in computer network.

TCP and UDP overview

TCP and UDP or TCP over IP or TCP/IP both are protocols. They are the transport layer protocol. TCP is a connection-oriented protocol, on the other hand UDP is a connectionless protocol. Both of them are protocols used for sending bits of data. This is known as packets over the Internet. 

They both build on top of the Internet protocol. TCP and UDP are not the only protocols that work on top of IP. Yet, they are the most widely used. Besides, whether you are sending a packet via TCP or UDP, that packet is sent to an IP address. These packets are pickled correspondingly, as they are accelerated from your computer to intermediary routers and on to the end point. The widely used term known as “TCP/IP” mean as to TCP over IP. UDP over IP could just as well be referred to as “UDP/IP”, but this is not a common term.

TCP

TCP stands for Transmission Control Protocol. 

TCP Communication between source to destination computer:

When you want to load a web page, your computer sends TCP packets to the web server’s address. During this asking it to send the web page to you. The web server responds by sending a stream of TCP packets. This is your web browser sews up together to form the web page and display it to you.

When you click a link, sign in, post, or a comment, or do anything else, your web browser sends TCP packets to the server. In additionally, the server sends TCP packets back. TCP is not just one way communication. The remote system sends packets back to acknowledge it is received your packets.

TCP guarantees the recipient will receive the packets accordingly by numbering them. The recipient sends messages back to the sender saying it received the messages. If the sender does not get a correct response, it will resend the packets. This process is use to ensure the recipient received them.

Packets are also checked for errors. This reliability is that packets sent with TCP are tracked so no data is lost or corrupted in transit. This is why file downloads do not become corrupted even so there are network hiccups. If the recipient is completely offline, your computer will give up. Additionally you will see an error message saying it cannot communicate with the remote host.

 

UDP

UDP stands a datagram is the same thing as a packet of information. The UDP protocol works similarly to TCP, though it tosses all the error-checking stuff out. All the back-and-forth communication and deliverability guarantees slow things down.

UDP Communication between source to destination computer:

When using UDP, packets are just sent to the recipient. The sender will not wait to make sure the recipient received the packet; it will just continue sending the next packets. If you are the recipient and you miss some UDP packets, you cannot ask for those packets again. There is no guarantee you are getting all the packets and there is no way to ask for a packet again if you miss it. But losing all this overhead means the computers can communicate more quickly. UDP is used when speed is desirable and error correction is not necessary. For instance, it is frequently used for live broadcasts and online games.

TCP vs UDP or Difference between TCP and UDP protocol

TCP(Transmission Control Protocol)

  • TCP establishes connection between the computers before transmitting the data
  • Connection Oriented type protocol
  • Speed is slow
  • Highly Reliable
  • Header size is 20Bytes
  • It takes acknowledgement of data and has the ability to retransmit, if the user requests.

UDP(User Datagram Protocol)

  • UDP stands the data directly to the destination computer without checking the system is ready or not.
  • Connection type is connectionless
  • Fast in speed
  • Unreliable
  • Header is 8Bytes
  • Neither it takes acknowledgement nor it retransmits the lost data.

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 109 ( SCUD Busters) :

This problem is UVA uhunt book chapters (Computational Geometry problem) category problem.

link: http://uva.onlinejudge.org/external/1/109.html

 

Problem Description:

Find each convex hull for each area then select that convex hull whether a Missile falls inside it.Make aggregation of the area among the selected convex hull.

 

Problem Solution:

#include <bits/stdc++.h>

#include <math.h>

using namespace std;

int main()

{

double x1,x2,x3,y1,y2,y3,d,e,h,k,r,g,f,c,a;

char selectA,selectB,selectC;

while(scanf(“%lf %lf %lf %lf %lf %lf”,&x1,&y1,&x2,&y2,&x3,&y3)==6)

{

g=((x1*x1+y1*y1-x3*x3-y3*y3)*(y1-y2)-(x1*x1+y1*y1-x2*x2-y2*y2)*(y1-y3))/(2*(x1-x2)*(y1-y3)-2*(x1-x3)*(y1-y2));

f=((x1*x1+y1*y1-x2*x2-y2*y2)*(x1-x3)-(x1*x1+y1*y1-x3*x3-y3*y3)*(x1-x2))/(2*(x1-x2)*(y1-y3)-2*(x1-x3)*(y1-y2));

c=-(x1*x1+y1*y1+2*g*x1+2*f*y1);

h=-g;

k=-f;

r=sqrt(g*g+f*f-c);

if(h<0)

{

selectA=’+’;

h=-h;

}

else

{

selectA=’-‘;

}

if(h==0)

{

selectA=’+’;

h=-h;

}

if(k<0)

{

selectB=’+’;

k=-k;

}

else selectB=’-‘;

if(k==0)

{

selectB=’+’;

k=-k;

}

printf(“(x %c %.3f)^2 + (y %c %.3f)^2 = %.3f^2\n”,selectA,h,selectB,k,r);

if(g<0)

{

selectA=’-‘;

g=-g;

}

else

{

selectA=’+’;

}

if(g==-0)

{

selectA=’+’;

g=-g;

}

if(f<0)

{

selectB=’-‘;

f=-f;

}

else

{

selectB=’+’;

}

if(f==-0){

selectB=’+’;

f=-f;

}

if(c>0) selectC=’+’;

else

{

selectC=’-‘;

c=-c;

}

printf(“x^2 + y^2 %c %.3fx %c% .3fy %c %.3f = 0\n\n”,selectA,2*g,selectB,2*f,selectC,c);

}

return 0;

}

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 476 (Points in Figures Rectangles) Solution

UVA Problem 476 (Points in Figures Rectangles) :

This problem is UVA uhunt book chapters (Computational Geometry problem) category problem.

Details link: http://uva.onlinejudge.org/external/1/476.html

 

Problem Description:

This is a straightforward problem.

#include<bits/stdc++.h>

using namespace std;

int main()

{

    double x1[10],y1[10],x2[10],y2[10],X,Y;

    char ch;

    int index=0,p_no=1,fig;

    while(1)

    {

        cin>>ch;

        if(ch=='*') break;

        cin>>x1[index]>>y1[index]>>x2[index]>>y2[index];

        index++;

    }



   while(scanf("%lf %lf",&X,&Y)==2)

   

    {

        if(X==9999.9&&Y==9999.9) break;



        bool f=false;

        for(fig=0;fig<10;fig++)

        {

            if(X>x1[fig]&&X<x2[fig]&&Y>y2[fig]&&Y<y1[fig])

            {

                printf("Point %d is contained in figure %d\n",p_no,fig+1);



            f=true;

            }

        }

        if(f==false) printf("Point %d is not contained in any figure\n",p_no);

        p_no++;

    }

    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 640 ( Self Numbers) Solution

UVA Problem 640 ( Self Numbers): Is a basic UVa problem.

Details link:

 

Problem Details:

This is a Straightforward problem.

 

problem solution:

#include <stdio.h>

#include <math.h>



int d[1000010];



int generator(int num)

{

    int sum = num;

    while(num > 0)

    {

        sum += num%10;

        num /= 10;

    }

    return sum;

}



int main()

{

    int i;

//for(i=1;i<=100;i++)

    for(i=1;i<=1000000;i++)

    {

        if(d[i] == 0)

            printf("%d\n",i);

        d[generator(i)] = 1;

    }



    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10137 (The trip) Solution

 

#include <bits/stdc++.h>



using namespace std;

double arr[1020];

int main()

{

//    double P=0,N=0,F,S,T;

    int n,i,j;

    while(cin>>n && n)

    {

        double avg=0;

        for(i=0;i<n;i++)

        {

           

            scanf("%lf",&arr[i]);

            avg += arr[i];

        }

        avg /= n;

        double P = 0, N = 0;

        for( j = 0; j < n; j++)

        {

            double res = (long) ((arr[j] - avg) * 100.0) / 100.0;

            if(res> 0)

             P += res;

            else

             N += res;

        }

        N = -N;

        if(N>P)

        printf("$%.2f\n", N );

        else

        printf("$%.2f\n",P);

    }

    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10221 ( Satellites) Solution

#include<bits/stdc++.h>

#define PI acos(-1)

using namespace std;





int main ()

{

  double dis_of_sate ,angle,r;

   char s[4];

   while(cin>>dis_of_sate>>angle>>s) // circle (arc) length s=r*theta. (chord) length = 2*rsin(C/2)

   {

       if(s[0]=='m') angle/=60;

       if(angle>180)

       angle=360-angle; // tribhujer kono kon 180 er boro hoy na

       r=dis_of_sate + 6440;

       angle=PI*angle/180;

  

    printf("%.6lf %.6lf\n",r*angle,2*r*sin(angle/2));

}

    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10286 (Trouble with a Pentagon) Solution

 

#include <bits/stdc++.h>

#include <math.h>

#define pi acos(0.0)

//#define pi 3.1416

int main()

{

double n;



while(scanf("%lf",&n) != EOF )

{

    //poligon_inte_angle = (3/5)*180=(108 degree)as figure sides n=5;

    //square_inte_angle  = (2/4)*90=(63 degree) as figure sides n=4;

printf("%.10lf\n",( n*sin(108*pi/90 ) / sin(63*pi/90) ));//* pi/90



}



return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVa Problem 10347 ( Medians) Solution

 

#include <bits/stdc++.h>

#include <math.h>



using namespace std;



int main()

{



 double  a,b,c,ans,s;



 while(scanf("%lf %lf %lf",&a,&b,&c) == 3 )

 {



 s=(a+b+c)/2;

 ans=sqrt(s*(s-a)*(s-b)*(s-c));

 if(ans>0)

 printf("%.3lf\n",ans*(4.0/3.0));

 else

 {

 ans=-1;

 printf("%.3lf\n",ans);

 }

 }



return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10451 (Ancient Village Sports) Solution

 

 

#include <bits/stdc++.h>

#include<iostream>

#include<math.h>

#define pi 2*acos(0.0)



using namespace std;



int main()

{

double n,x,y,a,R,r,A,A1,A2,spect,offic;



int c=0;



while(scanf("%lf %lf",&n,&A)==2 && n>=3)

{



r=sqrt((2*A)/(n*sin(2*pi/n))); //2. Given the radius (circumradius); area(A)=((r^2)nsin(360/n)/2)

R=sqrt( A/(n*tan(pi/n))); //Given the apothem (inradius) area=a^2 ntan(180/n);

                             //printf("Case %d: %.5lf %.5lf\n",i,R,r);

A1=pi*r*r;

A2=pi*R*R;



spect = A1-A;

offic = A-A2;



printf("Case %d: %.5lf %.5lf\n",c+1,spect,offic);



c++;



}   

     return 0 ;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10522 Solution

 

 

#include <bits/stdc++.h>

#include <cmath>



using namespace std;



int main()

{

  int tc;

  cin>>tc;

 

  while (tc) {

     

    double ha, hb, hc,a,b,c;//s,s1,a1,b1,c1,a,b,c;

    scanf("%lf%lf%lf", &ha, &hb, &hc);

    

     

         a=1/ha,b=1/hb,c=1/hc;

      double s1=(a + b + c);

      double a1=(-a + b + c);

      double b1=(a - b + c);

      double c1=(a + b - c);

      double s=s1*a1*b1*c1;

       if (s <= 0)

        {

        printf("These are invalid inputs!\n");

        tc--;

          }

       else if (ha == 0 || hb == 0 || hc == 0)

      {

       printf("These are invalid inputs!\n");

       tc--;   

      }

      else {

        printf("%.3f\n", 1 / sqrt(s));

      }

     

     

    }

 

  return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10573 Solution

 

 

#include <bits/stdc++.h>

#define PI 2*acos(0)



using namespace std;



int main()

{

    int n,tc,i,j;

    char t[2];

    cin>>tc;

    while(tc--)

    {

        int a,b;

        cin>>a;

        if(getchar()=='\n')

       {

        printf("%.4lf\n", (2*a*a*PI)/16);

        }

        else

        {

        cin>>b;

        printf("%.4lf\n", 2*a*b*PI);

        }

    }

    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10589 (Area) Solution

 

 

#include <bits/stdc++.h>



using namespace std;



int main()



{

    int N,a,M,rr;

   

    double x,y;

   

    while(scanf("%d %d",&N,&a)!=EOF && N)

    {

        bool f = true;

        M = 0;

        rr = a*a;

       

        for(int i = 0;i<N;++i)

        {

            scanf("%lf %lf",&x,&y);

           

            f = true;

           

            if((x-0)*(x-0)+(y-0)*(y-0)>rr)   //(x1,y1)(x2,y2) bindu gula: (0,0)(0,0)

            f = false;                        //(0,a)(0,a);(a,0)(a,0);(a,a)(a,a)

            if((x-0)*(x-0)+(y-a)*(y-a)>rr)

            f = false;

            if((x-a)*(x-a)+(y-0)*(y-0)>rr)

            f = false;

            if((x-a)*(x-a)+(y-a)*(y-a)>rr)

            f = false;

           

            if(f)

            {

                M++;

            }

        }

       

        printf("%.5f\n",(double)M*(a*a)/N);

    }

   

    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10991(Region) Solution

 

 

#include<bits/stdc++.h>

#include <iostream>

#include<math.h>



using namespace std;



int main()

{



    double c1,c2,c3,a,b,c,s,ang1,ang2,ang3,arc1,arc2,arc3,area,area1,area2;

    int tc;

    scanf("%d",&tc);

    while(tc--){



        scanf("%lf%lf%lf",&c1,&c2,&c3);



        a=c1+c2;

        b=c2+c3;

        c=c1+c3;



        s =(a+b+c)/2.0;

       area1 = sqrt(s*(s-a)*(s-b)*(s-c));





        ang1 = acos((b*b+c*c-a*a)/(2*b*c));

        ang2 = acos((c*c+a*a-b*b)/(2*c*a));

        ang3 = acos((a*a+b*b-c*c)/(2*a*b));





      arc1 =(c3*c3*ang1) ;

        arc2 =(c2*c2*ang3);//arc2 =(c3*c3*ang3) ;//arc2 =(c2*c2*ang3) ;

        arc3 =(c1*c1*ang2); //arc3 =(c2*c2*ang2);*///arc3 =(c1*c1*ang2);



        area2 = (arc1 +arc2 +arc3 )/2;



        printf("%.6lf\n",area1-area2);

    }

    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10254 ( The Priest Mathematician) Solution

 

 

#include <bits/stdc++.h>



using namespace std;



int main()



{

    int s,n;

    int first_term,last_term;

   

    while (scanf("%d", &s), s != -1)

    {

        int n_sum =(int)sqrt(2*s);

       

        for (n = n_sum ; n > 0; n--)

       

         {

            if ( (2 * s + n - n * n) % (2 * n) == 0 )

           

            {

           

             first_term =  (2 * s + n - n * n) / (2 * n);

              last_term  =  first_term + n - 1;

           

            break;



            }

        }

        printf("%d = %d + ... + %d\n", s, first_term, last_term);

//    return 0*    printf("%d = %d + ... + %d\n", s, a, last_term);

    }



    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10341 – Solve It Solution

#include <cstdio>

#include <cmath>

using namespace std;

int main()

{

int T,p,q,r,s,t,u;

double lo,hi,mi,f;

while(scanf("%d %d %d %d %d %d",&p,&q,&r,&s,&t,&u)==6)

{

if(p*exp(-1)+q*sin(1)+r*cos(1)+s*tan(1)+t+u>1e-9 || p+r+u<0)

{

printf("No solution\n");

continue;

}

lo=0.0; hi=1.0;

for(int i=0;i<30;i++){

mi=(lo+hi)/2;

f=p*exp(-mi)+q*sin(mi)+r*cos(mi)+s*tan(mi)+t*mi*mi+u;

if(f>0) lo=mi;

else hi=mi;

}

printf("%.4f\n",lo);

}

return 0;



}