Skip to main content
Logo image

Dive Into Systems: Exercises

Section 16.1 Getting Started Programming in C

Checkpoint 16.1.1. Translating Java into C.

Rewrite the following Java program into C:.
public class AddNumbers {

    public static void main(String[] args) {
	int result;
	 
	result = 1 + 2;
	System.out.println("result is " + result);
	 
    }
}
Answer.
See below for the solution:
int main(void) { 
    int result;

    result = 1 + 2;
    printf("%d\n", result);

    return 0;
}