Write C program to count total number of negative elements in array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <stdio.h> int main() { int arr[100]; //Declaring size of an array as 100 int i, num, count=0; //Reads size and elements of array printf("Enter size of the array : "); scanf("%d", &num); printf("Enter elements in array : "); for(i=0; i<num; i++) { scanf("%d", &arr[i]); } //Counts total number of negative elements for(i=0; i<num; i++) { if(arr[i]<0) { count++; //couting negative elements } } printf("\nTotal number of negative elements = %d", count); return 0; } |
24 June 2019 2728 Written By: Rohit
© 2020 Tech Study. All rights reserved | Developed by Tech Study| Privacy Policy | Sitemap