C PROGRAMMING(VSEC102)
Assignment No.-1
Q.1 Explain token in C.
Tokens are the smallest individual units of a program that have a meaning to the compiler.
They are the building blocks of C code.
Programs are written using these tokens and syntax of language.
There are totally six tokens.
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Special Symbols
6. Operator
1. Keywords
Keywords are reserved words that have a special meaning in C.
They cannot be used as identifiers (like variable names or function names) because they are part of the
language syntax.
Example: int, float, if, else, while, return, etc
2. Identifiers
Identifiers are names used to identify variables, functions, arrays, and other user-defined items in the program.
3. Constants
Constants are fixed values that do not change during the execution of a program. They can be of various
types:
Integer Constants: 10, -5, 0
Floating-point Constants: 3.14, -0.001
Character Constants: 'a', '1', '\n'
String Constants: "Hello", "123"
4. String Literals
A sequence of characters enclosed in double quotes, like "Hello World", are string literals.
5. Punctuation Symbols / Special Symbols
Punctuation symbols or special characters are used in the syntax of the language to separate statements, group
statements, and to control program flow.
Common punctuation symbols include:
Semicolon (;) — used to end statements.
Comma (,) — used to separate multiple items.
Parentheses (()) — used for grouping and function calls.
Curly braces ({}) — used to define a block of code.
Square brackets ([]) — used for array subscripts.
6 Operators
Operators are symbols that perform operations on one or more operands.
Types of operator:
Arithmetic Operators: +, -, *, /, %
Relational Operators: ==, !=, <, >, <=, >=
Logical Operators: &&, ||, !
Assignment Operators: =, +=, -=, *=, /=
Increment/Decrement Operators: ++, --
Q.2 Explain in detail data types in C.
Data type is the instruction to the compiler telling about what type of value will be stored in a memory location
and also to specify the amount of memory required for location.
The value of a variable can be changed any time.
C has the following 4 types of data types
basic built-in data types: int, float, double, char
Enumeration data type: enum
Derived data type: pointer, array, structure, union
Void data type: void
Size
Basic data type Data type with type qualifier Range
(byte)
char or signed char 1 -128 to 127
char
Unsigned char 1 0 to 255
int int or signed int 2 -32768 to 32767
unsigned int 2 0 to 65535
short int or signed short int 1 -128 to 127
unsigned short int 1 0 to 255
long int or signed long int 4 -2147483648 to 2147483647
unsigned long int 4 0 to 4294967295
float float 4 -3.4E-38 to 3.4E+38
double double 8 1.7E-308 to 1.7E+308
Long double 10 3.4E-4932 to 1.1E+4932
Q.3 Draw a flowchart to find the largest of three numbers
Q.4 Write a program in C to find largest of three numbers
#include <stdio.h>
int main()
{
int a, b, c;
printf("Enter three numbers:");
scanf("%d %d %d", &a, &b, &c);
if (a >= b && a >= c)
printf("Largest number is:%d", a);
else if (b >= a && b >= c)
printf("Largest number is:%d", b);
else
printf("Largest number is:%d", c);
return 0;
}
Output
Enter three numbers:3
4
5
Largest number is:5
Q.5 Write a program tp calculate simple interest SI using formula
SI= (p * r* t) / 100
Where,
p= Principle amount
r= Rate of interest .
t=numbers of years
Accept values of p , n and r from user.
#include<stdio.h>
int main()
{
float p,r,t,SI;
printf("Enter principal amount:");
scanf("%f",&p);
printf("Enter rate of interest: ");
scanf("%f",&r);
printf("Enter number of years:");
scanf("%f",&t);
SI=(p*r*t)/100;
printf("Simple Interest= %.3f",SI);
return 0;
}
Output
Enter principal amount:50000
Enter rate of interest: 9.6
Enter number of years:1.5
Simple Interest= 7200.000