Print positive and negative numbers using One Dimensional Array in C


This program is about checking and print the numbers in array according to positive or negative using for loops and if conditions.

Source Code

#include<stdio.h>
int main()
{
  int i,j,a[10],n,m,b=0,c=0;
  printf("\nEnter the limit:");
  scanf("%d",&n);
  printf("\nEnter the values:");
  for(i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
  }
  printf("\nGiven values are:");
  for(i=0;i<n;i++)
  {
    printf("\na[%d]=%d",i,a[i]);
  }
  for(i=0;i<n;i++)
  {
    if(a[i]>0)
    {
       printf("\nPositive value a[%d]=%d",i,a[i]);
       c++;
    }
    else
    {
       printf("\nNegative value a[%d]=%d",i,a[i]);
       b++;
    }
  }
  printf("\nNo of positive numbers:%d",c);
  printf("\nNo of negative numbers:%d",b);
  return 0;
}



To download raw file Click Here

Output

Enter the limit:5
Enter the values:-3
1
-6
4
-2
Given values are:
a[0]=-3
a[1]=1
a[2]=-6
a[3]=4
a[4]=-2
Negative value a[0]=-3
Positive value a[1]=1
Negative value a[2]=-6
Positive value a[3]=4
Negative value a[4]=-2

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