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 :
- Input the value 'n'
- Check whether 'n' is greater than 0(zero)
- If print with '+' sign else only print 'n'
- 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
Post a Comment