Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


C Programming Code Examples

C > If Else and Switch Case Code Examples

program to check whether a number is divisible by 5 and 13 or not

/* program to check whether a number is divisible by 5 and 13 or not Write a C program to check whether a number is divisible by 5 and 13 or not using if else. How to check divisibility of any number in C programming. C program to enter any number and check whether it is divisible by 5 and 13 or not. A number is exactly divisible by some other number if it gives 0 as remainder. To check if a number is exactly divisible by some number we need to test if it leaves 0 as remainder or not. C supports a modulo operator %, that evaluates remainder on division of two operands. You can use this to check if a number is exactly divisible by some number or not. For example - if(8 % 2), if the given expression evaluates 0, then 8 is exactly divisible by 2. Input a number from user. Store it in some variable say j. To check divisibility with 5, check if(j % 5 == 0) then j is divisible by 5. To check divisibility with 13, check if(j % 13 == 0) then j is divisible by 13. Now combine the above two conditions using logical AND operator &&. To check divisibility with 5 and 13 both, check if((j % 5 == 0) && (j % 13 == 0)), then number is divisible by both 5 and 13. */ #include <stdio.h> int main() { int j; /* Input number from user */ printf("Enter any number: "); scanf("%d", &j); /* * If j modulo division 5 is 0 * and j modulo division 13 is 0 then * the number is divisible by 5 and 13 both */ if((j % 5 == 0) && (j % 13 == 0)) { printf("Number is divisible by 5 and 13"); } else { printf("Number is not divisible by 5 and 13"); } return 0; }

Writes the C string pointed by format to the standard output (stdout). If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers. printf format string refers to a control parameter used by a class of functions in the input/output libraries of C programming language. The string is written in a simple template language: characters are usually copied literally into the function's output, but format specifiers, which start with a % character, indicate the location and method to translate a piece of data (such as a number) to characters. "printf" is the name of one of the main C output functions, and stands for "print formatted". printf format strings are complementary to scanf format strings, which provide formatted input (parsing). In both cases these provide simple functionality and fixed format compared to more sophisticated and flexible template engines or parsers,

Read formatted data from stdin. Reads data from stdin and stores them according to the parameter format into the locations pointed by the additional arguments. The additional arguments should point to already allocated objects of the type specified by their corresponding format specifier within the format string. In C programming, scanf() is one of the commonly used function to take input from the user. The scanf() function reads formatted input from the standard input such as keyboards. The scanf() function enables the programmer to accept formatted inputs to the application or production code. Moreover, by using this function, the users can provide dynamic input values to the application.

#include is a way of including a standard or user-defined file in the program and is mostly written at the beginning of any C/C++ program. This directive is read by the preprocessor and orders it to insert the content of a user-defined or system header file into the following program. These files are mainly imported from an outside source into the current program. The process of importing such files that might be system-defined or user-defined is known as File Inclusion. This type of preprocessor directive tells the compiler to include a file in the source code program. Here are the two types of file that can be included using #include:

In C, the "main" function is treated the same as every function, it has a return type (and in some cases accepts inputs via parameters). The only difference is that the main function is "called" by the operating system when the user runs the program. Thus the main function is always the first code executed when a program starts. main() function is a user defined, body of the function is defined by the programmer or we can say main() is programmer/user implemented function, whose prototype is predefined in the compiler. Hence we can say that main() in c programming is user defined as well as predefined because it's prototype is predefined. main() is a system (compiler) declared function whose defined by the user, which is invoked automatically by the operating system when program is being executed.

Relational Operators are the operators used to create a relationship and compare the values of two operands. For example, there are two numbers, 5 and 15, and we can get the greatest number using the greater than operator (>) that returns 15 as the greatest or larger number to the 5. Following are the various types of relational operators in C. Equal To Operator (==) is used to compare both operands and returns 1 if both are equal or the same, and 0 represents the operands that are not equal. Not Equal To Operator (!=) is the opposite of the Equal To Operator and is represented as the (!=) operator. The Not Equal To Operator compares two operands and returns 1 if both operands are not the same; otherwise, it returns 0.

The if-else statement is used to perform two operations for a single condition. The if-else statement is an extension to the if statement using which, we can perform two different operations, i.e., one is for the correctness of that condition, and the other is for the incorrectness of the condition. Here, we must notice that if and else block cannot be executed simiulteneously. Using if-else statement is always preferable since it always invokes an otherwise case with every if condition.

An expression containing logical operator returns either 0 or 1 depending upon whether expression results true or false. Logical operators are commonly used in decision making in C programming. These operators are used to perform logical operations and used with conditional statements like C if-else statements.


C program to will prompt user to input three integer numbers and based on the input, it would compare and display greatest number as output. In this program number1, number2




C Language program is used to Find the Sum of the geometric progression series. Here G.P stands for geometric progression. Geometric progression, or GP, is a sequence where each

Comparing two integer variables is one of the simplest c program you can write at ease. In this program, you can either take input from user using scanf() function or statically define


C function 'strncat' concatenates n characters of str2 to string str1. Program concatenates n characters of str2 to string str1. A 'terminator' char ('\0') will always be appended at the end


Array of MAXARRAY length. Preform the heapsort. Help heapsort() to bubble down starting at pos[ition]. Load some random values into the array. Print the original array.