0% found this document useful (0 votes)
6 views6 pages

Pop Lab Programs (10,11,12)

The document contains three C programs: the first program calculates the average marks of students and identifies those scoring above or below average; the second program uses pointers to compute the sum, mean, and standard deviation of an array of real numbers; and the third program copies the contents of one text file to another, prompting the user for both file names.

Uploaded by

hchandrika116
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Pop Lab Programs (10,11,12)

The document contains three C programs: the first program calculates the average marks of students and identifies those scoring above or below average; the second program uses pointers to compute the sum, mean, and standard deviation of an array of real numbers; and the third program copies the contents of one text file to another, prompting the user for both file names.

Uploaded by

hchandrika116
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

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;

printf("Enter the filename to open for reading \n");


scanf("%s", filename);

// Open one file for reading


fptr1 = fopen(filename, "r");
if (fptr1 == NULL)
{
printf("Cannot open file %s \n", filename);
exit(0);
}

printf("Enter the filename to open for writing \n");


scanf("%s", filename);

// Open another file for writing


fptr2 = fopen(filename, "w");
if (fptr2 == NULL)
{
printf("Cannot open file %s \n", filename);
exit(0);
}

// Read contents from file


c = fgetc(fptr1);
while (c != EOF) //end of file
{
fputc(c, fptr2);
c = fgetc(fptr1);
}

printf("\nContents copied to %s", filename);

fclose(fptr1);
fclose(fptr2);
return 0;
}

You might also like