Review of Programming in C
Structures, Functions, File Handling & Pointers
Complete NEB Class 12 Computer Science notes on Programming in C тАФ structures, functions, file handling, operators, and pointers тАФ with fully solved MCQs, short answer questions, and 35+ solved C programs.
Exercise 1: Choose the correct answer.
Select an option to view the correct answer and justification.
Justification: A structure in C must be declared using the struct keyword followed by a tag name and a block containing its members, as in struct name {…};
Justification: The address-of operator (&) returns the memory address of a variable, e.g. &b gives the address of b. (The * operator is used to dereference a pointer, not to get an address.)
char str1[20]="Hello", str2[20]="World"; strcat(str1, str2); puts(str1);Justification: strcat() appends the second string directly to the end of the first string with no separator, so str1 becomes “HelloWorld”.
Justification: The “r” mode opens an existing file strictly for reading. “w” is for writing (overwrites), “a” is for appending, and “b” alone is not a valid standalone mode.
FILE *fpt;?Justification: FILE is actually a structure defined in stdio.h that stores information about a file stream, and fpt is declared as a pointer to that structure.
printf("%d", a++); in C programming?Justification: The post-increment operator (a++) uses the current value of a in the expression first, and only increments it afterward.
Justification: The “rb+” mode opens an existing binary file for both reading and writing, unlike “wb” (write-only, overwrites), “ab” (append-only), or “rb” (read-only).
int b = 25; int *p; p = &b; printf("%d %d", b, *p);Justification: p stores the address of b, so *p (dereferencing p) gives the value stored at that address, which is 25 тАФ the same as b itself.
Justification: Keywords are reserved words (like int, for, return) that already have a fixed, predefined meaning in the C language and cannot be used as identifiers.
Justification: A constant is a fixed value that cannot be altered once assigned, unlike a variable, whose value can change during execution.
Justification: A variable is a named storage location whose value can be changed during program execution, matching the given description exactly.
Justification: An operator (e.g. +, -, *) is a symbol that tells the compiler to perform a specific mathematical or logical operation on given operands.
Justification: An operand is the value or variable that an operator performs its action on, e.g. in a + b, both a and b are operands.
Exercise 2: Write short answers to these questions.
A user-defined or a user-readable custom name assigned to a memory location is known as a variable. The major data types which are used in a C program are as follows:
The four basic data types in C programming are namely char, int, float, and double. In the C programming language, the signed modifier represents both positive and negative values while the unsigned modifier means all positive values.
A structure can be defined as a single entity holding variables of different data types that are logically related to each other. All the data members inside a structure are accessible to the functions defined outside the structure. There are 6 sections in a C program that are Documentation, Preprocessor section, Definition, Global Declaration, main() function, and subprograms.
Syntax of structure:
struct structureName {
DataType member1;
DataType member2;
DataType memberN;
};
The different types of operators in C are as follows:
Logical operators: A logical operator is a symbol or word used to connect two or more expressions such that the value of the compound expression produced depends only on that of the original expressions and on the meaning of the operator. Common logical operators include AND, OR, NOT. An operator is used to compare logical expressions that return a result of true and false.
File handling in C involves a series of operations including the creation, opening, reading, writing, and closing of files. To accomplish these tasks, C provides a set of functions such as fopen(), fwrite(), fread(), fseek(), fprintf(), among others. The different modes of file handling are as follows:
| Array | Structure |
|---|---|
| Array is a collection of homogeneous data. | Structure is a collection of heterogeneous data. |
| Array data are accessed using an index. | Structure elements are accessed using a dot (.) operator. |
| Array allocates static memory. | Structure allocates dynamic memory. |
| Array element access takes less time than structures. | Structure elements take more time to access than Arrays. |
| Each data item is called an element. | Each data item is called a member. |
| We cannot have an array of arrays (in this context). | We can have an array of structures. |
Exercise 3: Long Answer Questions (Solved C Programs)
#include <stdio.h>
#include <conio.h>
struct books {
char title[50];
char author[20];
char publisher[30];
float price;
} b[5];
int main() {
int i;
printf("Enter the details of books:\n");
for (i = 0; i < 5; i++) {
printf("Enter book %d details\n", i + 1);
printf("----\n");
printf("Enter the title: ");
scanf("%s", b[i].title);
printf("Enter the author: ");
scanf("%s", b[i].author);
printf("Enter the publisher: ");
scanf("%s", b[i].publisher);
printf("Enter the price: ");
scanf("%f", &b[i].price);
}
// Display results
printf("The book details are:\n");
for (i = 0; i < 5; i++) {
printf("\nBook details %d", i + 1);
printf("\nTitle: %s", b[i].title);
printf("\nAuthor: %s", b[i].author);
printf("\nPublisher: %s", b[i].publisher);
printf("\nPrice: %f", b[i].price);
}
getch();
return 0;
}
Binary File Handling is a process in which we create a file and store data in its original format. It means that if we stored an integer value in a binary file, the value will be treated as an integer rather than text. Binary files are mainly used in storing records just as we store records in a database. A binary file contains data in binary form (i.e. 0’s and 1’s) instead of ASCII characters. They contain data that is stored in a similar manner to how it is stored in the main memory. Binary files can be created only from within a program and their contents can only be read by a program.
The getw() function is used to read binary data from a file. A pointer to the file stream from which the data is to be read serves as its sole argument. The file pointer is advanced in accordance with how the function reads the data, which normally reads as an integer (4 bytes).
The putw() function is used to write binary data to a file. The data to be written and a pointer to the file stream where the data is to be written are its required inputs. The data is written to the file as an integer, which is normally 4 bytes long.
#include <stdio.h>
#include <conio.h>
struct employees {
int EID;
char Name[50];
char Post[30];
char department[10];
} E[5];
int main() {
int i;
printf("Enter the details of employees\n");
for(i = 0; i < 5; i++) {
printf("Enter the employee information %d\n", i + 1);
printf("---\n");
printf("Enter the EID: ");
scanf("%d", &E[i].EID);
printf("Enter the Name: ");
scanf("%s", E[i].Name);
printf("Enter the Post: ");
scanf("%s", E[i].Post);
printf("Enter the department: ");
scanf("%s", E[i].department);
}
// Display results
printf("The employee information are:\n");
for(i = 0; i < 5; i++) {
printf("\nEmployee information %d\n", i + 1);
printf("EID: %d\n", E[i].EID);
printf("Name: %s\n", E[i].Name);
printf("Post: %s\n", E[i].Post);
printf("Department: %s\n", E[i].department);
}
getch();
}
Answer: A way to group several related variables into one place is known as a structure.
#include <stdio.h>
#include <conio.h>
struct student {
int ID;
char Name[50];
int DOB;
int phone;
} S[5];
int main() {
int i;
// Input loop
for(i = 0; i < 5; i++) {
printf("\nEnter the details of student %d\n", i + 1);
printf("-------------------\n");
printf("Enter the Name: ");
scanf("%s", S[i].Name);
printf("Enter the DOB: ");
scanf("%d", &S[i].DOB);
printf("Enter the ID: ");
scanf("%d", &S[i].ID);
printf("Enter the phone num: ");
scanf("%d", &S[i].phone);
}
// Display result
printf("\nThe student details are:\n");
for(i = 0; i < 5; i++) {
printf("\nDetails of student %d\n", i + 1);
printf("Name: %s\n", S[i].Name);
printf("DOB: %d\n", S[i].DOB);
printf("ID: %d\n", S[i].ID);
printf("Phone num: %d\n", S[i].phone);
}
getch();
return 0;
}
Answer: The process of file handling refers to how we store the available data or info in a file with the help of a program. The C language stores all the data available in a program into a file with the help of file handling in C. This data can be fetched/extracted from these files to work again in any program.
To create a file in C, the steps are as follows:
FILE *fptr = NULL;Answer: A collection of logically related variables of different data types is called a structure.
#include <stdio.h>
#include <conio.h>
struct Staff {
int staffid;
char name[50];
float salary;
} S[50];
int main() {
int i;
// Input loop
for(i = 0; i < 50; i++) {
printf("\nEnter the information of staff %d\n", i + 1);
printf("-------------------\n");
printf("Enter the staff id: ");
scanf("%d", &S[i].staffid);
printf("Enter the Name: ");
scanf("%s", S[i].name);
printf("Enter the salary: ");
scanf("%f", &S[i].salary);
}
// Display result
printf("\nThe information of staff details are:\n");
for(i = 0; i < 50; i++) {
if(S[i].salary >= 25000 && S[i].salary <= 40000) {
printf("\nInformation of staff %d\n", i + 1);
printf("Staff id: %d\n", S[i].staffid);
printf("Name: %s\n", S[i].name);
printf("Salary: %.2f\n", S[i].salary);
}
}
getch();
return 0;
}
#include <stdio.h>
#include <conio.h>
struct Student {
int grade;
char name[50];
int age;
char address[20];
} S[10];
int main() {
int i;
// Input loop
for(i = 0; i < 10; i++) {
printf("\nEnter the information of student %d\n", i + 1);
printf("-------------------\n");
printf("Enter the grade: ");
scanf("%d", &S[i].grade);
printf("Enter the name: ");
scanf("%s", S[i].name);
printf("Enter the age: ");
scanf("%d", &S[i].age);
printf("Enter the address: ");
scanf("%s", S[i].address);
}
// Display result
printf("\nThe student information details are:\n");
for(i = 0; i < 10; i++) {
printf("\nInformation of student %d\n", i + 1);
printf("Grade: %d\n", S[i].grade);
printf("Name: %s\n", S[i].name);
printf("Age: %d\n", S[i].age);
printf("Address: %s\n", S[i].address);
}
getch();
return 0;
}
Answer: The process of file handling refers to how we store the available data or info in a file with the help of a program. The C language stores all the data available in a program into a file with the help of file handling in C. This data can be fetched/extracted from these files to work again in any program.
#include <stdio.h>
#include <conio.h>
struct student_dat {
char name[50];
char address[30];
} s_dat[20];
int main() {
int i;
// Input loop
for(i = 0; i < 20; i++) {
printf("\nEnter the information of student %d\n", i + 1);
printf("-------------------\n");
printf("Enter the name: ");
scanf("%s", s_dat[i].name);
printf("Enter the address: ");
scanf("%s", s_dat[i].address);
}
// Display result
printf("\nThe information of Student details are:\n");
for(i = 0; i < 20; i++) {
printf("\nInformation of student %d\n", i + 1);
printf("Name: %s\n", s_dat[i].name);
printf("Address: %s\n", s_dat[i].address);
}
getch();
return 0;
}
Answer: A function declaration specifies the name of the function, the types and number of parameters it expects to receive, and its return type.
#include <stdio.h>
#include <conio.h>
int fact(int);
int main() {
int f, n;
printf("Enter any number: ");
scanf("%d", &n);
f = fact(n);
printf("The factorial of the number is %d\n", f);
getch();
return 0;
}
int fact(int n) {
if(n == 1) {
return 1;
} else {
return (n * fact(n - 1));
}
}
Answer: The three modes of file opening in C are:
r – read: Only reading is possible. It does not create a file if it does not exist. It opens a text file for reading.
w – write: Only writing is possible. It creates a file if it does not exist, otherwise, it erases the old content of the file and opens it as a blank file.
a – append: Only writing is possible. It creates a file if it does not exist, otherwise, it opens the file and writes from the end of the file (it does not erase the old content).
#include <stdio.h>
#include <conio.h>
struct exam_dat {
char name[50];
int roll;
} E_dat[20];
int main() {
int i;
// Input loop
for(i = 0; i < 20; i++) {
printf("\nEnter the information of student %d\n", i + 1);
printf("-------------------\n");
printf("Enter the name: ");
scanf("%s", E_dat[i].name);
printf("Enter the roll: ");
scanf("%d", &E_dat[i].roll);
}
// Display result
printf("\nThe information of student details are:\n");
for(i = 0; i < 20; i++) {
printf("\nInformation of student %d\n", i + 1);
printf("Name: %s\n", E_dat[i].name);
printf("Roll: %d\n", E_dat[i].roll);
}
getch();
return 0;
}
Answer: A collection of logically related variables of different data types is called a structure.
#include <stdio.h>
#include <conio.h>
struct Student {
int roll;
char name[50];
int age;
} S[5];
int main() {
int i;
printf("\nThe student details of %d\n", i);
for(i = 0; i < 5; i++)
{
printf("Enter the information of student %d", i+1);
printf("\n --- ");
printf("Enter the roll");
scanf("%d", &s[i].roll);
printf("Enter the name");
scanf("%s", s[i].name);
printf("Enter the age");
scanf("%d", &s[i].age);
}
// Display result
printf("The student details is %d are :", i);
for(i=0; i<5; i++)
{
printf("Enter the information of student %d", i+1);
printf("%d roll", s[i].roll);
printf("%s name", s[i].name);
printf("%d age", s[i].age);
}
getch();
}
#include<stdio.h>
#include<conio.h>
struct emp
{
int ID;
char name[20];
char post[20];
} e_txt[10];
int main()
{
int i;
printf("The information of employee is %d ", i);
for(i=0; i<10; i++)
{
printf("Enter the information of employee is %d", i+1);
printf("\n --- ");
printf("Enter the ID");
scanf("%d", &e_txt[i].ID);
printf("Enter the name");
scanf("%s", e_txt[i].name);
printf("Enter the post");
scanf("%s", e_txt[i].post);
}
// Display result
printf("The information of employee is %d ", i);
for (i=0; i<10; i++)
{
printf("Enter the information of employee is %d", i+1);
printf("%d ID", e_txt[i].ID);
printf("%s Name", e_txt[i].name);
printf("%s post", e_txt[i].post);
}
getch();
}
The three different types of operators in C are:
#include<stdio.h>
#include<conio.h>
int fib(int n);
int main()
{
int i, n, A;
printf("Enter the number");
scanf("%d", &n);
for(i=6; i<=n; i++)
A = fib(n);
printf("%d \t", A);
getch();
}
int fib(int n)
{
if(n==0 || n==1)
return n;
else
return(fib(n-1) + fib(n-2));
}
#include<stdio.h>
#include<conio.h>
struct employees
{
int empno;
char name[50];
float salary;
} e[100];
int main()
{
int i;
printf("The information of employee is %d", i);
for(i=0; i<100; i++)
{
printf("Enter the information of employee is %d", i+1);
printf("\n --- ");
printf("Enter the emp_no");
scanf("%d", &e[i].empno);
printf("Enter the name");
scanf("%s", e[i].name);
printf("Enter the salary");
scanf("%f", &e[i].salary);
}
// Display result
printf("The information of employee is %d ", i);
for(i=0; i<100; i++)
{
printf("Enter the information of employee is %d", i+1);
printf("%d emp_no", e[i].empno);
printf("%s name", e[i].name);
printf("%.2f salary", e[i].salary);
}
getch();
}
A function is defined as a relation between a set of inputs having one output each.
#include<stdio.h>
#include<conio.h>
int num(int n);
int main()
{
int n;
printf("Enter the number");
scanf("%d", &n);
num(n);
getch();
}
int num(int n)
{
if(n>0)
{
printf("%d is positive number", n);
}
else
{
printf("%d is negative number", n);
}
}
The process of file handling refers to how we store the available data or info in a file with the help of a program.
#include<stdio.h>
#include<conio.h>
struct employee
{
char Name[50];
float salary;
} e_txt[10];
int main()
{
int i;
printf("The information of employee is %d", i);
for(i=0; i<10; i++)
{
printf("Enter the information of employee is %d", i+1);
printf("\n --- ");
printf("Enter the Name");
scanf("%s", e_txt[i].Name);
printf("Enter the salary");
scanf("%f", &e_txt[i].salary);
}
// Display result
printf("The information of employee are: %d", i);
for(i=0; i<10; i++)
{
printf("Enter the information of employee is %d", i+1);
printf("%s name", e_txt[i].Name);
printf("%.2f salary", e_txt[i].salary);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i, marks[100], p=0, f=0;
for(i=0; i<5; i++)
{
printf("enter the marks:");
scanf("%d", &marks[i]);
if(marks >= 35)
{
printf("student has passed");
p++;
}
else
{
printf("student has failed");
f++;
}
}
printf("Number of student passed: %d", p);
printf("Number of student failed: %d", f);
getch();
}
A structure in c is a user-defined data type that allows one to store data of different types under one name.
#include<stdio.h>
#include<conio.h>
struct student
{
char name[50];
int age;
char gender[20];
} s[5];
int main()
{
int i;
printf("The information of student is %d", i);
for(i=0; i<5; i++)
{
printf("Enter the details of student is %d", i+1);
printf("\n --- ");
printf("Enter the name");
scanf("%s", s[i].name);
printf("Enter the age");
scanf("%d", &s[i].age);
printf("Enter the gender");
scanf("%s", s[i].gender);
}
// Display result
printf("The information of student is %d", i);
for(i=0; i<5; i++)
{
printf("Enter the details of student is %d", i+1);
printf("%s name", s[i].name);
printf("%d age", s[i].age);
printf("%s gender", s[i].gender);
}
getch();
}
A user-defined function is a type of function in c language that is defined by the user himself to perform some specific task.
#include <stdio.h>
// User-defined function declaration (prototype)
float calculateArea(float length, float breadth);
int main() {
float length, breadth, area;
// Prompt user for input
printf("Enter the length of the pond: ");
scanf("%f", &length);
printf("Enter the breadth of the pond: ");
scanf("%f", &breadth);
// Call the user-defined function and store the result in 'area'
area = calculateArea(length, breadth);
// Display the calculated area
printf("The area of the pond is: %.2f\n", area);
return 0;
}
// User-defined function definition
float calculateArea(float length, float breadth) {
// Area of a rectangle (pond) is length multiplied by breadth
return length * breadth;
}
A collection of logically related variables of different data types is called structure.
#include<stdio.h>
#include<conio.h>
struct employee
{
int employee_id;
char name[50];
char address[30];
} e[20];
int main()
{
int i;
printf("The information of student is %d", i);
for(i=0; i<10; i++)
{
printf("Enter the information of student is %d", i+1);
printf("\n --- ");
printf("Enter the employee id");
scanf("%d", &e[i].employee_id);
printf("Enter the name");
scanf("%s", e[i].name);
printf("Enter the address");
scanf("%s", e[i].address);
}
// Display result
printf("The student information is %d :", i);
for(i=0; i<10; i++)
{
printf("Enter the student information is %d", i+1);
printf("%d employee id", e[i].employee_id);
printf("%s name", e[i].name);
printf("%s address", e[i].address);
}
getch();
}
A user-defined function is a type of function in c language that is defined by the user himself to perform some specific task.
The advantages of function are:
Difference between library and user defined function:
| Library-Defined Function | User-Defined Function |
|---|---|
| It refers to predefined functions or built-in functions in C libraries. | It is a function which is created by the user as per their own requirements. |
| It is already created. | We have to create it ourselves. |
| It is simple to use. | It is usually more complex to use. |
| Program development time is faster. | Program development time is slower. |
| It requires a header file to use it. | It requires a function prototype to use it. |
| It is called at run time. | It is called at compile time. |
#include <stdio.h>
#include <conio.h>
struct student
{
char name[20];
int roll;
int regno;
} st[10];
int main()
{
int i;
printf("The information of 10 students\n");
for (i = 0; i < 10; i++)
{
printf("Enter the information of student %d\n", i + 1);
printf("--------------------------------------\n");
printf("Enter the name: ");
scanf("%s", st[i].name);
printf("Enter the roll: ");
scanf("%d", &st[i].roll);
printf("Enter the registration number: ");
scanf("%d", &st[i].regno);
}
// Display result
printf("\nThe information of student is:\n");
for (i = 0; i < 10; i++)
{
printf("\nInformation of student %d:\n", i + 1);
printf("Name: %s\n", st[i].name);
printf("Roll: %d\n", st[i].roll);
printf("Registration No: %d\n", st[i].regno);
}
getch();
}
Definition: A function prototype specifies the name of the function, the types and number of parameters it expects to receive, and its return type.
#include <stdio.h>
#include <conio.h>
float si(float p, float t, float r);
int main()
{
float P, T, R, SI;
printf("Enter the principle: ");
scanf("%f", &P);
printf("Enter the time: ");
scanf("%f", &T);
printf("Enter the rate: ");
scanf("%f", &R);
SI = si(P, T, R);
printf("The simple interest is: %f\n", SI);
getch();
return 0;
}
float si(float p, float t, float r)
{
return (p * t * r) / 100;
}
The importance / key features of functions in a C program are:
#include <stdio.h>
#include <conio.h>
int check(int n);
int main()
{
int n;
printf("Enter the number: ");
scanf("%d", &n);
check(n);
getch();
return 0;
}
int check(int n)
{
if (n % 2 == 0)
{
printf("The even number is %d\n", n);
}
else
{
printf("The odd number is %d\n", n);
}
}
Definition: The C string functions are built-in functions that can be used for various operations and manipulations on strings. These string functions can be used to perform tasks such as string copying, concatenation, comparison, length, etc. The <string.h> header file contains these string functions.
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main() {
char text[100];
int i, length;
printf("Enter the text to reverse: ");
gets(text);
length = strlen(text);
printf("Reversed text: ");
for(i = length - 1; i >= 0; i--) {
printf("%c", text[i]);
}
printf("\n");
getch();
return 0;
}
Definition: A structure in C is a user-defined data type that can be used to group items of possibly different types into a single type.
#include <stdio.h>
#include <conio.h>
struct Subject
{
int Eng, Nep, Sci, Eco, Acc;
} s[5];
int main()
{
int i;
int sum;
printf("The information of 5 subjects\n");
for (i = 0; i < 5; i++)
{
printf("Enter the information of subject group %d\n", i + 1);
printf("-------------------------------------------\n");
printf("Enter marks for 5 subjects (English, Nepali, Science, Economics, Account): ");
scanf("%d%d%d%d%d", &s[i].Eng, &s[i].Nep, &s[i].Sci, &s[i].Eco, &s[i].Acc);
}
// Display result
printf("\nThe information of 5 subjects are:\n");
for (i = 0; i < 5; i++)
{
sum = s[i].Eng + s[i].Nep + s[i].Sci + s[i].Eco + s[i].Acc;
printf("\nStudent %d marks:\n", i + 1);
printf("English: %d, Nepali: %d, Science: %d, Economics: %d, Account: %d\n",
s[i].Eng, s[i].Nep, s[i].Sci, s[i].Eco, s[i].Acc);
printf("Sum = %d\n", sum);
}
getch();
}
Definition: Functions in C are the basic building blocks of a program. A function is a set of statements enclosed within curly brackets {} that takes inputs, performs computations, and provides the resultant output.
#include <stdio.h>
#include <conio.h>
int sum(int n);
int main()
{
int num, A;
printf("Enter the number: ");
scanf("%d", &num);
A = sum(num);
printf("The sum of natural numbers is %d\n", A);
getch();
return 0;
}
int sum(int n)
{
if (n == 0)
{
return 0;
}
else
{
return (n + sum(n - 1));
}
}
| Array | Structure |
|---|---|
| An array is a collection of homogeneous data. | A structure is a collection of heterogeneous data. |
| Array elements are accessed using an index. | Structure elements are accessed using the dot (.) operator. |
| Arrays allocate static memory. | Structures allocate dynamic memory. |
| Accessing array elements takes less time. | Accessing structure elements takes more time. |
| Each data item is called an element. | Each data item is called a member. |
| We cannot have an array of arrays (directly as a single linear type). | We can have an array of structures. |
Definition: Control structures enable a programmer to determine the order in which program statements are executed.
#include <stdio.h>
int main()
{
int num1, num2, sum, diff, greater;
int choice;
printf("Enter two numbers: ");
scanf("%d%d", &num1, &num2);
printf("Choose an operation:\n");
printf("1. Sum\n");
printf("2. Difference\n");
printf("3. Greater number\n");
scanf("%d", &choice);
switch (choice)
{
case 1:
sum = num1 + num2;
printf("Sum = %d\n", sum);
break;
case 2:
diff = num1 - num2;
printf("Difference = %d\n", diff);
break;
case 3:
greater = (num1 > num2) ? num1 : num2;
printf("Greater number = %d\n", greater);
break;
default:
printf("Invalid Choice\n");
}
return 0;
}
#include <stdio.h>
#include <conio.h>
int add(int a, int b);
int main()
{
int a, b, A;
printf("Enter the two numbers: ");
scanf("%d%d", &a, &b);
A = add(a, b);
printf("The sum of two numbers is %d\n", A);
getch();
return 0;
}
int add(int a, int b)
{
return (a + b);
}
#include <stdio.h>
#include <conio.h>
int mul(int a, int b);
int main()
{
int a, b, M;
printf("Enter any two numbers: ");
scanf("%d%d", &a, &b);
M = mul(a, b);
printf("The multiplication of two numbers is %d\n", M);
getch();
return 0;
}
int mul(int a, int b)
{
return (a * b);
}
#include <stdio.h>
#include <conio.h>
void main()
{
int n, num, greatest, smallest, i;
printf("Enter the number of terms: ");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
printf("Enter number %d: ", i);
scanf("%d", &num);
if (i == 1)
{
greatest = num;
smallest = num;
}
if (num > greatest)
{
greatest = num;
}
if (num < smallest)
{
smallest = num;
}
}
printf("The greatest number is %d\n", greatest);
printf("The smallest number is %d\n", smallest);
getch();
}
ЁЯУД View / Download Full PDF Notes
If the PDF doesn’t load, click here to open it in Google Drive.
