So, we saw what is C in our first blog and had a look over a simple program. Now, we will see about datatypes and addition of two numbers .
Basic Data Type:- int, char, float, double
int Datatype:-Its an integer datatype .Its of 2 bytes .Its range is −32,768 to 32,767.
char Datatype:-Its an character datatype. Its of 1 byte. Its range is -128 to 127 .
float Datatype:-Its for floating point numbers. Its of 4 byte.
double Datatype:-Its for large floating point numbers .Its of 8 byte
1.Addition of two numbers using int datatype
#include <stdio.h>
int main()
{
int number1,number2,number3;
printf("Enter two numbers number1 and number2: ");
scanf("%d %d",&number1,&number2);
number3=number1+number2;
printf("The addition of two numbers is %d",number3);
return 0;
}
Algorithm:-
1.Start
2.Declare the header file #include<stdio.h>
3.Inside the main function declare the keyword int for the variables number1 ,number2,number3.Use the printf to display the text "Enter two numbers number1 and number2: ".
4.Use scanf and get the first number and second number .For integer variable we have to use a format specifier "%d" .
5.Use the number3 variable and add first number and second number .
6.Finally use the printf statement to display "The addition of two numbers is " and use "%d" to display the number3 variable.
7.Stop
Explanation:-
scanf:-Its used to get the user input from the user .
Since we are using two integer variable we are using two format specifiers which is of integer type i.e,"%d".
Screenshot:-
1.Code Screenshot
2.Output Screenshot:-
2.Addition of two numbers using float datatype
#include <stdio.h>
int main()
{
float number1,number2,number3;
printf("Enter two numbers number1 and number2: ");
scanf("%f %f",&number1,&number2);
number3=number1+number2;
printf("The addition of two numbers is %f",number3);
return 0;
}
Algorithm:-
1.Start
2.Declare the header file #include<stdio.h>
3.Inside the main function declare the keyword float for the variables number1 ,number2,number3.Use the printf to display the text "Enter two numbers number1 and number2".
4.Use scanf and get the first number and second number .For float variable we have to use a format specifier "%f" .
5.Use the number3 variable and add first number and second number .
6.Finally use the printf statement to display "The addition of two numbers is " and use "%f" to display the number3 variable.
7.Stop
Explanation:-
scanf:-Its used to get the user input from the user .
Since we are using two float variable we are using two format specifiers which is of float type i.e, "%f".
Screenshot:-
1.Code Screenshot :-
2.Output Screenshot:-
3.Addition of two numbers using double datatype.
#include <stdio.h>
int main()
{
double number1,number2,number3;
printf("Enter the numbers number1 and number2 : ");
scanf("%lf %lf",&number1,&number2);
number3=number1+number2;
printf("The addition of two numbers is %lf",number3);
return 0;
}
Algorithm:-
1.Start
2.Declare the header file #include<stdio.h>
3.Inside the main function declare the keyword double for the variables number1 ,number2,number3.Use the printf to display the text "Enter two numbers number1 and number2".
4.Use scanf and get the first number and second number .For double variable we have to use a format specifier "%lf" .
5.Use the number3 variable and add first number and second number .
6.Finally use the printf statement to display "The addition of two numbers is " and use "%lf" to display the number3 variable
7.Stop
Explanation:-
scanf:-Its used to get the user input from the user .
Since we are using two double variable we are using two format specifiers which is of double type i.e,"%lf".
Screenshot:-
1.Code Screenshot
2.Output Screenshot:-
In the next blog we will see how to subtract two numbers.
0 Comments