Professional Documents
Culture Documents
Lovely Professional University: Mittal School of Business
Lovely Professional University: Mittal School of Business
CONTINUOUS ASSESSMENT-1
Ans:
This has an analytic solution so you have a constant time algorithm: S(n) = (n(n+1))/2 =>
or
or more generally
1. #include<stdio.h>
2. #include<conio.h>
3. void main() {
4. int year;
5. printf("Enter a year: ");
6. scanf("%d", &year);
7. if(((year%4==0) && ((year%400==0) || (year%100!==0))
8. {
9. printf("%d is a leap year", &year);
10. } else {
11. printf("%d is not a leap year", &year);
12. }
13. getch();
14. }
Output
Test 1:
Enter a year: 2004
Test 2:
Ans:
In the world of programming languages, keywords and identifiers are important
terminologies. Some programming languages contain keywords and identifiers that
are recognized by its compiler. In general, keywords are the predefined and
specific reserved words, which hold special meaning. On the other hand, an
identifier is a different term or name given to a variable, label of class in the program
or function. Let’s find out the difference between keywords and identifiers.
What is a Keyword?
Keywords are the predefined and specific reserved words, which hold special meaning.
Keywords help in defining any statement in the program. When it comes to C language it
consists of 32 keywords. Some of the examples of keywords are: double, int, auto, char,
break, and more.
What is an Identifier?
2 A keyword begins with lowercase. In the identifier, the first character may begin
with uppercase, lowercase or underscores.
4 It can only have alphabetical characters. It can have numbers, alphabetical characters,
and underscores.
6 It helps in defining a particular property It helps in locating the name of the entity.
that subsists in a computer language.
7 double, int, auto, char, break, and more Test, count1, highspeed, etc are examples of
are examples of keywords. identifiers.
18. What is an operator? Explain the arithmetic, relational, logical, and assignment operators in
C language?
Ans:
An operator is a symbol that tells the compiler to perform specific mathematical or logical
functions. C language is rich in built-in operators and provides the following types of
operators −
Arithmetic Operators
Relational Operators
Logical Operators
Assignment Operators
• Arithmetic Operators
The following table shows all the arithmetic operators supported by the C language.
Assume variable A holds 10 and variable B holds 20 then −
• Relational Operators
The following table shows all the relational operators supported by C. Assume
variable A holds 10 and variable B holds 20 then –
Operator Description Example
== Checks if the values of two operands are equal or not. If yes, (A == B) is not
true.
then the condition becomes true.
!= Checks if the values of two operands are equal or not. If the (A != B) is true.
> Checks if the value of left operand is greater than the value of (A > B) is not
true.
right operand. If yes, then the condition becomes true.
< Checks if the value of left operand is less than the value of (A < B) is true.
>= Checks if the value of left operand is greater than or equal to (A >= B) is not
true.
the value of right operand. If yes, then the condition becomes
true.
<= Checks if the value of left operand is less than or equal to the (A <= B) is true.
Following table shows all the logical operators supported by C language. Assume
variable A holds 1 and variable B holds 0, then –
&& Called Logical AND operator. If both the operands are non-zero, then the (A && B)
is false.
condition becomes true.
! Called Logical NOT Operator. It is used to reverse the logical state of its !(A &&
B) is
operand. If a condition is true, then Logical NOT operator will make it true.
false.
• Assignment Operators
The following table lists the assignment operators supported by the C language −
+= Add AND assignment operator. It adds the right operand to the left C += A is
operand and assign the result to the left operand. equivalent
to C = C +
A
/= Divide AND assignment operator. It divides the left operand with the C /= A is
right operand and assigns the result to the left operand. equivalent
to C = C /
A
Ans:
#include <stdio.h>
#include <stdlib.h>
int main(void){
printf("%d",test(120, -1));
printf("\n%d",test(-1, 120));
printf("\n%d",test(2, 120));
}
int test(int temp1, int temp2)
{
return temp1 < 0 && temp2 > 100 || temp2 < 0 && temp1 >
100;
}
Sample Output:
1
1
0
Flowchart: