C Code 30 _ To Find the Number of handshakes possible between people such that a person can hand shake only once [Wipro Programming Question]
sample Input : 5sample output: 10
solving: 5 persons(a,b,c,d,e). a can give hand shake to b,c,d,e (so 4) , b can give hand shake to c,d,e (so 3) , c can give hand shake to d,e (so 2) , d can give hand shake to e (so 1) . totally 4+3+2+1 = 10 .
Program:
#include<stdio.h>
int main()
{
int n,ans;
printf("\nEnter the number of peoples : ");
scanf("%d",&n);
if(!(n<0))
{
ans=n*(n-1)/2;
printf("\n\nNumber of hand shakes possible : %d",ans);
}
else
{
printf("\n\nEnter only positive values");
}
return 0;
}
Output:
Thank You ...
0 comments: