Diwali or Deepavali is the Hindu festival of lights celebrated every year in autumn in the northern hemisphere.
Mayank is excited about Diwali and he asked for money from his dad for buying crackers. His dad told him that he will be giving him money in splits and will give money every day in a split amount so that on the day before Diwali, Mayank will have the total money to buy the crackers.
Everybody has his savings so Mayank has saved some coins. Let's assume that he saved “a” coins and his dad will give every day split money that is “k” coins every day. So Diwali is on “nth” day.
Mayank is very busy in preparation for Diwali, so he asked you to tell him that how much money he will have on an nth day so that he will know whether he can buy the crackers on an nth day or not.
Example:
Input: a = 10, n = 3, k = 5
Output: 22
Approach
C++
#include <bits/stdc++.h>using namespace std;int diwaliCelebration(int a, int n, int k){int ans = a + n * (k - 1);return ans;}int main(){int a = 10, n = 3, k = 5;cout << diwaliCelebration(a, n, k) << "\n";return 0;}
Approach
Java
public class DiwaliCelebration {public static void main(String[] args) {int a = 10, n = 3, k = 5;System.out.println(diwaliCelebration(a, n, k));}static int diwaliCelebration(int a, int n, int k) {int ans = a + n * (k - 1);return ans;}}
Read Interview Questions
Exception Handling Interview Questions
DBMS Interview Questions Set -1
DBMS Interview Questions Set -2
JPA Interview Questions Set -1
Spring Boot Interview Questions Set 1
Spring Boot Interview Questions Set 2
i want in java code this pblm.......
ReplyDelete