Hello World
Hello World
Raghavendra Kanakagiri
Fall 2023
Hardware
Assembler
Compiler
1 /*
2 Author : James Bond
3 */
4 # include < stdio .h >
Lines 1 to 3: multi-line comment
5 int main ( void )
6 { Line 7: single line comment
7 // say hello
8 printf ( " Hello world \ n " ) ;
9 return 0;
10 }
$ ./a.out
1 # include < stdio .h >
2 int main ( void )
3 { 1 2
4 int a ;
5 int b ;
6 int c ; $ ./a.out
7 scanf ( " % d " , & a ) ;
8 scanf ( " % d " , & b ) ;
9 c = a - b; 1 a
10 printf ( " Difference of % d and
% d is % d \ n " , a , b , c ) ;
11 return 0; $ ./a.out
12 }
1.4 3.2
x = a + b * c;
x = a + b / c;
x = a * b + c;
x = a * b % c + d / e - f;
Paranthesis can be used to change the order of evaluation. They are evaluated first.
If the paranthesis are nested, the innermost paranthesis are evaluated first.
If parantheiss are on the same level, they are evaluated from left to right.
x = (a + b) * c;
x = (a + b) / c;
x = a * b % c + d / e - f;
x = ((a * b) % c) + (d / e) - f;
Better?
Replace lines 11 to 18 in the previous program with the following:
1 if ( sum_o r_diff erence == 1) {
2 c = a + b;
3 printf ( " Sum of % d and % d is % d \ n " , a , b , c ) ;
4 }
5 else if ( sum_o r_diff erence == 2) {
6 c = a - b;
7 printf ( " Difference of % d and % d is % d \ n " , a , b , c ) ;
8 }
9 else {
10 printf ( " Invalid input \ n " ) ;
11 }
Operator Operation
== Equality
!= Inequality
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
Write a program that reads in 4 numbers and prints the largest and
smallest of them.
Write a program that reads in a number and prints the sum of its
digits.
Write a program that prints the square and cube of the numbers from 1
to 10.