Solutions

STOP! Before you look here, make sure you have completed your attempt at the problem

Programming is like many things in this world. To become good at it you must do it. Not watch others do it. Not reading through solutions. YOU need to do it yourself. Working through your solution is key. All that typing will help you remember how to do something. Do not look at this page until you have written your own solutions, compiled it and tested it. If you got some of it wrong, or if you are stuck, you can look here. If you are done and just want to verify your answer, you can look here. However, do not look here until you have actually attempted the problem.

Note that with programming, there are often more than one solutions. While the solutions here will solve the problem, it does not mean that your solution is wrong. Do not worry if your solution is not exactly the same as my solution. That will happen.

Question

Write a program that will write out the following, note that all indentations are tabs.

The itsy bitsy spider crawled up the water spout
    down came the rain to wash the spider out
        then came the sun that dried up all the rain
            and the itsy bitsy spider crawled up the spout again

Solution:

#include <stdio.h>
int main(void){
    printf("The itsy bitsy spider crawled up the water spout\n");
    printf("\tdown came the rain to wash the spider out\n");
    printf("\t\tthen came the sun that dried up all the rain\n");
    printf("\t\t\tand the itsy bitsy spider crawled up the spout again\n");
    return 0;
}


Question

Write a program that will write out the following to the screen.

In DOS based systems, you use \ in your path
In UNIX based systems you use / in your path
99% of students polled love ice-cream!
"Always be wary of any helpful item that weighs less than its operating manual."
    - Terry Pratchett

Solution

#include <stdio.h>
int main(void){
    printf("In DOS based systems, you use \\ in your path\n");
    printf("In UNIX based systems you use / in your path\n");
    printf("99%% of students polled love ice-cream!\n");
    printf("\"Always be wary of any helpful item that weighs less than its operating manual.\"\n");
    printf("- Terry Pratchett\n");
    return 0;
}


Question

Re-write the hello world program so that when it will do a beep just before it ends

Solution

#include <stdio.h>
int main(void){
    printf("Hello World!\n");
    printf("\a");
}

results matching ""

    No results matching ""