C Program to check whether the number is +ve or not

Solution with out using functions
Solution using functions without passing arguments
Solution using functions and by passing arguments



Solution : Without using function
Program/Source Code

#include <stdio.h>
 int main()
 {
     int n;
     printf("Enter any no ");
     scanf("%d",&n);
     if(n>0)
        printf("Number is +ve");
     else
        printf("Number is not +ve");

 return 0;
 }

Output:

case 1:
Enter any no 36
Number is +ve

case 2:
Enter any no -96
Number is not +ve



Solution : Using function Without Passing Arguments
Program/Source Code

#include <stdio.h>
void check()
{
     int n;
     printf("Enter any no ");
     scanf("%d",&n);
     if(n>0)
        printf("Number is +ve");
     else
        printf("Number is not +ve");
}
 int main()
 {
     check();
     return 0;
 }

Output:

case 1:
Enter any no 67
Number is +ve

case 2:
Enter any no -92
Number is not +ve



Solution : Using function Passing Arguments
Program/Source Code

#include <stdio.h>
void check(int n)
{
     if(n>0)
        printf("Number is +ve");
     else
        printf("Number is not +ve");
}
 int main()
 {
     int n;
     printf("Enter any no ");
     scanf("%d",&n);
     check(n);
     return 0;
 }

Output:

case 1:
Enter any no 23
Number is +ve

case 2:
Enter any no -99
Number is not +ve

Next: Number is -ve or not

Programming Solutions @ rajeshshukla

All Programs
C Language Simple Programs
C Language If Condition and Switch Statement Programs
C Language Loop Programs
C Language Conversion Programs
C Language Pattern Programs
C Language Single Dimension Numeric Array programs
C Language Double Dimension Numeric Array Programs
C Language Single Dimension Character Array programs
C Language Pointer Programs
C Language File Handling Programs

Tutorials

Technical Questions

Interview Questions

C Programming
C++ Programming
Class 11 (Python)
Class 12 (Python)
C Language
C++ Programming
Python

C Interview Questions
C++ Interview Questions