Print the positive and negative numbers using While Loop in C


This program is about print the positive and negative numbers upto given limits using While Loop

Source Code

#include<stdio.h>
int main()
{
  int i,n,pos,neg;
  printf("\nEnter the starting value:");
  scanf("%d",&i);
  printf("\nEnter the Ending value:");
  scanf("%d",&n);
  printf("\nNegative numbers:");
  while(i<=n)
  {
    if(i<0)
    {
       printf("\n%d",i);
       neg++;
    }
    i++;
  }
  printf("\nPositive numbers:");
  i=0;
  while(i<=n)
  {
    if(i>0)
    {
       printf("\n%d",i);
       pos++;
    }
    i++;
  }
  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: -6
Enter the Ending value: 6
Negative numbers:
-6
-5
-4
-3
-2
-1
Positive numbers:
1
2
3
4
5
6
Total number of Positive:6
Total number of Negative:6


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