Find the Number of Elements in An Array : C Program

Computer Science » C Program » Find the Number of Elements in An Array

Program :

#include <stdio.h>
 
int main()
{
    int array[] = {10, 20, 30, 40, 50, 60, 70,80,90,100};
    int n,m;
 
    n = sizeof(array);
    m = n/sizeof(int);
 
    printf("Size of the given array is : %d", m);
    return 0;
}

Output :

Size of the given array is : 10
Subject Name : Computer Science
Exam Name : IIT GATE, UPSC ESE, RRB, SSC, DMRC, NMRC, BSNL, DRDO, ISRO, BARC, NIELIT
Posts Name : Assistant Engineer, Management Trainee, Junior Engineer, Technical Assistant
Computer Science Books

GATE 2023 Total InfoENGG DIPLOMAUGC NET Total Info
IES 2023 Total InfoPSUs 2022 Total InfoCSIR UGC NET Total Info
JAM 2023 Total InfoM TECH 2023 Total InfoRAILWAY 2022 Total Info

Related Posts

  • Even Number Pyramid : C ProgramComputer Science » C Program » Even Number Pyramid Program : [php]#include&lt;stdio.h&gt; int main() { int i, j, num = 2; for (i = 0; i &lt; 4; i++) { num = 2; for (j = 0; j &lt;= i; j++) { printf(&quot;%dt&quot;, num); num = num + 2; } printf(&quot;n&quot;); } return (0); }[/php] Output : [php]2 2 4 2 4 6 2 4 6 8 [/php]
    Tags: program, number, computer, science, output, programs
  • Reversing an Array Elements : C ProgramComputer Science » C Program » Reversing an Array Elements Program : [php]#include<stdio.h> int main() { int arr[30], i, j, num, temp; printf("nEnter no of elements : "); scanf("%d", &num); //Read elements in an array for (i = 0; i < num; i++) { scanf("%d", &arr[i]); } j = i - 1; // j will Point to last Element i = 0; // i will be pointing to first element while (i < j) { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; // increment i j--; // decrement j } //Print out the Result of Insertion printf("nArray after reversal : "); for (i = 0; i < num; i++) { printf("%d t", arr[i]); } return (0); }[/php] Output : [php]Enter no of elements : 5 10 20 30 40 50 Array after reversal : 50 40 30 20 10 [/php]
    Tags: program, array, elements, computer, science, output, programs
  • Find greatest in 3 numbers : C ProgramComputer Science » C Program » Find greatest in 3 numbers  Program : [php]#include&lt;stdio.h&gt; int main() { int a, b, c; printf(&quot;nEnter value of a, b &amp; c : &quot;); scanf(&quot;%d %d %d&quot;, &amp;a, &amp;b, &amp;c); if ((a &gt; b) &amp;&amp; (a &gt; c)) printf(&quot;na is greatest&quot;); if ((b &gt; c) &amp;&amp; (b &gt; a)) printf(&quot;nb is greatest&quot;); if ((c &gt; a) &amp;&amp; (c &gt; b)) printf(&quot;nc is greatest&quot;); return(0); }[/php] Output : [php]Enter value for a,b &amp; c : 12 16 20 c is greatest[/php]
    Tags: program, find, computer, science, output, programs
  • Delete an Element from Specified Location from Array : C ProgramComputer Science » C Program » Delete an Element from Specified Location from Array Program : [php]#include&lt;stdio.h&gt; int main() { int arr[30], num, i, loc; printf("nEnter no of elements : "); scanf("%d", &amp;num); //Read elements in an array printf("nEnter %d elements : ", num); for (i = 0; i &lt; num; i++) { scanf("%d", &amp;arr[i]); } //Read the location printf("nLocation of the element to be deleted : "); scanf("%d", &amp;loc); /* loop for the deletion */ while (loc &lt; num) { arr[loc - 1] = arr[loc]; loc++; } num--; // No of elements reduced by 1 //Print Array for (i = 0; i &lt; num; i++) printf("n %d", arr[i]); return (0); }[/php] Output : [php]Enter no of elements : 5 Enter 5 elements : 10 20 30 40 50 Location of the element to be deleted : 3 10 20 40 50[/php]
    Tags: program, array, computer, science, output, programs
  • Reverse a Given Number : C ProgramComputer Science » C Program » Reverse a Given Number  Program : [php]#include<stdio.h> int main() { int num, rem, rev = 0; printf("nEnter any number to be reversed : "); scanf("%d", &num); while (num >= 1) { rem = num % 10; rev = rev * 10 + rem; num = num / 10; } printf("nReversed Number : %d", rev); return (0); }[/php] Output : [php]Enter any number to be reversed : 123 Reversed Number : 321[/php]
    Tags: program, number, computer, science, output, programs

LEAVE A REPLY

Please enter your comment!
Please enter your name here