Posts

Showing posts with the label Learning "C"

getting Started with "C" part3

Image
In C programming, one of the frequently arising problem is to handle similar types of data. For example: If the user want to store marks of 100 students. This can be done by creating 100 variable individually but, this process is rather tedious and impracticable. These type of problem can be handled in C programming using arrays. An array is a sequence of data item of homogeneous value(same type). Arrays are of two types: One-dimensional arrays Multidimensional arrays ( will be discussed in next chapter ) Declaration of one-dimensional array data_type array_name [ array_size ]; For example : int age [ 5 ]; Here, the name of array is age . The size of array is 5,i.e., there are 5 items(elements) of array age . All element in an array are of the same type (int, in this case). Array elements Size of array defines the number of elements in an array. Each element of array can be accessed and used by user according to the need of program. For example: int

getting Started with "C" part 3

Image
In programming, a function is a segment that groups code to perform a specific task. A C program has at least one function main ( ) . Without main () function, there is technically no C program. Types of C functions Basically, there are two types of functions in C on basis of whether it is defined by user or not. Library function User defined function Library function Library functions are the in-built function in C programming system. For example: main () - The execution of every C program starts from this main () function. printf () - prinf () is used for displaying output in C. scanf () - scanf () is used for taking input in C. Visit this page to learn more about library functions in C programming language. User defined function C allows programmer to define their own function according to their requirement. These types of functions are known as user-defined functions. Suppose, a programmer wants to find factorial of a number and check whether i

getting started with"C" part2

Image
The if, if...else and nested if...else statement are used to make one-time decisions in C Programming, that is, to execute some code/s and ignore some code/s depending upon the test expression. C if Statement if ( test expression ) { statement / s to be executed if test expression is true ; } The if statement checks whether the text expression inside parenthesis ( ) is true or not. If the test expression is true, statement/s inside the body of if statement is executed but if test is false, statement/s inside body of if is ignored. Flowchart of if statement Example 1: C if statement Write a C program to print the number entered by user only if the number entered is negative. #include <stdio.h> int main (){ int num ; printf ( "Enter a number to check.\n" ); scanf ( "%d" ,& num ); if ( num < 0 ) { /* checking whether number is less than 0 or not. */ printf (