Showing posts with label if else if. Show all posts
Showing posts with label if else if. Show all posts

Count number of students above,below and average students

Count no. of students above,below and average students

  #include<stdio.h>
  #include<conio.h>
   void main()
    {
     int a[10];
     int aa=0,ba=0,ae=0,i;
     clrscr();
     printf("Enter the marks:\n");
     for(i=0;i<10;i++)
       {
scanf("%d",&a[i]);
if(a[i]>55)
aa++;
else if(a[i]<55)
ba++;
else
ae++;
       }
     printf("No. OF AVG STUDENTS ARE:%d\n",ae);
     printf("No. OF ABOVE AVERAGE STUDENTS:%d\n",aa);
     printf("No. OF BELOW AVERAGE STUDENTS ARE:%d",ba);
    getch();
   }

constants usage in C

Basic example showing constants usage in C

#include
/*constants for bonus rates and sales*/
#define BONUSRATE1 0.1
#define BONUSRATE2 0.15
#define BONUSRATE3 0.2
#define SALES1 2000
#define SALES2 5000
#define SALES3 10000
int main()
{
int sales;
double commission;
/*get employees sales*/
printf("Please enter your total sales to the nearest dollar.\n");
scanf("%d", &sales);
/*calculate employees bonus based on info*/
if(sales <=2000)
{
commission = sales * BONUSRATE1;
printf("%g\n" , commission);
}
else if(sales > 2000 && sales <=5000)
{
commission = sales * BONUSRATE2;
printf("%g\n" , commission);
}
else
{
commission = sales * BONUSRATE3;
printf("%g\n" , commission);
}

return 0;
}