Monday, 26 October 2015

C LANGUAGE PROGRAM TO MULTIPLY TWO NUMBERS

WRITE A PROGRAM THAT TAKES TWO DIFFERENT INPUTS FROM USER, MULTIPLY THEM AND FINALLY DISPLAY THE RESULT IN OUTPUT SCREEN


#include<stdio.h>       // Header file “Standard Input and Output”
#include<conio.h>      //Header file “Console input and output”

void main ()
{
            clrscr();                                                // Clear the output screen
            int a, b, product;                                  // Variable declaration
            printf(“Enter first number = “);           // Display prompt for first number
            scanf(“%d”,&a);                                 // Take first input from user
            printf(“Enter second number = “);      // Display prompt for first number
            scanf(“%d”,&b);                                 // Take second input from user
           
            product = a * b;                                               // Formula for multiplying two numbers
            printf(“The product = %d“, product);                        // Display output on screen
           
getch();                                                //Get character
}

OUTPUT

Enter first number = 15
Enter second number = 6
The product = 90

EXPLANATION

1. I have used clrscr() function to clear the output screen, then I have declared three variables “a” and “b” to take input and “product” to store the multiplication result.

2. printf() function is used to display text on output screen, and scanf() function is used to take input into the variables.

3. Then I have used formula product = a * b; to multiply both numbers. After multiplying both numbers I have displayed the result using printf() function.

4. In the end of the program I have used getch() function, this function have no use in the program, I just use it to stop the output screen for a while so that user can see the output.


No comments:

Post a Comment