Professional Documents
Culture Documents
21BCE2209 DSALab (A1.2)
21BCE2209 DSALab (A1.2)
21BCE2209 DSALab (A1.2)
Q1) Two friends like to pool their money and go to the ice cream parlour.
They always choose two distinct flavours and they spend all of their money.
Given a list of prices for the flavours of ice cream, select the two that will cost
Algorithm IceCreamFlavours(n,flavours[n],m)
for(i=0;i<n;++i)
for(j=i;j<n;j++)
if(flavours[i]+flavours[j]==m)
else
return 0;
Code
#include<stdio.h>
int main()
{
int i,j,m,n;
printf("Number of flavours:\n");
scanf("%d",&n);
int flavours[n];
for(i=0;i<n;++i)
scanf("%d",&flavours[i]);
scanf("%d",&m);
for(i=0;i<n;++i)
for(j=i;j<n;j++)
if(flavours[i]+flavours[j]==m)
return 0;
return 0;
}
Output
Q2) The median of a list of numbers is essentially its middle element after
sorting. The same number of elements occur after it as before. Given a list of
Algorithm MedianOfArray(n,arr[n])
j = i;
temp = arr[j];
arr[j - 1] = temp;
j--;
return 0;
Code
#include <stdio.h>
int main()
int n, i, j, temp,;
int arr[n];
scanf("%d", &arr[i]);
j = i;
temp = arr[j];
arr[j - 1] = temp;
j--;
printf("%d",arr[n/2]);
return 0;
}
Output