Skip to main content

Posts

Showing posts with the label introduction in c language

C Program to Swap Two Numbers

  Swap Numbers Using Temporary Variable # include <stdio.h> int main () { double first, second, temp; printf ( "Enter first number: " ); scanf ( "%lf" , &first); printf ( "Enter second number: " ); scanf ( "%lf" , &second); // Value of first is assigned to temp temp = first; // Value of second is assigned to first first = second; // Value of temp (initial value of first) is assigned to second second = temp; printf ( "\nAfter swapping, firstNumber = %.2lf\n" , first); printf ( "After swapping, secondNumber = %.2lf" , second); return 0 ; } Output Enter first number: 1.20 Enter second number: 2.45 After swapping, firstNumber = 2.45 After swapping, secondNumber = 1.20

C Program to Demonstrate the Working of Keyword long

  Program Using the long keyword # include <stdio.h> int main () { int a; long b; // equivalent to long int b; long long c; // equivalent to long long int c; double e; long double f; printf ( "Size of int = %zu bytes \n" , sizeof (a)); printf ( "Size of long int = %zu bytes\n" , sizeof (b)); printf ( "Size of long long int = %zu bytes\n" , sizeof (c)); printf ( "Size of double = %zu bytes\n" , sizeof (e)); printf ( "Size of long double = %zu bytes\n" , sizeof (f)); return 0 ; } Output Size of int = 4 bytes Size of long int = 8 bytes Size of long long int = 8 bytes Size of double = 8 bytes Size of long double = 16 bytes

C Program to Find the Size of int, float, double and char

  Program to Find the Size of Variables # include <stdio.h> int main () { int intType; float floatType; double doubleType; char charType; // sizeof evaluates the size of a variable printf ( "Size of int: %zu bytes\n" , sizeof (intType)); printf ( "Size of float: %zu bytes\n" , sizeof (floatType)); printf ( "Size of double: %zu bytes\n" , sizeof (doubleType)); printf ( "Size of char: %zu byte\n" , sizeof (charType)); return 0 ; } Output Size of int: 4 bytes Size of float: 4 bytes Size of double: 8 bytes Size of char: 1 byte

C Program to Compute Quotient and Remainder

  Program to Compute Quotient and Remainder # include <stdio.h> int main () { int dividend, divisor, quotient, remainder; printf ( "Enter dividend: " ); scanf ( "%d" , &dividend); printf ( "Enter divisor: " ); scanf ( "%d" , &divisor); // Computes quotient quotient = dividend / divisor; // Computes remainder remainder = dividend % divisor; printf ( "Quotient = %d\n" , quotient); printf ( "Remainder = %d" , remainder); return 0 ; } Output Enter dividend: 25 Enter divisor: 4 Quotient = 6 Remainder = 1

C Program to Find ASCII Value of a Character

  Program to Print ASCII Value # include <stdio.h> int main () { char c; printf ( "Enter a character: " ); scanf ( "%c" , &c); // %d displays the integer value of a character // %c displays the actual character printf ( "ASCII value of %c = %d" , c, c); return 0 ; } Output Enter a character: G ASCII value of G = 71

C Program to Multiply Two Floating-Point Numbers

  Program to Multiply Two Numbers # include <stdio.h> int main () { double a, b, product; printf ( "Enter two numbers: " ); scanf ( "%lf %lf" , &a, &b); // Calculating product product = a * b; // Result up to 2 decimal point is displayed using %.2lf printf ( "Product = %.2lf" , product); return 0 ; } Output Enter two numbers: 2.4 1.12 Product = 2.69 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.

C Program to Add Two Integers

  Program to Add Two Integers # include <stdio.h> int main () { int number1, number2, sum; printf ( "Enter two integers: " ); scanf ( "%d %d" , &number1, &number2); // calculating sum sum = number1 + number2; printf ( "%d + %d = %d" , number1, number2, sum); return 0 ; } Output Enter two integers: 12 11 12 + 11 = 23

Simple Calculator in c language

#include   <stdio.h> #include   <string.h> #include   <math.h> #include   <stdlib.h> int   main () {         int  a, b;      scanf ( "%d" , &a);      scanf ( "%d" , &b);      printf ( "%d \n " , a + b);      printf ( "%d \n " , a - b);      printf ( "%d \n " , a * b);      printf ( "%d \n " , a / b);      return   0 ; }