To add two numbers we will simply just create three variables, two for the numbers and one for the result. See example
int main()
{
int a=10, b=5, c; \\ We can also create many variables in the same line
c = a + b; \\ The equal sign we put the right side value to left side
printf("%d",c);
return 0;
}
In last line we are printing the value of C named variable to print a integer variable's value
we use '%d' for others just scroll down.
char %c
string %s
float %f
double %l
We can also take input from user with just using the scanf function. Scanf function simply take user's input and then can processing with it.
int main()
{
int a,b,c;
printf("Enter Two Number"); \\ giving message to the user by which he can understand what he exactly has to do
scanf("%d %d",&a,&b); \\ two %d for two variables
c = a + b;
printf("Sum = %d",c);
}
Here in first line we are giving message to the user by which he can understand what input are allowed in this program. So a message should be always easy and simple to understafd.
A variable name must be meaningful or mnemonic type , means name should relate to its functionality. It is very important to do this for example if you have created a program a revising it after a long gap at this stage it may be possible that you can't understand that where you are using a particular variable.
Thanks for coming
and will appreciate your comments
Know more about computer and Networks on www.computergenre.blogspot.com
No comments:
Post a Comment