Posts

Showing posts with the label Introduction

How does a C program to compute quotient and remainder work?

 Courtesy: Programiz.com In this program, the user is asked to enter two integers (dividend and divisor). They are stored in variables  dividend  and  divisor  respectively. printf ( "Enter dividend: " ); scanf ( "%d" , &dividend); printf ( "Enter divisor: " ); scanf ( "%d" , &divisor); Then the quotient is evaluated using  /  (the division operator), and stored in  quotient . quotient = dividend / divisor; Similarly, the remainder is evaluated using  %  (the modulo operator) and stored in  remainder . remainder = dividend % divisor; Finally, the quotient and remainder are displayed using  printf( ) . printf ( "Quotient = %d\n" , quotient); printf ( "Remainder = %d" , remainder);

How does a C program to multiply two floating-point numbers work?

Image
Courtesy: Programiz.com  In this program, the user is asked to enter two numbers which are stored in variables  a  and  b  respectively. printf ( "Enter two numbers: " ); scanf ( "%lf %lf" , &a, &b); Then, the product of  a  and  b  is evaluated and the result is stored in  product . product = a * b; Finally,  product  is displayed on the screen using  printf() . printf ( "Product = %.2lf" , product); Notice that, the result is rounded off to the second decimal place using  %.2lf  conversion character.

How does C program to add two integers work?

Image
Courtesy: Programiz.com In this program, the user is asked to enter two integers. These two integers are stored in variables  number1  and  number2  respectively. printf ( "Enter two integers: " ); scanf ( "%d %d" , &number1, &number2); Then, these two numbers are added using the  +  operator, and the result is stored in the  sum  variable. sum = number1 + number2; Add Two Numbers Finally, the  printf()  function is used to display the sum of numbers. printf ( "%d + %d = %d" , number1, number2, sum);

How does C program to print an integer work?

Image
Courtesy: Programiz.com   In this program, an integer variable   number   is declared. int number; Then, the user is asked to enter an integer number. This number is stored in the  number  variable. printf ( "Enter an integer: " ); scanf ( "%d" , &number); Finally, the value stored in  number  is displayed on the screen using  printf() . printf ( "You entered: %d" , number);