0% found this document useful (0 votes)
4 views3 pages

Module 5 C Programming Complete

The document provides an overview of key concepts in C programming, including pointers, structures, and their usage. It includes examples of pointer declaration and initialization, structure declaration and initialization, and programs to compute average marks and statistical measures using arrays. The content is structured as a series of questions and answers, demonstrating practical coding implementations.

Uploaded by

tharunkumarsv1
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)
4 views3 pages

Module 5 C Programming Complete

The document provides an overview of key concepts in C programming, including pointers, structures, and their usage. It includes examples of pointer declaration and initialization, structure declaration and initialization, and programs to compute average marks and statistical measures using arrays. The content is structured as a series of questions and answers, demonstrating practical coding implementations.

Uploaded by

tharunkumarsv1
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/ 3

C Programming - BESCK104E/204E

Module 5: Complete Answers

Q1. Define a pointer and explain the declaration and initialization of a pointer variable with an

example.

A pointer is a variable that stores the address of another variable.

Declaration:

int *ptr;

Initialization:

int x = 10; ptr = &x;

Accessing value:

printf("%d", *ptr);

Q2. Define a structure and explain its declaration and initialization with an example.

A structure is a user-defined data type that groups variables of different types.

Declaration:

struct Student {

int id;

char name[20];

float marks;

};

Initialization:

struct Student s1 = {1, "John", 89.5};

Q3. Explain how members of a structure are accessed, initialized, and declared.

Declaration:

struct Student s1;

Initialization:

s1.id = 101;

strcpy(s1.name, "Ravi"); s1.marks = 95.5;


Access:

printf("%d %s %.2f", s1.id, s1.name, s1.marks);

Q4. Implement structures to read, write and compute average marks and the students scoring above

and below the average marks for a class of N students.

#include <stdio.h>

struct Student {

char name[20];

float marks;

};

int main() {

struct Student s[100];

int n; float sum = 0, avg;

printf("Enter number of students: ");

scanf("%d", &n);

for(int i=0; i<n; i++) {

printf("Enter name and marks: ");

scanf("%s %f", s[i].name, &s[i].marks);

sum += s[i].marks;

avg = sum / n;

printf("Above average:\n");

for(int i=0;i<n;i++) if(s[i].marks > avg) printf("%s %.2f\n", s[i].name, s[i].marks);

printf("Below average:\n");

for(int i=0;i<n;i++) if(s[i].marks < avg) printf("%s %.2f\n", s[i].name, s[i].marks);

return 0;

Q5. 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 arr[100], *p, sum = 0, mean, sd = 0;

int n, i;

printf("Enter number of elements: ");

scanf("%d", &n);

p = arr;

for(i=0; i<n; i++) {

scanf("%f", p+i);

sum += *(p+i);

mean = sum / n;

for(i=0; i<n; i++) {

sd += pow(*(p+i) - mean, 2);

sd = sqrt(sd / n);

printf("Sum = %.2f\nMean = %.2f\nSD = %.2f\n", sum, mean, sd);

return 0;

You might also like