My Professional Profile

I am Johnson Augustine Sr.Software Engineer and System Architect. I have 10 Yrs of hands on expertise in ASP.net MVC 5 , Angular 5 , C# MVC Razor, WPF MVVM , Android , IOS Swift 3 , IOS11 MSSQL,MySQL Database,,PHP,C/C++/Visual C++/G++/QT++,Com,DirectX,Open CV,EMGU CV , embedded System Development , [Raspberry PI]. ,html,Javascript,Jquery,Ajax.CSS , Networking ,Cyber security, Ethical Hacking You can see my professional profile at http://linkedin.com/in/johnsontaugustine Email : johnsonaugustine@live.com

Saturday, 19 January 2013

C Development




Write a program that accepts a rupee amount(less than one thousand) and computes the number of HUNDRED, FIFTY, TWENTY, TEN, FIVE, TWO  and ONE rupee currencies needed for that amount. Your solution must use the *fewest* number of currencies that are possible for the given rupee amount.
[You may assume that the input is an integer amount greater than 0.]

Eg. Input : 346

Output : HUNDRED-3, TWENTY-2, FIVE-1, ONE-1


Code : by Johnson

#include<stdio.h>
#include<conio.h>
void main()
{
  int c,c1,changes[7],a[7]={100,50,20,10,5,2,1},i=0;
clrscr();
 printf("Enter amount ");
 scanf("%d",&c);
 while(c>0)
 {
   c1=c;
   c=c%a[i];
   changes[i]=(c1-c)/100;
   i++;
 }

 for(j=0;j<7;j++)
 {
  if(changes[j]>0)
   {
   printf("Currencies of a[j]= %d \n" changes[j]);
  }
}
 
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.