C Programming Code Examples
C > Pyramid Patterns Code Examples
program to Calculate 1 + 2 + 3 + 4 + 5 + ... + n series
/* program to Calculate 1 + 2 + 3 + 4 + 5 + ... + n series
In c++ language you can print any number series. Here 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 difference between two numbers.. */
#include<iostream.h>
#include<conio.h>
void main()
{
int j,n,sum=0;
clrscr();
n=10;
for(j=1;j<=n;j++)
{
sum+=j;
}
cout<<"Sum: "<<sum;
getch();
}
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.
#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:
The getch() is a predefined non-standard function that is defined in conio.h header file. It is mostly used by the Dev C/C++, MS- DOS's compilers like Turbo C to hold the screen until the user passes a single value to exit from the console screen. It can also be used to read a single byte character or string from the keyboard and then print. It does not hold any parameters. It has no buffer area to store the input character in a program.
The for loop is used in the case where we need to execute some part of the code until the given condition is satisfied. The for loop is also called as a per-tested loop. It is better to use for loop if the number of iteration is known in advance. The for-loop statement is a very specialized while loop, which increases the readability of a program. It is frequently used to traverse the data structures like the array and linked list.
Function clrscr() clears the screen and moves the cursor to the upper left-hand corner of the screen. If you are using the GCC compiler, use system function to execute the clear/cls command. clrscr() function is also a non-standard function defined in "conio.h" header. This function is used to clear the console screen. It is often used at the beginning of the program (mostly after variable declaration but not necessarily) so that the console is clear for our output.
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.
Graphic program about Mine Sweeper. Put mines in random blocks. Put mines value in other blocks. Sets view port to the play area only. Puts F tag in Array. Determine current
Swap two number using bitwise operator in C programming. There are tons of discussions going around the internet to swap 2 numbers without using temporary variable. We can...
C language program take the letter as input and store it in the variable grade. Convert the input letter into its uppercase using function toupper(). Using switch statement, verify the
C program to enter elements in two matrices and check whether both matrices are equal or not. C code to check whether elements of two matrices are equal or not. Input elements