C Program to check whether the given integer is positive or negative
/* Description: A program to check whether the input * integer number is positive or negative. * Written by: Santosh Asole */ #include <stdio.h> void main() { int num; printf("Enter a number: \n"); scanf("%d", &num); if (num > 0) printf("%d is a positive number \n", num); else if (num < 0) printf("%d is a negative number \n", num); else printf("0 is neither positive nor negative"); }
Output 1:
Enter a number: 0 0 is neither positive nor negative
Output 2:
Enter a number: -3 -3 is a negative number
Output 3:
Enter a number: 100 100 is a positive number
Program to find largest of three input numbers
#include<stdio.h> int main() { int num1,num2,num3; //Ask user to input any three integer numbers printf("\nEnter value of num1, num2 and num3:"); //Store input values in variables for comparsion scanf("%d %d %d",&num1,&num2,&num3); if((num1>num2)&&(num1>num3)) printf("\n Number1 is greatest"); else if((num2>num3)&&(num2>num1)) printf("\n Number2 is greatest"); else printf("\n Number3 is greatest"); return 0; }Output:
Enter value of num1, num2 and num3: 15 200 101 Number2 is greatest
Comments
Post a Comment