In this post we have uploaded some of the important programs for Anna University Semester Examinations. These programs were given at the syllabus as Example Programs. During the exam they may ask any kind of program to test your programming skills.
Mostly they will ask example programs from the questions, so keep prepared. Instead of writing theory questions for four to six pages you can attend programming questions which you can complete within two pages and saves lots of time.
1. Finding average of numbers stored in sequential access file.
Program
/* Sum and average of numbers stored in sequential access file */
/*Author : https://cse-r17.blogspot.com*/
#include <stdio.h>
int main (int argc, const char * argv[])
{
// Declaration of file
// Declaration of file
FILE *input;
// declaration of variable
int term, sum, total_items=0, avg;
// declaration of variable
int term, sum, total_items=0, avg;
sum = 0;
// opening the file
// opening the file
input = fopen("input.txt","r");
// Reading content in the files
// Reading content in the files
while(!feof(input))
{
fscanf(input,"%d",&term);
sum = sum + term;
total_items = total_items+1;
}
fclose(input);
//Using General Average formulae
//Using General Average formulae
avg=sum/total_items;
printf("The sum of the numbers is %d.\n",sum);
printf("The Average of the numbers is %d.\n",avg);
return 0;
}
input.txt
1 2 3
Output
The sum of the numbers is 6.
The Average of the numbers is 2.
Post a Comment