Simple C Program to Display Two Integers

 

Simple C Program to Display Two Integers

//Simple C Program to display two integers on screen.

#include<stdio.h>

int main()

{

    int a=10;

    int b=20;

    printf("The A and B values are\n%d\t%d,", a,b);

    return 0;

}

 

Output:

The A and B values are

10      20

 

In the above program instructions are written to display two integers value on screen. The values of two variables assigned with assignment operator (=) and have its data type integer(int).

The main () function is declared with int. So programmer has to return something to main function.

To display the values on screen %d%d two times used because the programmer wants to display two integers.



//Simple C Program to display two integers on screen.

#include<stdio.h>

int main()

{

    float a=10.5;

    float b=20.5;

    printf("The A and B values are\n%d\t%f,", a,b);

    return 0;

}

Output:

The A and B values are

10 5     20.5

  



//Simple C Program to display  user input (two integers) on screen. 

#include<stdio.h>

#include<conio.h>

void main()

{

    int a;

    int b;

printf("Enter first integer\n");

scanf("%d",&a);

printf("Enter second  integer\n");

scanf("%d",&b);

printf("The two integers are: \n%d\t%d,", a,b);

}

 

Output:

Enter first integer

5

Enter second integer

5

The two integers are:

5   5

10      20


In above program the two integer values are given by user.

scanf() function is used to read user input. & is address operator used to store user input in a variable.

%d is format specifier for integer data or values. 

\t is used to give white space in between two values.

\n is used to print the statement to new line.



टिप्पणी पोस्ट करा

0 टिप्पण्या