#include <stdio.h>
int main()
{
int num1, num2;
float avg;
printf("nEnter first number : ");
scanf("%d",&num1);
printf("nEnter second number : ");
scanf("%d",&num2);
avg= (float)(num1+num2)/2;
printf("nAverage of %d and %d is : %f",num1,num2,avg);
return 0;
}
Output :
Enter first number : 5
Enter second number : 3
Average of 5 and 3 is : 4.00
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 » Rectangle using Line and Special Symbols Program : [php]#include<stdio.h> int main() { int i, j; for (i = 0; i < 10; i++) { printf("n"); for (j = 0; j < 10; j++) { if (i == 0 || i == 9 || j == 0 || j == 9) printf("▲"); else printf("-"); } } return (0); }[/php] Output : [php]▲▲▲▲▲▲▲▲▲▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲▲▲▲▲▲▲▲▲▲[/php]
Computer Science » C Program » Check if a Number is Divisible by 3 Program : [php]#include<stdio.h> int main() { int number; printf("Enter a number : "); scanf("%d",&number); if ((number % 3) == 0) printf("n%d is a multiple of 3.",number); else printf("n%d is not a multiple of 3.",number); return 0; }[/php] Output 1: [php]Enter a number : 9 9 is a multiple of 3.[/php] Output 2: [php]Enter a number : 8 8 is not a multiple of 3.[/php]
Computer Science » C Program » Check if Number is Odd or Even Program : [php]#include<stdio.h> int main() { int n; printf("nEnter a number : "); scanf("%d",&n); if ( n%2 == 0 ) printf("n%d is an even number.", n); else printf("n%d is an odd number.", n); return 0; }[/php] Output 1: [php]Enter an number : 122 122 is an even number.[/php] Output 2: [php]Enter an number : 123 123 is an odd number.[/php]