Hey guyzz welcome back .Today i will be uncovering some library functions and some Unary operators .
So lets start up with the code
In my last post we (means predefined) assigned the values to the variables .Now if u want to take input from the user then study this code .
Lets improve the last code and do some multiplication:-
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c; //we initialized three variables of integer type
clrscr();
printf("Enter the numbers you want to multiply"); //you r giving output on the standard output device i.e., monitor
scanf("%d",&a); //to assign value to a variable from standard input device i.e., key board
scanf("%d",&b);
c=a+b;
printf("answer = %d",c);
getch();
}
you all see a new library function called scanf() it is a predefined function in this language .Now coming on to the inner stuff you know about %d i.e., telling compiler that the variable is int now & assigns the value inputted by the user to a variable .
easy way to writ above program i.e., like professionals
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
clrscr();
printf("enter the numbers ");
scanf("%d%d",&a,&b);
printf("answer=%d",a*b);
getch();
}
now whats happening here in scanf or printf .
Lets take scanf i gave two %d in the code it means am telling compiler that there are two integer values.
now is used &a and &b to assign the value taken from user to variables respectively.
That's all for this post in the next post there will be some theory about operators .
So lets start up with the code
In my last post we (means predefined) assigned the values to the variables .Now if u want to take input from the user then study this code .
Lets improve the last code and do some multiplication:-
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c; //we initialized three variables of integer type
clrscr();
printf("Enter the numbers you want to multiply"); //you r giving output on the standard output device i.e., monitor
scanf("%d",&a); //to assign value to a variable from standard input device i.e., key board
scanf("%d",&b);
c=a+b;
printf("answer = %d",c);
getch();
}
you all see a new library function called scanf() it is a predefined function in this language .Now coming on to the inner stuff you know about %d i.e., telling compiler that the variable is int now & assigns the value inputted by the user to a variable .
easy way to writ above program i.e., like professionals
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
clrscr();
printf("enter the numbers ");
scanf("%d%d",&a,&b);
printf("answer=%d",a*b);
getch();
}
now whats happening here in scanf or printf .
Lets take scanf i gave two %d in the code it means am telling compiler that there are two integer values.
now is used &a and &b to assign the value taken from user to variables respectively.
That's all for this post in the next post there will be some theory about operators .
No comments:
Post a Comment