FCS Assignment
FCS Assignment
FCS Assignment
Characteristics of Algorithm:
1) An algorithm must contain blocks that will help to solve problems more
efficiently & logically
5) An algorithm must contain blocks that will help to solve problems more
efficiently & logically.
2) Increment Operator in C:
Mainly used for incrementing the value of an integer. It is represented by the ‘++’
operator. X++ will increase the value of the variable x instantly. But if it is placed
after the variable then it gets increased before the execution of the next statement.
#include <stdio.h>
#include<conio.h>
int main()
{
int a = 10;
clrscr();
a++;
printf(“Value of a: %d”, a);
getch();
return 0;
}
3) Decrement Operator in C:
Mainly used for decrementing the value of an integer. It is represented by the ‘--’
operator. X-- will decrease the value of the variable x instantly. But if it is placed
after the variable then it gets decreased before the execution of the next statement.
#include <stdio.h>
#include<conio.h>
int main()
{
int a = 10;
clrscr();
a--;
printf(“Value of a: %d”, a);
getch();
return 0;
}
4) Assignment Operators in C:
The purpose of this operator is to assign value to a variable. The most used
assignment operator is “=”.
Operator Example
= a = b or b = a
+= a += b or a = a + b
-= a -= b or a = a - b
*= a *= b or a = a*b
/= a /= b or a = a/b
%= a %= b or a = a % b
5) Relational Operators in C:
Mainly used for checking relationships between operands. With the help of this
operator, you can check whether one operand is equal to or greater than the other
operand or not.
It returns 1 when the relation is true. And when it is false, it returns 0.
6) Logical Operators in C:
In the C programming language, Logical operators are mostly used for decision
making. A logical operator returns either 0 or 1 whether the condition is true or
false.
Operator What it does
&& (Logical AND) True only if all conditions satisfy.
|| (Logical OR) True only if either one condition satisfies.
! (Logical Not) True only if the operand is 0.
7) Conditional Operator in C:
Also known as Ternary operator. The main purpose of conditional operators is in
decision making statements. It is similar to an if-else statement.
8) Bitwise Operator in C:
C also provides special operators for bit operation between two variables.
Operator Also known as
9) Special Operators in C:
Apart from these operators, C supports special operators:-
1. sizeof():- If you want to check the size of data types available in C then you
can do it by using sizeof() operator.
Ans. Control structures are used to alter the flow of execution of the
program.There are three types of control structures available in C:
All the 3 control structures and its flow of execution is represented in the flow
charts given below.
Control statements in C to implement control structures:
Switch
If
If Else
While
Do While
For
As shown in the flow charts:-
If and If Else statements are 2 way branching statements where as Switch is a multi
branching statement.
Statement 1;
Statement 2:
Statement 2;
The expression given inside the brackets after if is evaluated first. If the expression
is true, then statements inside the curly braces that follow if(expression) will be
executed. If the expression is false, the statements inside curly braces will not be
executed and program control goes directly to statements after curly braces.
Statement 2;
Statement 1;
Statement 2;
Statement 1;
Statement 2;
Else // If all expressions(1,2,3) are FALSE, the statements that follow this
else(inside curly braces) is executed.
Statement 1;
Statement 2;
Other statements;
Switch statement:
Case value 1: // case is the keyword used to match the integer/character constant
from expression.
Statement 1;
Statement 2;
Break; // break is a keyword used to break the program control from switch block.
Case value2;
Statement 1;
Statement 2;
Break;
Statement 1;
Statement 2;
Break;
}
Loop structures:
A loop structure is used to execute a certain set of actions for a predefined number
of times or until a particular condition is satisfied. There are 3 control statements
available in C to implement loop structures. While, Do while and For statements.
The while statement:
The condition is checked for TRUE first. If it is TRUE then all statements inside
curly braces are executed . Then program control comes back to check the
condition has changed or to check if it is still TRUE. The statements inside braces
are executed repeatedly, as long as the condition is TRUE. When the condition
turns FALSE, program control exits from while loop.
do
{
statement 1;
statement 2;
statement 3;
}
while(condition);
Unlike while, do while is an exit controlled loop. Here the set of statements inside
braces are executed first. The condition inside while is checked only after finishing
the first time execution of statements inside braces. If the condition is TRUE, then
statements are executed again. This process continues as long as condition is
TRUE. Program control exits the loop once the condition turns FALSE.
The For statement:
{
Statement 1;
Statement 2;
Statement 3;
}
The while loop is used when the number of repetitions is not predefined.
Types of function:
User-defined function:
You can also create functions as per your need. Such functions created by the user
are known as user-defined functions.
3. A large program can be divided into smaller modules. Hence, a large project can
be divided among many programmers.
i) Pointers
Ans. Pointers can be used to make a function return more than one value
simultaneously.
Pointer Notation:
int i = 30 ;
Applications of Pointers:
Pointers are an important tool in computer science for creating, using, and
destroying all types of data structures. An array of pointers is useful for the same
reason that all arrays are useful: it allows you to numerically index a large set of
variables.
Below is an array of pointers in C that points each pointer in one array to an integer
in another array. The value of each integer is printed by dereferencing the pointers.
In other words, this code prints the value in memory of where the pointers point.
#include <stdio.h>
const int B= 8;
int main ()
int i, *C[B];
C[i] = &B[i];
{
/* print the values of the integers pointed to by the pointer: */
return 0;
char A[20];
int id;
};
Example:
The following program shows the usage of array of structures:
#include <stdio.h>
#include <string.h>
#include<conio.h>
struct student
{
int ID;
char NAME[30];
float percentage;
};
int main()
{
int i;
struct student record[2];
// 1st student's record
record[0].ID=1;
strcpy(record[0].NAME, "Bhanu");
record[0].percentage = 86.5;
// 2nd student's record
record[1].ID=2;
strcpy(record[1].NAME, "Priya");
record[1].percentage = 90.5;
// 3rd student's record
record[2].ID=3;
strcpy(record[2].NAME, "Hari");
record[2].percentage = 81.5;
for(i=0; i<3; i++)
{
printf(" Records of STUDENT : %d \n", i+1);
printf(" Id is: %d \n", record[i].ID);
printf(" Name is: %s \n", record[i].NAME);
printf(" Percentage is: %f\n\n",record[i].percentage);
}
getch();
return 0;
}
Q7] Explain File Descriptor and Storage Allocator in detail.
1. Grants access.
File descriptors were first used in Unix, and are used by modern operating systems
including Linux, macOS, and BSD. In Microsoft Windows, file descriptors are
known as file handles.
Storage Allocator:
Algorithm:
FLOW CHART:
b) To find the area of circle.
ALGORITHM:
Step 1: Start
Step 2: Input radius
Step 3: let pi = 3.14
Step 4: area = pi * radius * radius
Step 6: print area
Step 7: stop
FLOWCHART:
c) To find the circumference of circle.
ALGORITHM:
Step 1: Start
Step 2: input radius
Step 3: let pi = 3.14
Step 5: circumference = 2 * radius * pi
Step 6: print circumference
Step 7: Stop
FLOWCHART:
Q2] Structured code writing with:
#include <stdio.h>
#include<conio.h>
struct numbers
{
int A,B;
};
int main ()
{
struct numbers s1 ,s2;
s1.A=35;
s1.B=40;
s2.B=55;
clrscr();
printf ("\t1: %d, 2: %d\n", s1.A, s1.B);
printf ("\t1: %d", s2.B);
getch();
return 0;
}
OUTPUT:
b) Store Information in structure and display it:
#include <stdio.h>
#include <conio.h>
struct student
{
char FirstName[50];
float Marks;
};
int main()
{
int i;
struct student s[3];
printf("Enter information of students:\n");
for (i = 0; i < 3; i++)
{
OUTPUT:
Call by Reference
Call by Value
CALL BY VALUE:
#include <stdio.h>
#include <conio.h>
C = a;
a = b;
b = C;
printf("\nAfter swap: A= %d\nB = %d", a, b);
return 0;
}
int main()
{
int A, B; // function declaration
printf("Enter values for a and b\n");
scanf("%d%d", &A, &B);
return 0;
}
OUTPUT:
CALL BY REFRENCE:
#include <stdio.h>
int main()
{
int a = 55;
printf("the value of a is %d\n", a);
change(&a);
printf("now the value of a is %d\n", a);
return 0;
}
OUTPUT:
#include <stdio.h>
OUTPUT:
4) Variable Parameter.
#include <stdarg.h>
#include <stdio.h>
int min(int arg_count, ...)
{
int i;
int min, a;
va_list ap;
va_start(ap, arg_count);
min = va_arg(ap, int);
for(i = 2; i <= arg_count; i++)
if((a = va_arg(ap, int)) < min)
min = a;
va_end(ap);
return min;
}
int main()
{
int count = 5;
printf("Minimum value is %d", min(count, 12,
67, 6, 7, 100));
return 0;
}
OUTPUT:
5) Pointer to Functions.
#include <stdio.h>
#include <conio.h>
void fun(int a)
{
printf("\n\tValue of a is %d", a);
}
int main()
{
void (*fun_ptr)(int) = &fun;
(*fun_ptr)(20);
return 0;
}
OUTPUT:
#include <stdio.h>
#include "myhead.h"
int main()
{
add(4, 6);
/*This calls add function written in myhead.h
and therefore no compilation error.*/
multiply(5, 5);
// Same for the multiply function in myhead.h
printf("BYE!See you Soon");
return 0;
}
OUTPUT:
Misc.h
#ifndef MISC_H
#define MISC_H
/*function declaration.*/
void myFunc(void);
#endif
Main.c
#include <stdio.h>
#include "misc.h"
/*function definition*/
void myFunc(void)
{
printf("Body of myFunc function.\n");
}
int main()
{
printf("Hello, World.\n");
myFunc();
fflush(stdout);
return 0;
}
OUTPUT:
8) Multi file program and user defined libraries.
#include <stdio.h>
#include <math.h>
int main()
{
float num, root;
printf("Enter a number: ");
scanf("%f", &num);
OUTPUT:
#include <stdio.h>
#include <string.h>
int main()
{
char str[] = "finding first and last occurrence of a character is amazing";
char alpha[] = "abcdefghi";
return 0;
}
OUTPUT:
MINI PROJECT