Posts

Showing posts with the label C-programming

THE DECISION CONTROL STRUCTURE

Image
C language must be able to perform different set of actions depending on the circumstances.Here comes the importance of decision control structures. Decision making is about deciding the order of the execution of statements based on certain conditions.This decision control instruction can be implemented in C using : The if statement The if  statement may be implemented in different forms depending on the complexity of conditions to be tested. The different forms are, Simple if   statement if else  statement Nested if  statement if else ladder statement Simple if statement The general syntax of simple if statement is if(boolean_expression) { /* statement(s) will execute if the boolean expression is true */ } If the Boolean expression evaluates to  true , then the block of code inside the i f statement will be executed. If the Boolean expression evaluates to  false , then the first set of code after the end of the...

C-programming Reading input

Image
C - Input & Output printf() ,scanf(),gets(),getchar(),puts() and putchar() scanf()   This  function reads formatted input from standard input (keyboard)  printf()  This  function sends formatted output to the standard output (screen) Example 1    C Integer Input/Output #include <stdio.h> int main () { int n ; printf ( "Enter an integer: " ); scanf ( "%d" ,&n ); //Reads intiger from keyboard to variable n printf ( "Number = %d" ,n ); //Prints the read value in output screen return 0 ; } getchar()  - This function is used to read single character  putchar() -This function is used to print single character Example 2  -getchar(),putchar() #include <stdio.h> int main () { char c ; printf ( "Enter character: " ); c = getchar (); printf ( "Character entered: " ); putchar ( c ); return ( 0 ); } gets...

C-Programming introduction

Image
         Every C-Program begins with a function called "main()",A function is simply a collection of commands that do "something".     From main, we can call other functions, whether they be written by us or by others or use built-in language features. To access the standard functions that comes with your compiler, you need to include a header with the #include directive. Let's look a simple C-program: PROGRAMME #include <stdio.h> int main() { printf( "I am alive! Beware.\n" ); getchar(); return 0; } OUTPUT I am alive! Beware.          The #include is a "preprocessor" directive that tells the compiler to put code from the header called stdio.h into our program before actually creating the executable file. By including header files, you can get access to many different functions like printf() and getchar() functions, these are included in stdio.h.          The "int main() " te...