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 




      "+y+""}else{if(A==5){c+='
    • '+w+""+y+"
    • "}else{if(A==6){c+='
    • "+w+'
      '+u+""+y+"
    • "}else{c+='
    • "+w+"
    • "}}}}}s.innerHTML=c+=""+y;d.callBack()};randomRelatedIndex=h;showRelatedPost=g;j(d.homePage.replace(/\/$/,"")+"/feeds/posts/summary"+e+"?alt=json-in-script&orderby=updated&max-results=0&callback=randomRelatedIndex")})(window,document,document.getElementsByTagName("head")[0]); //]]>

      4 comments:

      1. Awesome article, it was exceptionally helpful! I simply began in this and I'm becoming more acquainted with it better! Cheers, keep doing awesome! Writing apps

        ReplyDelete
      2. I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here. Book writing software

        ReplyDelete
      3. I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here. How to title an essay

        ReplyDelete
      4. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. Mua Tài khoản Grammarly Premium

        ReplyDelete

      Follow on Twitter

      Linkedin

      Categories

      Contact Form

      Name

      Email *

      Message *

      Mad About Computer. Powered by Blogger.
      This site is in no way affiliated with or endorsed by specified business. It exists as a compendium of supporting information intended for informational purposes only. If you want to buy this website, please don't hesitate to contact us via e-mail: "d e n a c c 9 7 7 (at) g m a i l (dot) c o m" (delete spaces) or you can find and buy it on Afternic domain auctions.