8/30/20

Principle or Rules for Writing C Program in C Programming.


In the previous articles, we already told you about variables, constants, and keywords, etc. Now the next step is to combine them (variable, keywords, and constants) to form an instruction. But before knowing about instruction we are going to make a new program using variable constant and keywords.

But before going to make a program we have to study the procedure or rules of writing a program in c language.  Remember that these rules are applicable to all c programs written on c language. Let’s Begin...

  • Every C program statement must be ended with “;” (semicolon) generally known as a statement terminator.
  • All the statements should be written in small letters.
  • Blank space is used between two words to improve the statement readability.
  • No blanks were allowed between the variables, constants, and keywords.
  • Each Instruction in c program is written as a separate statement.
Let us write down our first program in c language. In this program we are going to calculate the simple interest of any amount.

/* Calculation of simple interest */
/* Author Mad About Computer Date: 01/09/2020 */

main( )
{
 int p, t ;
 float r, si ;
 p = 1000 ;
 t = 3 ;
 r = 8.5 ;
 /* formula for simple interest */
 si = p * t * r / 100 ;
 printf ( "%f" , si ) ;
}

Explanation of the program.

  1. The first two lines of the program are a comment. The Information provided between the /* */ is the information of the program, programmer, and date of the program when it was written.  
  2. It is not necessary to write down the comment in your program but it is a good practice of the programmer to begin the program with a comment which shows the information about the programs and something else which is important in your program.
  3. After the comment, we used a function called main (). Main() is the function of c program. It indicates where your program has started. When you execute your program it directly executes from the main functions.
  4. After the main function, we declared our variables where p represents the principle, t represents time, the r represent rate and si represent the simple interest respectively. It is necessary to declare the variable before we use it on the program. We already assign the value of the variables. ( p = 1000, t = 3.5, r = 8.5 ). 
  5. After the variable declaration, we have to put the formula of the simple interest into the program. The formula of the simple interest is p*r*t/100. In the formula, you have seen we use (*, / ) symbol. What does it mean? The symbol is known as an arithmetic operator. We discuss the operator in detail later. Just know that * operator is used to multiplying two or more values. And the / operator is used to divide two or more values.   
  6. Once the s.i value Is calculated we have to display it on the screen. To display the result of the simple interest, we have to use printf() keyword on the program. Printf() keyword is used to display anything on the display screen
 The main method to used printf( ) function is :- printf ( "", ) ;can contain,
  • %f for printing real values
  • %d for printing integer values
  • %c for printing character values
In this tutorial, we learn about principle or rules for writing c programs in C programming. If you find any mistakes on it. Or if you have any quarry related to it please comment below. Follow us for more programming tutorials.

You May Also Like 



Continue Reading →

8/23/20

Basic Structure of C programs


Hey Friends, so far we have learned about some basic things of C programming language like ( Variable, Constant, Keywords, etc. ) Now today we are going to learn about the basic structure of c programming. So let’s begin..!!!

Basic Structures of C programs 

Basically, any c program is divided into 6 different sections. These Six Sections are:-



1. Documentation Section
2. Link Section 
3. Definition Section 
4. Global Declaration Section 
5. Main() Function Section 
6. Subprograms Section

Below you find a brief information on them.

Basic Structure of C programs

Documentation Section

In the Documentation Section, the Programmer gives the information (Details) about the program, author, coding details, and some other stuff that is used on it. Documentation Section helps anyone (user, programmer, author, owner, etc)  to get an overview of the program.

Example:- 


/**

* File Name: Helloworld.c


* Author: Suresh Mishra


* Date: 24/08/2020


* Description: a program to display hello world


*/



Link Section 

Link Section is a part of code that is used to add or insert-header files that will be used on the program. This section tells the compiler to link header files from the system libraries.

Example:- 

#Include <stdio.h>
#include<conio.h>

Definition Section 

In this section, we define the different constant. And also keywords as well.

Example:-  

#define PI=3.14

Global Declaration Section 

In this Section, Global variables are declared. All the Global Variable which is used on the program are declared in the global declaration section.

Example:-

int a=7 b= 10, float z = 7.10 etc

Main Function Section 

Every C program it is necessary to have the main function. Each Main Function contains 2 parts. 1. Declaration Part and 2. Execution Part. The declaration part is the part where all the variables are declared. And the execution part always starts with curly brackets and end with curly brackets. Both the part must have inside the curly brackets.

Example:- 
{
void main ()
{
Int a = 10;
printf(“%d”, a);  
return 0;
}

Subprograms Section 

All the user-defined functions are defined in this section of the program.

Example:- 


int add(int a, int b)
{
return a+b;
}

In this tutorial, we learn about the basic structure of C programming. If you find any mistakes on it. Or if you have any quarry related to it please comment below. Follow us for more programming tutorials.

You May Also Like 



Continue Reading →

8/19/20

Compilation and Execution in C Programming.
















Compilation and Execution 

Once you wrote the program you need to type it and execute it. To type the C program you need a software in which you type your program called Editor. After type your code, you need another software which converts your c program code into machine language (0 and 1 form) known as Compiler.

The Compiler software companies provide an Integrated Development Environment (IDE) which consists of an Editor as well as the Compiler.

There are several IDE software available in the market for different operating systems. For ex: - Turbo C, Turbo C++, etc. are for MS-DOS. Visual C++, Borland, etc. are available for Windows and GCC are works under Linux OS.

  upload.wikimedia.org/wikipedia/commons/5/5e/GNU...MS DOS for Android - APK DownloadMicrosoft launches Visual Studio Online public preview and ML.NET ...
                                                                    Image Source

In my opinion, if you are a beginner you have to use Turbo C or Turbo C++. Once you have mastered the elements then you can easily switch over to other software like Borland or Visual C++ etc.

Now let assume you are using Turbo C or Turbo C++ compiler. So here are the few steps that you have to follow to compile or execute the C program. 


1. Start the compiler at C> prompt. 


2.  Select New from the File menu. 




3. Type the program.




4. Save the program using F2.

5. Use (Ctrl + F9) to compile and execute your c program.




6. Use Alt + F5 to view the output.





Note that after compiling the program a new file stored on your disk (.EXE file). This file is known as an executable file. If you give that file to your friend to check your program they didn’t need to compile the file again they directly double click on that file and the file will start executing the program.

People May Also Like



Continue Reading →

8/10/20

Keywords And First Program (Hello World!!) in C Programming.



In C programming language, there are some words stored on its compiler library. These words have performed some task or instruction which was already written on it. These types of words are known as Keywords.

You cannot define a variable which name is exactly matching with keywords. Because if you create them they perform their instruction rather than yours. Keywords are also known as ‘Reserved Words’.

In c programming, you can also create your keyword as well. There are only 32 keywords available in c programming.




Hello World – The first C Program

Friends, So far we have learned about variable, constant, and keywords. Let combine all of these to form a simple program in C language.

Let now write down our first c program. In this program, we are going to print a simple “Hello World!!” which is displayed on your monitor screen.  Let’s begin…

Ex:-


/* Welcome to Mad About Computer */
#include <stdio.h>
main()
{
printf("Hello World!!");
return 0;
}

Output:-



Now, look at the function of all the above code.

1. The First line in the program #include <stdio.h> is preprocessor command, which tells the compiler to include the content of <stdio.h> file in the program. The full form of stdio.h is Standard Input and Output. Stdio.h is a header file(Extension of the header file is .h) which contains functions such as Printf() or Scanf() to take input from the user and display the Output respectively.

2. The Next line main() is the main function where the program execution starts.

3. The Next line is printf(“…”). It is a function which comes under the <stdio.h> header file to display the several lines which you write in it as Output. (write you messages under the double comma otherwise it can’t display )

4. And the last line of the program returns 0. It describes that return 0; terminate the int main() function and the program return value in 0.

In this tutorial, we learn about keywords in c programming language and first c program called Hello World. If you find any mistakes on it. Or if you have any quarry related to it please comment below. Follow us for more programming tutorials.

You May Also Like 




Continue Reading →

Like us on facebook

blogger templatesblogger widgets

Follow on Twitter

Linkedin

Categories

Contact Form

Name

Email *

Message *

Mad About Computer. Powered by Blogger.