#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;
}
Computer Science » C Program » Even Number Pyramid Program : [php]#include<stdio.h> int main() { int i, j, num = 2; for (i = 0; i < 4; i++) { num = 2; for (j = 0; j <= i; j++) { printf("%dt", num); num = num + 2; } printf("n"); } return (0); }[/php] Output : [php]2 2 4 2 4 6 2 4 6 8 [/php]
Computer 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]
Computer Science » C Program » Find greatest in 3 numbers Program : [php]#include<stdio.h> int main() { int a, b, c; printf("nEnter value of a, b & c : "); scanf("%d %d %d", &a, &b, &c); if ((a > b) && (a > c)) printf("na is greatest"); if ((b > c) && (b > a)) printf("nb is greatest"); if ((c > a) && (c > b)) printf("nc is greatest"); return(0); }[/php] Output : [php]Enter value for a,b & c : 12 16 20 c is greatest[/php]
Computer Science » C Program » Delete an Element from Specified Location from Array Program : [php]#include<stdio.h> int main() { int arr[30], num, i, loc; printf("nEnter no of elements : "); scanf("%d", &num); //Read elements in an array printf("nEnter %d elements : ", num); for (i = 0; i < num; i++) { scanf("%d", &arr[i]); } //Read the location printf("nLocation of the element to be deleted : "); scanf("%d", &loc); /* loop for the deletion */ while (loc < num) { arr[loc - 1] = arr[loc]; loc++; } num--; // No of elements reduced by 1 //Print Array for (i = 0; i < 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]
Computer 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]