Letter Grade Calculater
I write a program which calculate the letter grade.
It is also simple program. I started to use dynamic
memory allocation with this program.
Here is the code :
#include <stdio.h>
#include <stdlib.h>
void pass(double *a,int b,char *c)
{
int i;
double d=0;
for(i=0;i<b;i++)
{
d+=a[i];
}
d/=(double)b;
if(d<101&&d>89)
*c='A';
else if(d<90&&d>79)
*c='B';
else if(d<80&&d>69)
*c='C';
else if(d<70&&d>59)
*c='D';
else if(d<60&&d>0)
*c='F';
else
*c='E';
}
int main()
{
int num,i;
double *grades;
char note;
printf("Enter the number of grades\n");
scanf("%d",&num);
grades=(double *)calloc(num,sizeof(double));
for(i=0;i<num;i++)
{
printf("Enter a numeric grade between 0-100\n");
scanf("%lf",&grades[i]);
}
pass(grades,num,¬e);
printf("The grade is %c\n",note);
free(grades);
system("PAUSE");
return 0;
}
It is also simple program. I started to use dynamic
memory allocation with this program.
Here is the code :
#include <stdio.h>
#include <stdlib.h>
void pass(double *a,int b,char *c)
{
int i;
double d=0;
for(i=0;i<b;i++)
{
d+=a[i];
}
d/=(double)b;
if(d<101&&d>89)
*c='A';
else if(d<90&&d>79)
*c='B';
else if(d<80&&d>69)
*c='C';
else if(d<70&&d>59)
*c='D';
else if(d<60&&d>0)
*c='F';
else
*c='E';
}
int main()
{
int num,i;
double *grades;
char note;
printf("Enter the number of grades\n");
scanf("%d",&num);
grades=(double *)calloc(num,sizeof(double));
for(i=0;i<num;i++)
{
printf("Enter a numeric grade between 0-100\n");
scanf("%lf",&grades[i]);
}
pass(grades,num,¬e);
printf("The grade is %c\n",note);
free(grades);
system("PAUSE");
return 0;
}
Comments
Post a Comment