C PROGRAM TO PRINT THE NUMBER ALONG WITH ITS SIGN

  

Consider the following I/O samples.


SAMPLE INPUT 1 : 110

SAMPLE OUTPUT 1 : +110


SAMPLE INPUT 2 : -110

SAMPLE OUTPUT 2 : -110


The algorithm used here is :

  1. Input the value 'n'
  2. Check whether 'n' is greater than 0(zero)
  3. If print with '+' sign else only print 'n' 
  4. Print the output

C PROGRAM:

#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    if(n>=0)
    printf("+%d",n);
    else
    printf("%d",n);
    return 0;
}


















OUTPUT:










The given source code in C program "to print the number along with its sign" is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free. 

If you have any feedback about this article and want to improve this, please comment in the comment section.


Comments

Popular posts from this blog

INVERTED PYRAMID STAR PATTERN

C PROGRAM TO PRINT ALL LEAP YEARS IN A GIVEN RANGE

C PROGRAM TO PRINT THE REMAINING DAYS AND COMPLETED DAYS FROM A GIVEN DATE