Pop Lab Programs (10,11,12)
Pop Lab Programs (10,11,12)
10. Implement structures to read, write and compute average- marks of the students, list the
students scoring above and below the average marks for a class of N students.
#include<stdio.h>
struct student
{
char usn[10];
char name[10];
float m1,m2,m3;
float avg,total;
};
void main()
{
struct student s[20];
int n,i;
float tavg,sum=0.0;
printf("Enter the number of student=");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the detail of %d students\n",i+1);
printf("\n Enter USN=");
scanf("%s",s[i].usn);
printf("\n Enter Name=");
scanf("%s",s[i].name);
printf("Enter the three subject score\n");
scanf("%f%f%f",&s[i].m1,&s[i].m2,&s[i].m3);
s[i].total=s[i].m1+s[i].m2+s[i].m3;
s[i].avg=s[i].total/3;
}
for(i=0;i<n;i++)
{
if(s[i].avg>=35)
printf("\n %s has scored above the average marks",s[i].name);
else
printf("\n %s has scored below the average marks",s[i].name);
}
}
11. Develop a program using pointers to compute the sum, mean and standard deviation of
all elements stored in an array of N real numbers.
#include<stdio.h>
#include<math.h>
int main(){
float a[50], *ptr, sum, mean, std, variance, sumstd;
int n, i;
printf("Enter the value of n\n");
scanf("%d", &n);
printf("Enter the real numbers\n");
for(i=0;i<n;i++){
scanf("%f", &a[i]);
}
sum = 0;
sumstd = 0;
ptr = a;
for(i=0;i<n;i++){
sum = sum + *ptr;
ptr++;
}
mean = sum / n;
ptr = a;
for(i=0;i<n;i++){
sumstd = sumstd + pow((*ptr - mean), 2);
ptr ++;
}
variance = sumstd / n;
std = sqrt(variance);
printf("Sum value is %f\n", sum);
printf("Mean value is %f\n", mean);
printf("Standard Deviation is %f\n", std);
return 0;
}
12. Write a C program to copy a text file to another, read both the input file name and target
file name.
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fptr1, *fptr2;
char filename[100], c;
fclose(fptr1);
fclose(fptr2);
return 0;
}