Thursday, 31 August 2017

Set Theory: P6 Counting Element from a set in C Language

Prepared By: Niraj Bhagchandani
Email: niraj.bhagchandani@live.com
Set Theory: Counting Element from a set
IN C LANGUAGE
Introduction:
  1. Take the input from the user.
  2. Calling count_element function and counting the elements one by one
  3. After the counting process, we print it.
imageedit_1_9127618562.png
Image Courtesy: ntu.edu.sg
---Program: ---
#include <stdio.h>
#define SIZE 10
void count_elements(int a[]){
   int i;
   /*Processing error for counting all the elements in an array */
   for(i=0;a[i];i++);
   /* Printing the total elements in an array */
   printf("The Total Elements are: %d", i);
}
int main(){
   int i, element;
   int a[SIZE]={'\0'}; /*={4,6,8,10,11,13,15,'\0'};*/
   /*Enter The total size for input of array a[] */
   printf("\nEnter element size <%d: ", SIZE);
   scanf("%d", &element);
   /* Program for input from user and storing to array begins */
   printf("\nEnter the value for array: \n");
   for(i=0;i<element;i++){
       printf("a[%d]: ", i);
       scanf("%d", &a[i]);
   }
   /* Program for input from user and storing to array ends */
   /* Calling the count_element function to perform all the operations */
   count_elements(a);

   return 0;
}
---Output:---


Enter element size <10: 5

Enter the value for array:
a[0]: 2
a[1]: 3
a[2]: 4
a[3]: 5
a[4]: 6
The Total Elements are: 5
Process returned 0 (0x0)   execution time : 9.077 s
Press any key to continue.


About This Article:
To cite this article add this reference and give credits to author.
  1. Bhagchandani, Niraj. “Set Theory: P6 Counting Element from a Set in C Language.”Edatastructure.blogspot.in, Blogger, 31 Aug. 2017, edatastructure.blogspot.in/2017/08/set-theory-p6-counting-element-from-set.html.

No comments:

Post a Comment