You are on page 1of 10

Department of Accounting & Information Systems

Course Title: Fundamentals of Programming and Database Management

Course Code: 2202

Assignment topic- Answer of the questions

Submitted to:
Nusrat Zerin Zenia
Lecturer
Institute of Information Technology
Jahangirnagar University

Submitted by:
Tania Sultana
Roll Number- 1575
Reg. Number- 47570
Batch-8th

Date of Submission: 19 October 2020

1
Table of Contents
Answer of question number 1....................................................................................................3

Arithmetic expression............................................................................................................3

Conditional operator...............................................................................................................3

Loop in C................................................................................................................................3

Answer of question number 2....................................................................................................5

Syntax error............................................................................................................................5

Errors of the program.............................................................................................................5

Answer of question number 3....................................................................................................7

The codes output:...................................................................................................................7

Answer of question number 4....................................................................................................8

Function arguments................................................................................................................8

The program...........................................................................................................................8

Answer of question number 5..................................................................................................10

The program:........................................................................................................................10

2
Answer of question number 1
Arithmetic expression
An arithmetic expression is an expression in code which consists of a numeric value. In
arithmetic expression, there are two kinds of numeric values, integers (whole numbers), and
real or floating-point numbers (numbers containing a decimal point).

Conditional operator
Conditional operators used to evaluate a condition that’s applied to one or two Boolean
expressions. The result of the evaluation is either true or false.

There are three kinds of conditional operators:

&& the logical AND operator.

|| the logical OR operator.

?: the ternary operator.

Loop in C
In programming, a loop is used to repeat a block of code until the specified condition is met.

C programming has three kinds of loops:

For loop

The syntax of the ‘for’ loop is:

For (initializationStatement; testExpression; updateStatement)

// statements inside the body of loop

While loop

The syntax of the while loop is:

While (testExpression)

3
// statements inside the body of the loop

do... while loop

The syntax of a do…while loop in C programming language is –

Do {

Statement(s);

} while( condition );

4
Answer of question number 2
Syntax error
There are various kinds of errors that can occur in a program, which can be categorized into
syntax errors, runtime errors, and logical errors.

Mistakes in using the language is called Syntax errors. Examples of syntax errors are missing
a comma or a quotation mark, or misspelling a word.

For example, the following character vector is missing the end quote:

>>mystr = 'how are you;

mystr = 'how are you;

 ↑

Error: Character vector is not terminated properly.

If this type of error is typed in a script or function using the Editor, the Editor will flag it.

Errors of the program


Compilation failed due to following errors:

Error 1: Implicit declaration of function ‘print’

Error 2: ‘Enter’ undeclared (first use in this function)

Error 3: Each undeclared identifier is reported only once for each function it appears in

Expected ‘)’ before ‘the’

Error 4: Stary ‘\’ in program

In the line Print(Enter the number to test\n);

‘is_prime’ undeclared (first use in this function)

In the line Is_prime=1;

5
Expected expression before ‘if’

In the line If ((n&i=0))

Expected expression before ‘}’ token

In the line }

6
Answer of question number 3
The codes output:
Enter the number of rows: 1

Enter the number of rows: 2

12

Enter the number of rows: 3

12

123

Similarly, with each increasing value, another row will be added with and output will be
1234, 12345, 123456 & so on like following,

(n+1)(n+2)

(n+1)(n+2)(n+3)

(n+1)(n+2)(n+3)(n+4)

………………………………………….

7
Answer of question number 4
Function arguments
The function-arguments property means array-like object corresponding to the arguments
passed to a function. Use the simple variable arguments instead. This property is restricted to
non-strict functions.

#include<stdio.h>

Int sum int a, int b)

{{

Int sum; sum = a + b; return sum;

Int main() {

Int a, b;

Int sum(int, int);

Printf(“Enter the values of a and b:”); scanf(“%d%d”, &a,&b);

Printf(“\nThe sum of two numbers is done by function with argument and with return

Value – sum : “); printf(“%d”, sum(a, b));

Return 0;

The program
#include<stdio.h>

Void sqr_it(intnum)

Printf(“%d”,num*num);

Int main()

8
{

Intnum=5;

Sqr_it(num);

Return 0;

9
Answer of question number 5
The program:
#include<stdio.h>

int main() {

intn,i;

int sum=0;

printf("Enter the n i.e. max values of series: ");

scanf("%d",&n);

sum = (n * (n + 1)) / 2;

printf("Sum of the series: ");

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

if (i!=n)

printf("%d + ",i); else

printf("%d = %d ",i,sum);

return 0;

10

You might also like