• C# Console for below logic

Hi Friends,

I need program for below logic to write c# console application

1) Input is 5 similar size tennis balls, 4 weigh exactly the same and the last one is heavier than other 4.
2) Find the heaviest ball in 3 iteration

Sriram.R
• As you know the only one ball is heavier and other 4 are same so in loop you should use this with logic.

I am writing algo for that here you can write code based on that.
//assume in one array of 5 have weight of all 5 ball
//here I am taking only 3 iteration in loop
for(int i=0;i<=3;i = i+2)
{
if(i==0)
{
if(weight[i] > weight[i+1] )
//if true then print value of weight[i] and break the loop

}

see here I am given incremental value of loop is 2
so in first iteration it is checking the 1st and 2nd ball if both are equal than it means both are the part of 4 same ball and if one is heavier than that will be answer. if not than in 2nd iteration incremental with 2 so that will check 3rd and 4th ball and if found heavier than that will be answer or if 3rd and 4th are same it means 5th ball is heavier than other

Hope you can write complete code based on this algorithm.

Regards & thanks
Arvind kumar
Visit--blog.akumars.esoftera.in

• Hi Aravind,

Am new to C# .Can u help to complete the code..

Thanks
Sriram.R

• Hi Aravind,

Am write logic for c Program.can u correct this one.

#include<conio.h>
#include<stdio.h>
void main()
{
int i,min,max,arr;
clrscr();
printf("enter 5 Size Balls:");
for(i=0;i<5;i++)
{
scanf("%d",&arr[i]);
}
min=arr;
max=arr;
for(i=1;i<5;i++)
{
if(arr[i]<min)
min=arr[i];
if(arr[i]>max)
max=arr[i];
}
printf("\n%d is Heviest Size",max);
getch();
}