C programs to practice: Basic input and output handling
Input is the data given the user to the program. Output is the response of the program to the user.
Let us create a program to handle basic input and
output.
First, include the header file which has the definitions for
functions definitions.
Next , identify the data type for basic input and outputs.
It has following types.
‘int’ -integer
‘float’ – float number.
‘double’ – double number.
‘char’ – character
‘short int’ -it is a short integer.
‘long int’ – it is a long integer.
To declare a variable, use the datatype with variable name.
To get the input ,use ‘scanf()’ function.
To display the output, use ‘printf()’ function.
Access specifiers:
It gives you the meaning of variable for getting the input
and printing the output.
For eg, ‘%d’ is for integer values, ‘%f’ is for floating
values and ‘%s’ is for string variables.
The operations for the variables, you can use arithmetic symbols.
Let us create the program.
C Program to handle basic input and output operations:
#include<stdio.h>
int main()
{
int a,b,c=0;
float d,e,f=0.0;
char g[10];
printf("Enter
the two integer value");
scanf("%d
%d",&a,&b);
printf("Enter
the floating value");
scanf("%f
%f",&d,&e);
printf("Enter
your name");
scanf("%s",g);
c=a+b;
f=d+e;
printf(" The
sum of two integer values are: %d",c);
printf("\n
The sum of two floating values are:%f",f );
printf("\n
Hi,%s ,Welcome to C world",g);
return 0;
}
Output:
Compile and run the program to get the output.
Enter the two integer value
4 5
Enter the floating value
5.6 6.7
Enter your name
rajeeva
The sum of two integer values are: 9
The sum of two floating values are:12.299999
Hi,rajeeva ,Welcome
to C world
This is the simple way of creating C program to handle basic
input and output operations. Hope the code is useful to you. Keep coding!!!!
Comments
Post a Comment