SET- NO - 4
ASSIGNMENT - 1
1.) what is an expression ? write the priority and associaty of different arthimetic operators
in c ? evaluate 2+4*5/2-2/4+2%5?
Go down u will find the answer at set -2 assignment -1 👇👇👇👇👇
2). what is ascii value and unicode ? explain how they are used in c language ?
In C programming, a character variable holds ASCII value (an integer number between 0 and 127) rather than that character itself. This integer value is the ASCII code of the character.
For example, the ASCII value of 'A'
is 65.
What this means is that, if you assign 'A'
to a character variable, 65 is stored in the variable rather than 'A'
itself.
example
int main() {
char c;
printf("Enter a character: ");
scanf("%c", &c);
// %d displays the integer value of a character
// %c displays the actual character
printf("ASCII value of %c = %d", c, c);
return 0;
}
3).illustrate input and output stream in c with prinntf and scanf how to detech error during The data input ?
Go down u will find the answer at set -3 assignment -1 👇👇👇👇👇
SET- NO -III
ASSIGNMENT - 1
1). WHAT IS SCOPE OF VARIABLE ? EXPLAIN BLOCK SCOPE , FUNCTION SCOPE, PROGRAM SCOPE AND FILE SCOPE
A variable's scope is the context in which can be used. It defines “how long the variable lives,” or “where the variable exists.”
A variable with limited scope, as in the execution of a function, is called a local variable.
Function Scope: A Function scope begins at the opening of the function and ends with the closing of it. Function scope is applicable to labels only. A label declared is used as a target to go to the statement and both goto and label statement must be in the same function.
A block scope is the area within if, switch conditions or for and while loops. Generally speaking, whenever you see {curly brackets}, it is a block.
File scope is varibale can be accessed with in the file
2).illustrate input and output stream in c with prinntf and scanf how to detech error during The data input ?
printf() and scanf() functions are used for input and output in C language. Both functions are inbuilt library functions, defined in stdio.h (header file).
printf() function
The printf() function is used for output. It prints the given statement to the console.
The syntax of printf() function is given below:
The format string can be %d (integer), %c (character), %s (string), %f (float) etc.
scanf() function
The scanf() function is used for input. It reads the input data from the console.
3. how are expression evaluted in c . explain the role of precedence and associaty in it give an example ?
Go down u will find the answer at set -2 assignment -1 👇👇👇👇👇
SET NO -II
ASSIGNMENT-1
3) WHAT IS CONSTANT ? EXPLAIN DIFFERENTE TYPES OF CONSTANTS AVALIBLE IN C WITH EXAMPLES ?
.
A constant is a value or variable that can't be changed in the program, for example: 10, 20, 'a', 3.4, "c programming" etc.
There are different types of constants in C programming.
List of Constants in C
Constant | Example |
---|---|
Decimal Constant | 10, 20, 450 etc. |
Real or Floating-point Constant | 10.3, 20.2, 450.6 etc. |
Octal Constant | 021, 033, 046 etc. |
Hexadecimal Constant | 0x2a, 0x7b, 0xaa etc. |
Character Constant | 'a', 'b', 'x' etc. |
String Constant | "c", "c program", "c in javatpoint" etc. |
2. HOW ARE EXPRESSION EVALUATED IN C ? EXPLAIN THE ROLE OF PREDENCE AND ASSOICATIVITY IN IT GIVE EXAMPLE ?
Infix Notation: Operators are written between the operands they operate on, e.g. 3 + 4.
Prefix Notation: Operators are written before the operands, e.g + 3 4
Postfix Notation: Operators are written after operands.
Infix Expressions are harder for Computers to evaluate because of the additional work needed to decide precedence. Infix notation is how expressions are written and recognized by humans and, generally, input to programs. Given that they are harder to evaluate, they are generally converted to one of the two remaining forms. A very well known algorithm for converting an infix notation to a postfix notation is Shunting Yard Algorithm by Edgar Dijkstra. This algorithm takes as input an Infix Expression and produces a queue that has this expression converted to postfix notation. The same algorithm can be modified so that it outputs the result of the evaluation of expression instead of a queue. The trick is using two stacks instead of one, one for operands, and one for operators.
1). The difference between Type casting and Type conversion which are given below:
#include <stdio.h>
int main() {
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i) {
for (j = 1; j <= i; ++j) {
printf("%d ", j);
}
printf("\n");
}
return 0;
}
#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
// true if num is perfectly divisible by 2
if(num % 2 == 0)
printf("%d is even.", num);
else
printf("%d is odd.", num);
return 0;
}
#include<stdio.h>
int main(){
char ch;
printf("enter a character:");
scanf("%c",&ch);
if(ch >= 65 && ch <= 90)
printf("Upper Case Letter");
else if(ch >= 97 && ch <= 122)
printf("Lower Case letter");
else if(ch >= 48 && ch <= 57)
printf("Number");
else
printf("Symbol");
return 0;
}
nested-if in C/C++
A nested if in C is an if statement that is the target of another if statement. Nested if statements mean an if statement inside another if statement. Yes, both C and C++ allow us to nested if statements within if statements, i.e, we can place an if statement inside another if statement.
Syntax:
if (condition1)
{
// Executes when condition1 is true
if (condition2)
{
// Executes when condition2 is true
}
}
Flowchart
Example:
- C
i is smaller than 15
i is smaller than 12 too
Output:
enter the number=151
palindrome number
enter the number=5621
not palindrome number
include <stdio.h>
int main() {
int n, i;
float num[100], sum = 0.0, avg;
printf("Enter the numbers of elements: ");
scanf("%d", &n);
while (n > 100 || n < 1) {
printf("Error! number should in range of (1 to 100).\n");
printf("Enter the number again: ");
scanf("%d", &n);
}
for (i = 0; i < n; ++i) {
printf("%d. Enter number: ", i + 1);
scanf("%f", &num[i]);
sum += num[i];
}
avg = sum / n;
printf("Average = %.2f", avg);
return 0;
}
include <ctype.h>
#include <stdio.h>
int main() {
char c;
int lowercase_vowel, uppercase_vowel;
printf("Enter an alphabet: ");
scanf("%c", &c);
// evaluates to 1 if variable c is a lowercase vowel
lowercase_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
// evaluates to 1 if variable c is a uppercase vowel
uppercase_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
// Show error message if c is not an alphabet
if (!isalpha(c))
printf("Error! Non-alphabetic character.");
else if (lowercase_vowel || uppercase_vowel)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
return 0;
}