Wednesday, January 20, 2016

Exercise given January 20, 2016

Write a small c/c++ program that accepts a 2 digit number and display/printf() its equivalent word form.


#include <stdio.h>

int main() {
char *ones[] = {"","One","Two","Three","Four","Five","six",
  "Seven","Eight","Nine"};
char *tenup[] = {"Ten","Eleven","Twelve","Thirteen","Fourteen",
"Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
char *tens[] = {" "," ","Twenty","Thirty","Forty","Fifty","Sixty","Seventy",
"Eighty","Ninety"};
int nAmt = 0;
float nTemp = 0.00;
int nOnes = 0;
int nTens = 0;

printf("Pls enter a 2 digit number: \n");
scanf("%i", &nAmt);

nTens = int(nAmt/10);
nTemp = nAmt-(int(nAmt/10)*10);
nOnes = int(nTemp);

if ((nAmt>=10) && (nAmt<20)) {
printf("\n\n%s \n\n", tenup[nOnes]);
}
else {
printf("\n%s ", tens[nTens]);
printf("%s\n\n", ones[nOnes]);
}
}

Monday, January 18, 2016

Exercise given January 18, 2016


Write a small c/c++ program that accepts a single digit number from 0 to 9 and display/printf() the spelled-out word for it. ie: 5 as the input, Five as the output.

#include <stdio.h>

main()
{
    int i = 0;

    char *ones[] = {
        "Zero", "One",
        "Two", "Three",
        "Four", "Five",
        "Six", "Seven",
        "Eight", "Nine"
    };
    
    printf("\nPls enter a single digit number: \n");
    scanf("%i",&i);

printf("\n%s\n", ones[i]);

}



Welcome Page

TO ALL MY STUDENTS:

We are going to use this blog for our class.  Assignments and exercises will be posted here for clarification and further checking of your answers.  I may not be able to chronologically post the answers to our exercises, but will try my best to post all.  Things we do for all schedules of CS 122 will be posted here. 

Thank you.

Sir Amores