Write algorithm to return change in denominations of 10$, 5$, 1$, 25 cents, 10 cents
double deno[]= {10, 5, 1, 0.25, 0.10, 0.05, 0.01};
//Scanner reader = new Scanner(System.in);
float cost = 67.9500f;
float cash = 100.00f;
float change = cash-cost;
System.out.println(change);
for(int i=0;i
=1)
{
}
}
#include
#include
#include
#include
using namespace std;
/* Function declarations */
void giveTheChange(int dollar, int cents, vector &inDollar, vector &inCent);
void process(int &sum,vector &denom,bool dollar);
/* Function definitions */
void giveTheChange(int dollar, int cents, vector &inDollar, vector &inCent){
/* Find minmum number of dollars needed to give the change */
int sum=dollar;
Business Unit/Tier 3 (Optional) | Practice Group/Tier 4 (Optional)
Proprietary & Confidential (Optional) | Legal Disclaimer (Optional)
int centsLeft;
int sumCent=cents;
process(sum,inDollar,true);
if(sum!=0){
centsLeft=sum*100;
sumCent+=centsLeft;
}
process(sumCent,inCent,false);
}
void process(int &sum,vector &denom,bool dollar){
while(sum!=0 && denom.size()!=0)
{
if(denom.back()<= sum )
{
sum-=denom.back();
if(dollar)
cout<<"$"< inDollar(dollarArray,dollarArray+sizeof(dollarArray)/sizeof(int));
sort(inDollar.begin(), inDollar.end());
vector inCent(centArray, centArray+sizeof(centArray)/sizeof(int));
Business Unit/Tier 3 (Optional) | Practice Group/Tier 4 (Optional)
Proprietary & Confidential (Optional) | Legal Disclaimer (Optional)
sort(inCent.begin(), inCent.end());
cout<<"Enter the amount that you wanna make change "<
>dollar ; cout<<" "; cin >>cents;
cout<>key;
return 0;
}
__________________________________*********************************______________________
Find the no, of days from 1st Jan to the date entered
// considering only 28 days in feb
initial_date = 01;
initial_month = 01;
initial_year = 2011; // lets say
target_date //
target_month //
target_year //
days = 0;
days += (target_year - initial_year )*365;
day = {0,31,28,31,30,31,30,31,31,30,31,30,31};
while(target_month > initial_month)
{
days += day[initial_month];
initial_month++;
}
days += target_date -01;
cout<public static int check(int n1,int n2,int n3)
{
count++;
if(n1+n2==n3)
{
System.out.println(n1+"+"+n2+"="+n3);
return 1;
}
else if(n2 + n3 == n1)
{
System.out.println(n2+"+"+n3+"="+n1);
return 2;
}
else if(n1+n3==n2)
{
System.out.println(n1+"+"+n3+"="+n2);
return 3;
}
else
return 0;
}
public static void main(String args[])
{
String f = "17512";
int n = f.length()/2;
System.out.println(n);
for(int i=0;i
_______________________________************************************______________________
Given a string...replace all occurances of a with the.
#include
#include
using namespace std;
int main()
{
string s = "I am a boy.";
string temp;
cout<String[] ans = printAlphabet(410292);
for (String str : ans) {
}
System.out.println(str);
if (num >= 0 && num < 10){
static String[] printAlphabet(int num){
String[] retStr;
if (num == 0 || num ==1){
} else {
retStr = new String[]{""};
retStr = new String[keypad[num].length()];
for (int i = 0 ; i < keypad[num].length(); i++){
}
retStr[i] = String.valueOf(keypad[num].charAt(i));
}
return retStr;
}
String[] nxtStr = printAlphabet(num/10);
int digit = num % 10;
String[] curStr = null;
if(digit == 0 || digit == 1){
} else {
curStr = new String[]{""};
curStr = new String[keypad[digit].length()];
for (int i = 0; i < keypad[digit].length(); i++){
}
curStr[i] = String.valueOf(keypad[digit].charAt(i));
}
String[] result = new String[curStr.length * nxtStr.length];
int k=0;
for (String cStr : curStr){
for (String nStr : nxtStr){
}
result[k++] = nStr + cStr;
}
return result;
}
---------------------------------------------------------------------*******************************************------------------------------------------
Business Unit/Tier 3 (Optional) | Practice Group/Tier 4 (Optional)
Proprietary & Confidential (Optional) | Legal Disclaimer (Optional)
Print Fibonacci Series
void main()
{
cin>>n;
cout<
>n;
cout<}
int fibo(int n){
if(n==0) return 0;
if(n==1) return 1;
else return(fibo(n-1)+fibo(n-2));
}
}
______________________________*************************__________________________________
_
Palindrome Date: A date is said to be a palindrome when it is expressed in MMDDYYYY format, it reads the
same both ways. Given 2 years as input(ex: 2000, 2010), print out all the dates which are palindrome dates.
public class PalindromeDate {
public static void main(String[] args) {
printDates(1000, 3010);
}
public static void printDates(int start, int end) {
int[] daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
for (int year = start; year <= end; year++) {
String yyyy = Integer.toString(year);
String mm = Integer.toString(year%10)+Integer.toString((year/10)%10);
String dd = Integer.toString((year/100)%10)+Integer.toString((year/1000)%10);
int m = Integer.parseInt(mm);
int d = Integer.parseInt(dd);
if (m > 0 && m < 13) {
if (d > 0 && d <= ((m-1 != 2)? daysInMonth[m-1]: (year%4 != 0)?28:29)) {
System.out.println(mm+dd+yyyy);
}
}
}
}
}
________________________________*********************_________________________________
Business Unit/Tier 3 (Optional) | Practice Group/Tier 4 (Optional)
Proprietary & Confidential (Optional) | Legal Disclaimer (Optional)