Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

Number of significant digits for a floating type

August 13, 2013 Posted by: GPA Views: 609 0 comments

Task

Write a C program to find the sum of two number and write the result in three significant digits.

Solution 

  
  

#include <stdio.h>
#include <stdlib.h>
//main function
int main(int argc, char *argv[]){
       double sum;//variable for sum
       double firstnumber;
       double secondnumber;
       printf("Enter first number: ");
       scanf("%lf",&firstnumber);
       printf("Enter second number: ");
       scanf("%lf",&secondnumber);
       sum=firstnumber+secondnumber;//add
       printf("Sum = %.3f\n",sum);//%.3f mean  significant digits
      system("PAUSE");//delay
    return 0;
}


Output

Download this example

0 Comments...

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe