Posts

Showing posts from August, 2020

HISTORY, FEATURES, USES OF C LANGUAGE

< GOT INTEREST IN C PROGRAMMING LETS LEARN ABOUT BRIEF HISTORY, FEATURES AND USAGE IF YOU HAVEN'T GO THROUGH PREVIOUS PROGRAMMING BLOGS: HELLO, WORLD! :   https://bit.ly/3b8gNeB ADDING TWO INTEGERS :  https://bit.ly/3gLvpBE PRINTING INTEGER, ITS SQUARE AND CUBE :  https://bit.ly/2YOld5h ODD/EVEN :  https://bit.ly/3lzTf6X CREATING CALCULATOR : https://bit.ly/3b9h9S4   > C – Language History C language is a structure oriented programming language, was developed at Bell Laboratories in 1972 by Dennis Ritchie C language features were derived from earlier language called “B” (Basic Combined Programming Language – BCPL) C language was invented for implementing UNIX operating system In 1978, Dennis Ritchie and Brian Kernighan published the first edition “The C Programming Language” and commonly known as K&R C In 1983, the American National Standards Institute (ANSI) established a committee to provide a modern, comprehensive definition of C. The resulting definition, the AN

C PROGRAM TO SWAP TWO NUMBERS.

C Program to swap two numbers. (Entered by User) # include <stdio.h> int main () { double n1, n2, temp; printf ( "Enter First Number: " ); scanf ( "%lf" , &n1); printf ( "Enter Second Number: " ); scanf ( "%lf" , &n2); // Value of first is assigned to temp temp = n1; // Value of second is assigned to first n1 = n2; // Value of temp (initial value of first) is assigned to second n2 = temp; printf ( "\nAfter swapping, First Number = %.2lf\n" , n1); printf ( "After swapping, Second Number = %.2lf" , n2); return 0 ; } Output Enter First Number: 23.77 Enter Second Number: 1.02 After swapping, First Number = 1.02 After swapping, Second Number = 23.77 Explanation   In above example temp variable is assigned to n1 variable. Then the value of n1 variable is assigned to n2 variable. At last, the temp (holding value of n1) is a

Creating Simple Calculator in C programming using switch statement.

 Creating Simple Calculator in C programming using switch statement. # include <stdio.h> int main () { char operator ; double n1, n2; printf ( "Enter an operator (+, -, *, /) : " ); scanf ( "%c" , & operator ); printf ( "Enter two operands : " ); scanf ( "%lf %lf" ,&n1, &n2); switch ( operator ) { case '+' : printf ( "%.2lf + %.2lf = %.2lf" ,n1, n2, n1+n2); break ; case '-' : printf ( "%.2lf - %.2lf = %.2lf" ,n1, n2, n1-n2); break ; case '*' : printf ( "%.2lf * %.2lf = %.2lf" ,n1, n2, n1*n2); break ; case '/' : printf ( "%.2lf / %.2lf = %.2lf" ,n1, n2, n1/n2); break ; // If operator doesn't match any case constant +, -, *, / default : printf ( &qu

C Program to check even or odd.

  C Program to check even or odd. // Program to check entered integer is even or odd. # include <stdio.h> int main () { int n; printf ( "Enter an integer: " ); scanf ( "%d" , &n); //checks if the n is even. if (n%2==0) { printf ( "%d is even number.",n ); } //checks if the n is odd. else { printf ( "%d is odd number.",n ); } return 0 ; } Output Enter an integer: 23 23 is a odd number. Explanation If test expression becomes true : statement inside if get executed and else statement get skipped from execution. If test expression becomes false : statement inside if get skipped from execution and else statement get executed. Here when user enters 23, test expression n%2==0 becomes false.Hence else statement get executed. 

C Program to print the ASCII value of a character.

C Program to print the value of a character. In C programming, a character variable stores the ASCII value rather than the character itself. The ASCII value represents the character variable in numbers, and each character variable is assigned with some unique number range from 0 to 127. For eg., the ASCII value of "A" is 65. # include <stdio.h> int main () { char ch; printf ( "Enter a character: " ); scanf ( "%c" , &ch); // %d displays the integer value of a character // %c displays the actual character printf ( "ASCII value of %c = %d" , ch, ch); return 0 ; } OUTPUT Enter a character: L ASCII value of L = 76 Explanation: In the program, the user is asked to enter a character. The character is stored in variable ch. When the character is specified using %c format specifier then it will display the character itself. When a character is specified using %d format specifier then it will display the

C Program to add two integers.

  C program to add two integers using C program. # include <stdio.h> int main () { int number1, number2, sum; printf ( "Enter first integer: " ); scanf ( "%d" , &number1); printf ( "Enter second integer: " ); scanf ( "%d" , &number2); // calculating sum sum = number1 + number2; printf ( "Sum of above two integers is: %d + %d = %d" , number1, number2, sum); return 0 ; } OUTPUT Enter first integer: 30 Enter second integer: 20 Sum of above two integers is: 30 + 20 = 50 Explanation. In this program user is used to asked to enter two integers.   Then this numbers are added using + operator and then the result is stored in the sum variable. Atlast, printf() function is used to show the sum of numbers as output.

C Program to print an integer, its square, its cube.

  C program to print an integer. # include <stdio.h> int main () { int number; printf ( "Enter an integer: " ); // reads and stores input scanf ( "%d" , &number); // displays output printf ( "You entered: %d" , number); return 0 ; } OUTPUT Enter an integer: 15 You entered: 15 C program to print square of an integer. # include <stdio.h> int main () { int number; printf ( "Enter an integer: " ); // reads and stores input scanf ( "%d" , &number); // displays output printf ( "Its square: %d" , number*number); return 0 ; } OUTPUT Enter an integer: 15 Its square: 225 C program to print cube of an integer. # include <stdio.h> int main () { int number; printf ( "Enter an integer: " ); // reads and stores input scanf ( "%d" , &number);

"Hello, World!" Program in C Language

  Program to print " Hello, World!" in C language # include <stdio.h> int main () { // printf() displays the string inside quotation printf ( "Hello, World!" ); return 0 ; } Output Hello, World! _____________ _________________________________ How "Hello, World!" program works? #include <stdio.h> includes standard input output library function. The stdio.h file contains functions such as scanf() and printf() to take input and display output respectively. If we use printf() without #include <stdio.h> program will not compile The main() function is the entry point of every C program, execution of program starts from main(). The printf() function used to send the formatted output on screen.  The " return 0 " statement is the 'exit status' of program.