C Programming Code Examples
C > Mathematics Code Examples
Averaging ten numbers - storing the numbers the hard way
/* Averaging ten numbers - storing the numbers the hard way */
#include <stdio.h>
void main()
{
int number0 = 9, number1 = 18, number2 = 27, number3 = 36, number4 = 45;
int number5 = 54, number6 = 63, number7 = 72, number8 = 81, number9 = 90;
long sum = 0L; /* Sum of the numbers */
float average = 0.0f; /* Average of the numbers */
sum = number0 + number1+ number2 + number3 + number4+
number5 + number6 + number7 + number8 + number9;
average = (float)sum/10.0f;
printf("Average of the ten numbers entered is: %f", average);
}
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.
Assignment operators are used to assign the value, variable and function to another variable. Assignment operators in C are some of the C Programming Operator, which are useful to assign the values to the declared variables. Let's discuss the various types of the assignment operators such as =, +=, -=, /=, *= and %=. The following table lists the assignment operators supported by the C language: Simple assignment operator. Assigns values from right side operands to left side operand. Add AND assignment operator. It adds the right operand to the left operand and assign the result to the left operand.
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,
Arithmetic Operator is used to performing mathematical operations such as addition, subtraction, multiplication, division, modulus, etc., on the given operands. For example: 6 + 3 = 9, 5 - 3 = 2, 3 * 4 = 12, etc. are the examples of arithmetic operators. Let's discuss the different types of Arithmetic Operators in the C programming. Plus Operator is a simple Plus (+) Operator used to add two given operands. We can use Plus Operator with different data types such as integer, float, long, double, enumerated and string type data to add the given operand. The minus operator is denoted by the minus (-) symbol. It is used to return the subtraction of the first number from the second number. The data type of the given number can be different types, such as int, float, double, long double, etc., in the programing language.
#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 The C, you can print any number series and I will show you how to 'print number series' in C Language with explanation. In case of print number series you need to focus on common
C program code, 'using recursion', reverses a Stack content. Stack here is represented use a linked list. A Linked List is an ordered set of "Data Elements", each containing a link to its
Take the number of rows as input and store in the variable number. Firstly decrement the variable number by 1 and assign this value to the variable count. Use this variable count as
C Program calculates the sum & difference of the matrices. Code first reads 2 matrices and then performs both addition and subtraction of matrices. Sum of elements of matrix A and
C Programming language code example to Allocates sufficient memory for an array of num objects of size size. Return: Returns a pointer to the first byte of the allocated...