C Programming Module 1 Solutions
C Programming Module 1 Solutions
C Programming Module 1 Solutions
Ujjwal Acharya
The operating system provides services such as a user interface, file and database
access, and interfaces to communication systems such as Internet protocols. The
primary purpose of this software is to keep the system operating in an efficient manner
while allowing the users access to the system.
The Algorithm is a finite sequence of instructions, each of which has a clear meaning and
can be performed with a finite amount of effort in a finite length of time. No matter what
the input values may be, an algorithm terminates after executing a finite number of
instructions. We represent an algorithm using a pseudo-language that is a combination
of the constructs of a programming language together with informal English statements.
The ordered set of instructions required to solve a problem is known as an algorithm.
🅰 COMPILER 🅱 Interpreter
A Compiler is used to compile an entire program An interpreter is used to translate each line of the
and an executable program is generated through program code immediately as it is entered
the object program
The executable program is generated in RAM and
The executable program is stored in a disk for the interpreter is required for each run of the
future use or to run it in another computer program
The compiled programs run faster The Interpreted programs run slower
Most of the Languages use compiler A very few languages use interpreters
void main()
{
1 < 2 ? return 1 : return 2;
}
#include <stdio.h>
void main()
{
(1 < 2)? return 1 : return 2;
}
//The Ternary operator accepts conditions and not statements. Since the return is a statement and not a condition, the above p
rogram will return an error
#include <stdio.h>
void main()
{
printf("value is = %d",(10++));
}
//This code is returning Compilation Error
void main()
{
const char var='A';
++var;
printf("%c",var);
}
#include <stdio.h>
void main()
{
const char var='A';
++var;
printf("%c",var);
}
//var here is a constant so the compiler will not iterate the characters
#include <stdio.h>
void main()
{
int x=(20 || 40 ) && (10);
printf("x= %d",x);
}
//Output: x= 1
#include <stdio.h>
int main()
{
int i;
i = 1, 2, 3;
printf("%d", i);
return 0;
}
//Output: 1
#include <stdio.h>
void main()
{
int a=3,b=2;
a=a==b==0;
printf("%d,%d",a,b);
}
//Output: 1,2
#include <stdio.h>
int main()
{
float a;
(int)a= 10;
printf("value of a=%d",a);
return 0;
}
//Error as Line 5 is not valid
#include <stdio.h>
int main()
{
int x = 2;
(x & 1)? printf("true") : printf("false");
return 0;
}
//Output: false
2. Differentiate among high level, low level and middle level language.
High-Level Language:
→ They are easy to learn and programs may be written in these languages with much
less effort.
→ However, the computer cannot understand them and they need to be translated into
machine language with the help of other programs known as Compilers or Translators.
Like C, Java, Python, etc.
Low-Level Language:
→ The language whose design is governed by the circuitry and the structure of the
machine is known as the Low Level / Machine language.
→ This language is difficult to learn and use. It is specific to a given computer and is
different for different computers i.e. these languages are machine-dependent.
→ These languages have been designed to give better machine efficiency, i.e. faster
program execution. Such languages are also known as Low-Level Languages.
4. Define flowchart and explain different symbols used for constructing flowchart.
1. Type Casting:
In typing casting, a data type is converted into another data type by the programmer
using the casting operator during the program design. In typing casting, the destination
data type may be smaller than the source data type when converting the data type to
another data type, that’s why it is also called narrowing conversion.
2. Type conversion :
In type conversion, a data type is automatically converted into another data type by a
compiler at the compiler time. In type conversion, the destination data type cannot be
smaller than the source data type, that’s why it is also called widening conversion. One
more important thing is that it can only be applied to compatible data types.
#include <stdio.h>
void main() {
int k = 8;
int m = 7;
k < m ? k++ : m = k;
printf("%d", k);
}
The code here will throw back an error, as in Line 5, the assignment operator is not
declared properly for the relation m=k. If the correction is made as "m==k", then the
correct output will be 8.
#include <stdio.h>
void main()
{
int a=10,b=2,x=0;
x=a+b*a+10/2*a;
printf("value is =%d",x);
}
//Ouput: value is =80
#include <stdio.h>
void main()
{
char a = 'A';
char b = 'B';
int c = a + b % 3 - 3 * 2;
printf("%d\n", c);
}
//Output: 59
#include <stdio.h>
int main()
{
int a=0;
a = 10 + 5 * 2 * 8 / 2 + 4;
printf("%d", a);
return 0;
}
//Output: 54
#include <stdio.h>
int main()
{
int x;
x=6*2/ (2+1 * 2/3 + 6) + 8 * (8/4);
printf("%d", x);
}
//Output: 17
#include <stdio.h>
int main()
int x = 2, y = 0;
printf("%d\n", z);
return 0;
Output: 0
#include <stdio.h>
void main()
int a, b = 10;
a = -b--;
Output: a = -10, b = 9
#include <stdio.h>
void main()
int a, b = 10;
a = b---;
return 0;
}
a = b---;
return 0;
#include <stdio.h>
int main()
int a = 2;
int b = 0;
printf("%d\n", y);
return 0;
Output: 2
#include <stdio.h>
void main()
printf(“%d”, y);
Output: 1
#include <stdio.h>
void main( )
printf(“%d”, -11%5);
Output: -1
#include <stdio.h>
void main()
printf(“z=%d”, z);
Output: z=0
#include <stdio.h>
void main()
int c= a<b?a++:b++;
#include <stdio.h>
void main()
}
Output: a=8, b=8, c=8
void main ( )
double x=28;
int y;
y= x%5;
y= x % 5;