Recent Post

Bon Appétit.c-HackerRank

Problem-Anna and Brian are sharing a meal at a restaurant and they agree to split the bill equally. Brian wants to order something that Anna is allergic to though, and they agree that Anna won't pay for that item. Brian gets the check and calculates Anna's portion. You must determine if his calculation is correct.


Solution-

#include <assert.h>

#include <ctype.h>

#include <limits.h>

#include <math.h>

#include <stdbool.h>

#include <stddef.h>

#include <stdint.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int main()

{

  int n,k,sum=0,i,sum2=0;

  int price=0,extra=0;

  scanf("%d %d",&n,&k);

  int arr[n];

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

  {

      scanf("\n%d ",&arr[i]);

  }

  int charge;

  scanf("\n%d",&charge);

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

  {

      sum=sum+arr[i];

  }

  sum2=sum-arr[k];

  price=sum2/2;

  if(price==charge)

      printf("Bon Appetit");

  else

  {

      extra=charge-price;

      printf("%d",extra);

  }

  return 0;

}


Link to the problem:-

https://www.hackerrank.com/challenges/bon-appetit/problem

Comments

  1. I just loved reading this post. Bon appetit meaning: The French phrase is used to wish someone before they start eating a meal, to tell them you hope they enjoy their food, but one shouldn't be wishing guests "bon appétit" before they dig in.

    ReplyDelete

Post a Comment

Popular posts from this blog

Caesar Cipher.c-HackerRank

Electronics Shop.c-HackerRank