Monday, February 28, 2011

Arrays

Evaluating a Test

#include <stdio.h>
#define STUDENT 3
#define ITEMS 25
void main()
{
char key[ITEMS+1],response[ITEMS+1];
int count,i,student,n,correct[ITEMS+1];
clrscr();
printf("Input key to the items\n");
for(i=0;i<ITEMS;i++)
scanf("%c",&key[i]);
scanf("%c",&key[i]);
key[i]='\0';
for(student=1;student<=STUDENT;student++)
{
count=0;
printf("\n");
printf("Input responses of student-%d\n",student);
for(i=0;i<ITEMS;i++)
scanf("%c",&response[i]);
scanf("%c",&response[i]);
response[i]='\0';
for(i=0;i<ITEMS;i++)
correct[i]=0;
for(i=0;i<ITEMS;i++)
if(response[i]==key[i])
{
count=count+1;
correct[i]=1;
}
printf("Student-%d\n",student);
printf("Score is %d Out of %d\n",count,ITEMS);
printf("Response to the items below are wrong\n");
n=0;
for(i=0;i<ITEMS;i++)
if(correct[i]==0)
{
printf("%d ",i+1);
n++;
}
if(n==0)
printf("NIL\n");
printf("\n");
}
getch();
}

No comments:

Post a Comment