Wednesday 25 July 2018

Question: Pranav and Change
 
Pranav, an enthusiastic kid visited the "Fun Fair 2017" along with his family. His father wanted him to purchase entry tickets from the counter for his family members. Being a little kid, he is just learning to understand about units of money. Pranav has paid some amount of money for the tickets but he wants your help to give him back the change of Rs. N using minimum number of rupee notes.

Consider a currency system in which there are notes of seven denominations, namely, Rs. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100. If the change given to Pranav Rs. N is input, write a program to computer smallest number of notes that will combine to give Rs. N.


Note:
Refer to problem specifications.

Input Format:
First line of the input is an integer N, the change to be given to Pranav.

Output Format:
Output should display the the smallest number of notes that will combine to give N.
Refer sample input and output for formatting specifications.

Sample Input 1:
1200

Sample Output1:
12

Sample Input 2:
242

Sample Output2:
7


Solution:
 #include<stdio.h>
int main()
{
    int n,n1,n2,n3,n4,n5,n6;
    scanf("%d",&n);
    n1=n/100;   n=n%100;
    n2=n/50;    n=n%50;
    n3=n/10;    n=n%10;
    n4=n/5;     n=n%5;
    n5=n/2;     n=n%2;
    n6=n;
    printf("%d",n1+n2+n3+n4+n5+n6);
    return 0;
}

13 comments:

  1. Replies
    1. // You are using Java
      import java.io.*;
      import java.util.*;
      import java.lang.*;
      class Main
      {
      public static void main(String args[])
      {
      Scanner sc=new Scanner(System.in);
      int a=sc.nextInt();
      int a1,a2,a3,a4,a5,a6,sum;
      a1=a/100;
      a=a%100;
      a2=a/50;
      a=a%50;
      a3=a/10;
      a=a%10;
      a4=a/5;
      a=a%5;
      a5=a/2;
      a=a%2;
      a6=a;
      sum=a1+a2+a3+a4+a5+a6;
      System.out.println(sum);
      }
      }

      Delete
    2. explain pls

      Delete
  2. Replies
    1. #include
      int main()
      {
      int n,n1,n2,n3,n4,n5,n6;
      scanf("%d",&n);
      n1=n/100; n=n%100;
      n2=n/50; n=n%50;
      n3=n/10; n=n%10;
      n4=n/5; n=n%5;
      n5=n/2; n=n%2;
      n6=n;
      printf("%d",n1+n2+n3+n4+n5+n6);
      return 0;
      }

      Delete
  3. #
    #
    n=int(input(""))
    x1=n/100
    a=int(x1)
    n=n%100
    x2=n/50
    b=int(x2)
    n=n%50
    x3=n/10
    c=int(x3)
    n=n%10
    x4=n/5
    d=int(x4)
    n=n%5
    x5=n/2
    e=int(x5)
    n=n%2
    x6=n
    f=int(x6)
    k=int(a+b+c+d+e+f)
    print(f'{k}')

    ReplyDelete
  4. using python please

    ReplyDelete

Random password generator in Java

       Random password generator in Java Source code: mport java.io.*; import java.util.*; public class Main { public static void main(Str...