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 » Check Whether a Number is Prime or Not Program : [php]#include<stdio.h> int main() { int num, i, count = 0; printf("nEnter a number :"); scanf("%d", &num); for (i = 2; i <= num / 2; i++) { if (num % i == 0) { count++; break; } } if (count == 0) printf("n%d is a prime number.", num); else printf("n%d is not a prime number.", num); return 0; }[/php] Output 1: [php]Enter a number : 5 5 is a prime number.[/php] Output 2: [php]Enter a number : 4 4 is not a prime number.[/php]
Computer Science » C Program » Inverted Pyramid Program : [php]#include<stdio.h> int main() { int i, j; char ch = '*'; for (i = 4; i >= 0; i--) { printf("n"); for (j = 0; j < i; j++) printf("%c", ch); } return(0); }[/php] Output : [php]**** *** ** *[/php]