Program to check whether a number is positive, negative or is zero:
(I did this while one of the teaching sessions in a few minutes to encourage student for coming out with new solutions )many programs same thing:
1:
2:
1:
#include<stdio.h> int main() { int a,b; printf("enter the number"); scanf("%d",&a); if(a==0) { printf(" %d number is 0",a); } else { if(a>0) { printf(" %d number is possitive",a); } else { printf("%d number is nagitive",a); } } return 0; }
2:
#include<stdio.h> int main() { int a,b; printf("enter the number"); scanf("%d",&a); if(a>0) { printf(" %d number is possitive",a); } else if(a<0) { printf("%d number is nagitive",a); } else if(a==0) { printf(" %d number is 0",a); } return 0; }3:
#include<stdio.h> int main() { int a,b; printf("enter the number"); scanf("%d",&a); if(a>0) { printf(" %d number is possitive",a); } else if(a<0) { printf("%d number is nagitive",a); } else { printf(" %d number is 0",a); } return 0; }4:
#include<stdio.h> int main() { int a,b; printf("enter the number"); scanf("%d",&a); if(a>0 || a<0 ) { if(a>0) { printf(" %d number is possitive",a); } else if(a<0) { printf("%d number is nagitive",a); } } else { printf(" %d number is 0",a); } return 0; }5:
#include<stdio.h> int main() { int a,b; printf("enter the number"); scanf("%d",&a); if(a>0 | a<0 ) { if(a>0) { printf(" %d number is possitive",a); } else if(a<0) { printf("%d number is nagitive",a); } } else { printf(" %d number is 0",a); } return 0; }6:
#include<stdio.h> int main() { int a,b; printf("enter the number"); scanf("%d",&a); if(a!=0) { if(a>0) { printf(" %d number is possitive",a); } else { printf("%d number is nagitive",a); } } else { printf(" %d number is 0",a); } return 0; }
No comments:
Post a Comment