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 » 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 » Find Largest Element in Array Program : [php]#include<stdio.h> int main() { int a[30], i, num, largest; printf("nEnter no of elements : "); scanf("%d", &num); //Read n elements in an array for (i = 0; i < num; i++) scanf("%d", &a[i]); //Consider first element as largest largest = a[0]; for (i = 0; i < num; i++) { if (a[i] > largest) { largest = a[i]; } } // Print out the Result printf("nLargest element is : %d", largest); return (0); }[/php] Output : [php]Enter no of elements : 5 10 20 30 40 50 Largest element is : 50[/php]