Print and separate the positive and negative numbers using For Loop in C


This program is about to separate and print the positive or negative number up to limit using For Loop

Source Code

#include<stdio.h>
int main()
{
  int i,n,pos,neg,s;
  printf("\nEnter the starting value:");
  scanf("%d",&i);
  s=i;
  printf("\nEnter the ending value:");
  scanf("%d",&n);
  printf("\nNegative numbers:");
  for(i;i<=n;i++)
  {
  if(i<0)
  {
    printf("\n%d",i);
    neg++;
  }
  }
  i=s;
  printf("\nPositive numbers:");
  for(i;i<=n;i++)
  {
    if(i>0)
    {
      printf("\n%d",i);
      pos++;
    }
  }
  printf("\nTotal number of positive:%d",pos);
  printf("\nTotal number of negative:%d",neg);
  return 0;
}
         
To download raw file Click Here

Output

Enter the starting value: -5
Enter the ending value: 5
Negative numbers:
-5
-4
-3
-2
-1

Positive numbers:
1
2
3
4
5

Total number of positive:5
Total number of negative:5


List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes