-->
Showing posts with label program to count total positive elements among 'n' elements.. Show all posts
Showing posts with label program to count total positive elements among 'n' elements.. Show all posts

program to count total positive elements among 'n' elements.

using turbo C++
-----------------------------------------------------------------------
// program to count total positive elements among 'n' elements.
#include <stdio.h>
#include<conio.h>
void main()
{
    int a[100],n,i,count=0;
    printf("enter total number\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter number for location=%d\n",i);
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        if(a[i]>0)
                {
                   count++;
                 }
    }
 printf("total positive elements is=%d",count);
    getch();
}
-------------------------------------------------------------------------------------------------------------------
using online compiler/devC++/codeblocks with return concept
---------------------------------------------------------------------------------------------------------------------
// program to count total positive elements among 'n' elements.
#include <stdio.h>

int main()
{
    int a[100],n,i;
    printf("enter total number\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter number for location=%d\n",i);
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
          if(a[i]>0)
                {
                   count++;
                 }
    }
       printf("total positive elements is=%d",count);
    return 0;
}