Translate

Showing posts with label Home. Show all posts
Showing posts with label Home. Show all posts

Friday, April 17, 2020

Calculation of simple interest

/* Calculation of simple interest*/

#include<stdio.h>
#include<conio.h>
 void main()
{
int p, t;
float r, si;
clrscr();
printf("enter principle amount");
scanf("%d,& p);
printf(enter the value of rate");
scanf("%f,& r); 
printf(enter time");
scanf("%d,& r); 
/*formula for simple interest*/
si= p*t*r /100;
printf("\n simple interest = Rs. %f", si);
getch();
}

Useful  Notes & Tips

1.)  The scanf() function can be written as-
Scanf("control string" , address1, address2,.....);
 here you can see we are  using int and float type of variable to store the value. 
In this program
  
printf("enter principle amount");
scanf("%d,& p);

here, %d is used, which implies that one integer value should be entered as input. 
the next one is

 printf(enter the value of rate");

 scanf("%f,& r); 

in this statement %f is used, which means that a floating point number should be entered as input.

2.) \n is an escape sequence provide special formatting control. and here, \n represents new line.

3.) Simple interest is calculated by, 
simple interest = Principle*Time*Rate/100;

4.) getch() function is used to hold the screen until user gives any input or press any key.

5.) clrscr() function is a predefined function in conio.h header file. it's used to clear the screen or you can say clear the previous data of previous running program.








Request the user for two integer and print their sum.

Sum of two numbers


#include<stdio.h>
#include<conio.h>
  void main()
{
  int a, b, sum;

/* Printf() outputs the values to the screen whereas scanf() receive them from the keyboard.
   and  &   is a address used in scanf(). */
 printf("enter  first no=");
  scanf("%d", & a);
  printf("enter second no=");
  scanf("%d", & b);
  sum= a+b;
  printf("Sum of two number is =%d",sum);
  getch();
}
Output:






 Useful Notes & Tips

 1.) semicolon(;) - end of statement  C statement must end with a semicolon because it's acts as an statement terminator.


2.)  a, b, sum are variables. Here, you can use x/y/z because variable is just a name that can be store values.  it is an identifiers whose value vary during program execution. 


3.)  & is a address used in scanf(). when we say &a or any variable name , we are telling the scanf() at which memory location  should it store the value supplied by the user from the keyboard.


 4.) main() is function. every C program must be contain one function that is called main() function because program execution always start with main().  

 

5.) Comment about the program should be enclosed within /*  write your comment */
 

6.) comment is not mandatory but it's indicating the purpose of the program so easy to understand by user or programmer.
 

7.) you can write a comment at any place.

 8.) we can comment in small, capital, or special character. there is no any rules because comments are completely ignored by the compiler. 


9.) stdio.h is a header file. it's stands for standard input output.  it contain printf() and scanf() function.


10. conio stands for console input output. it is used for following functions: clrscr(), getch().

C program to make a calculator using the switch statement.

/*perform arithmetic calculation on integers in C language*/ #include<stdio.h> #include<conio.h> void main() {     char op;     ...