Computer Science » C Program » Find Average of Two Numbers
Program :
#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
| 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 Info | ENGG DIPLOMA | UGC NET Total Info |
| IES 2023 Total Info | PSUs 2022 Total Info | CSIR UGC NET Total Info |
| JAM 2023 Total Info | M TECH 2023 Total Info | RAILWAY 2022 Total Info |
Related Posts
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 » Print All Prime Numbers between 1 and 100 Program : [php]#include <stdio.h> int main() { int number,j,flag; printf(" The prime numbers between 1 and 100 : n"); for(number=2;number<=100;number++) { flag=0; for(j=2;j<=number/2;j++) { if(number % j == 0) { flag = 1; break; } } if(flag==0) printf("n %d ",number); } return 0; }[/php] Output : [php]The prime numbers between 1 and 100 : 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 [/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]