C Language Variables Example Program
In this section of the course we have inserted some examples about integer variables, floating point variables.The example below are for the beginners and you can use turbo C or any other C language IDE to run the example.To run the example compile and run it.some of the programs require input from the user so don’t forget to provide input to the program and it will display the output. Result of every program is below the program code.
Integer Output Program
1 2 3 4 5 6 7 |
#include<stdio.h> int main() { int a=10; printf("number is %d",a); return 0; } |
Output : number is 10
Here , we can go further and use a bit step up.
1 2 3 4 5 6 7 8 9 |
#include<stdio.h> int main() { int a; printf("enter a number\n"); scanf("%d",&c); printf("number="%d",a); return 0; } |
output 1 : enter a number
input : 10
Output 2: number=10
Detail about above Program: The scanf() functions is used to take input from user.In this program, the user is asked a input and value is stored in variable c.
Note the ‘&‘ sign before c. &c denotes the address of c and value is stored in that address and printf() shows the simply result.
Here we can also check input and output of character and float variables.
Floating Point Number Examples
1 2 3 4 5 6 7 8 9 |
#include<stdio.h> int main() { float x; printf("enter a number:"); scanf("%f",&x); printf("value=%f",x); //%f is used for float instead of %d return 0; } |
Output : enter a number:
Input : 10.20
value=10.20