C - Code Examples
C - Code Examples
C - Code Examples
"
#include <stdio.h>
int main()
{
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
}
Output
Hello, World!
The printf() is a library function to send formatted output to the screen. In this
program, the printf() displays Hello, World! text on the screen.
The return 0; statement is the "Exit status" of the program. In simple terms,
program ends with this statement.
Output
Enter a integer: 25
You entered: 25
Finally, the value stored in the variable number is displayed on the screen
using printf()function.
// Displays sum
printf("%d + %d = %d", firstNumber, secondNumber, sumOfTwoNumbers);
return 0;
}
return 0;
}
Output
1.12
Product = 2.69
In this program, user is asked to enter two numbers. These two numbers entered by the
user is stored in variable firstNumber and secondNumber respectively. This is done
using scanf() function.
Then, the product of firstNumber and secondNumber is evaluated and the result is
stored in variable productOfTwoNumbers.
Notice that, the result is round to second decimal place using %.2lf conversion
character.
Output
Enter a character: G
ASCII value of G = 71
In this program, user is asked to enter a character which is stored in variable c. The
ASCII value of that character is stored in variable c rather than that variable itself.