Cheak input number is ‘positive’ or ‘negative’ in C language..

Cheak number is ‘negative’ or ‘positive’….

This programme is very simple so, you can understand very eaisly. Here only use the condition programme in it. Compare with only Zero.

Some important symbols used in code.

  • () small bracket
  • && use for ‘and’ use for address
  • {} curly bracket
  • “” double code
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. int a, b, c;
  6. clrscr();
  7. printf(“Inputs any number to know it is positive or negative”);
  8. scanf(“%d”, &a);
  9. if(a>=0)
  10. {
  11. printf(“it is a positive = %d”, a);
  12. }
  13. else
  14. {
  15. printf(“it is a negative = %d”, a);
  16. }
  17. getch();
  18. }

Results..

Cheak number is ‘negative’ or ‘positive’ by condition operator….

  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. int a, b, c;
  6. clrscr();
  7. printf(“Inputs any number to know it is positive or negative”);
  8. scanf(“%d”, &a);
  9. a>0? printf(“it is a positive = %d”, a):printf(“it is a negative = %d”, a);
  10. getch();
  11. }

Results..

Leave a Reply

Create your own website, free on WordPress.com.Create your own website.
Start free