[go: up one dir, main page]

0% found this document useful (0 votes)
36 views11 pages

صالح محمد أحمد2

The document contains a student assignment submission for a programming in C language course. It includes 30 questions related to C programming concepts like data types, variables, operators, functions, and I/O. The student provides answers to each question in the assignment.

Uploaded by

Saleh Kettan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views11 pages

صالح محمد أحمد2

The document contains a student assignment submission for a programming in C language course. It includes 30 questions related to C programming concepts like data types, variables, operators, functions, and I/O. The student provides answers to each question in the assignment.

Uploaded by

Saleh Kettan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Suez Canal University

Egyptian Chinese College


for Applied Technology

Mechatronics Department

Name \ Saleh Mohammed Ahmed


ID \73797
Department \ Mechatronics Technology (2nd grade)
Course \ Programming in C language
Assignment \ 2 ch(2&3)
professor \Zakaria Hassan
1- what is identfier
An identifier is a name given to a variable, function, or any other user-
defined entity. It is used to uniquely identify and refer to that entity within
the program. An identifier can consist of letters (both uppercase and
lowercase), digits, and underscores

2- the valid C identifier is Ralph23 , mission_control & off

3- int i, j;
4- The "float" type is a single-precision floating-point type, while the
"double" type is a double-precision floating-point type. The main difference
is in the precision and range of values they can represent. A "float"
typically has 32 bits and can represent numbers with about 6-7 decimal
digits of precision. A "double" typically has 64 bits and can represent
numbers with about 15-16 decimal digits of precision.

5- The "int" type represents signed integers, which can be positive,


negative, or zero. The "unsigned int" type represents unsigned integers,
which can only be zero or positive. The main difference is that "int" can
represent both positive and negative numbers, while "unsigned int" can
only represent non-negative numbers.

6- int I = 67;

7- By default, a C function returns an "int" type.

8- // Function declaration
long float calculateValue();

// Function definition
long float calculateValue() {
// Function body
// ...
return result;
}

9- double number = 23.1256;


int integerPart = (int)number;
printf("Integer part: %d\n", integerPart);

10- No, it is not possible to have an automatic global variable. Global


variables are by default static storage duration, meaning they exist for the
entire duration of the program execution. Automatic variables, on the other
hand, have automatic storage duration and are local to a specific block or
function.

11- #include <stdio.h>


int main() {
int result = 87 - 15;
printf("Result: %d\n", result);
return 0;
}

12- #include <stdio.h>


int main() {
int sum; // Removed uppercase errors

/* COMPUTE RESULT */
sum = 25 + 37 - 19;

/* DISPLAY RESULTS */
printf("The answer is %i\n", sum);
return 0;
}
13
- Output of the program:
The result is 95

14
- #include <stdio.h>
int main() {
printf("Size of int: %zu bytes\n", sizeof(int));
printf("Size of short int: %zu bytes\n", sizeof(short int));
printf("Size of long int: %zu bytes\n", sizeof(long int));
printf("Size of unsigned short int: %zu bytes\n", sizeof(unsigned short
int));
printf("Size of signed short int: %zu bytes\n", sizeof(signed short int));
printf("Size of unsigned long int: %zu bytes\n", sizeof(unsigned long int));
printf("Size of signed long int: %zu bytes\n", sizeof(signed long int));
printf("Size of float: %zu bytes\n", sizeof(float));
printf("Size of double: %zu bytes\n", sizeof(double));
printf("Size of char: %zu byte\n", sizeof(char));
return 0;
}
15-
#include <stdio.h>
int main() {
printf("Storage size for int: %zu bytes\n", sizeof(int));
printf("Storage size for long int: %zu bytes\n", sizeof(long int));
printf("Storage size for short int: %zu bytes\n", sizeof(short int));
printf("Storage size for char: %zu byte\n", sizeof(char));
return 0;
}
16-
#include <stdio.h>
#include <math.h>
extern int x, y, string;
extern float z;
extern double w, j;
extern const double PI;
extern char character;
int main() {
int x = 5;
int y = x;
float z = 555.67;
double w = 9.79e12;
double j = 9.79e+12;
const double PI = 3.1416;
char character = 'Z';
char string[] = "Dr.Zakaria";

17-
#include <stdio.h>
int main() {
char c;
c = 'A';
printf("ASCII value of %c: %d\n", c, c);
c = 'B';
printf("ASCII value of %c: %d\n", c, c);
c = 'C';
printf("ASCII value of %c: %d\n", c, c);
c = 'D';
printf("ASCII value of %c: %d\n", c, c);
return 0;
}

18-
#include <stdio.h>
int main() {
int num;
num = 101;
printf("ASCII character of %d: %c\n", num, num);
num = 102;
printf("ASCII character of %d: %c\n", num, num);
num = 103;
printf("ASCII character of %d: %c\n", num, num);
num = 104;
printf("ASCII character of %d: %c\n", num, num);
return 0;
}
19 -d = d

20-
#include <stdio.h>
#includ <math.h>
int main() {
int X = 10;
int Y = 20;

printf("X + Y = %d\n", X + Y);


printf("X - Y = %d\n", X - Y);
printf("Y - X = %d\n", Y - X);
printf("X * Y = %d\n", X * Y);
printf("X / Y = %d\n", X / Y);
printf("Y / X = %d\n", Y / X);
printf("X %% Y = %d\n", X % Y);
printf("Y %% X = %d\n", Y % X);

return 0;
}

21 –
#include <stdio.h>
#include <math.h>
int main() {
float X = 4.8;
float Y = 2.5;

printf("X + Y = %.2f\n", X + Y);


printf("X - Y = %.2f\n", X - Y);
printf("Y - X = %.2f\n", Y - X);
printf("X * Y = %.2f\n", X * Y);
printf("X / Y = %.2f\n", X / Y);
printf("Y / X = %.2f\n", Y / X);

return 0;
}
22-
#include <stdio.h>
int main() {
double F = 27;
double C = (F - 32) / 1.8;

printf("%.2f degrees Fahrenheit is equal to %.2f degrees Celsius.\n", F,


C);

return 0;
}

23-
#include <stdio.h>
int main() {
double x = 2.55;
double result = 3 * pow(x, 3) - 5 * pow(x, 2) + 6;

printf("The result of the polynomial for x = %.2f is %.2f\n", x, result);

return 0;
}

24-
#include <stdio.h>
int main() {
double result = (3.31 * pow(10, -8) * 2.01 * pow(10, -7)) / (7.16 * pow(10, -
6) + 2.01 * pow(10, -8));

printf("The result of the expression is %.2e\n", result);

return 0;
}

25- by define preprocessor

#include <stdio.h>

#define LENGTH 10
#define WIDTH 9

int main() {
int area = LENGTH * WIDTH;
printf("Area using #define: %d\n", area);

return 0;
}
By const keyword

#include <stdio.h>
int main() {
const int length = 10;
const int width = 9;

int area = length * width;


printf("Area using const: %d\n", area);

return 0;
}

26-
#include <stdio.h>
int main() {
int x = 4;
int y = 5;

printf("x > y: %d\n", x > y);


printf("x < y: %d\n", x < y);
printf("x >= y: %d\n", x >= y);
printf("x <= y: %d\n", x <= y);
printf("x == y: %d\n", x == y);
printf("x != y: %d\n", x != y);
return 0;
}

27-
#include <stdio.h>
int main() {
int x = 4;
int y = 5;

printf("x && y: %d\n", x && y);


printf("x || y: %d\n", x || y);
printf("!x: %d\n", !x);
printf("!(x && y): %d\n", !(x && y));
printf("!(x || y): %d\n", !(x || y));

return 0;
}
28-
#include <stdio.h>
int main() {
int x = 5;
int y = 6;

printf("x & y: %d\n", x & y);


printf("x | y: %d\n", x | y);
printf("x ^ y: %d\n", x ^ y);
printf("~x: %d\n", ~x);
printf("x << 1: %d\n", x << 1);
printf("y >> 1: %d\n", y >> 1);

return 0;
}

29 #include <stdio.h>
int main() {
int x = 0;
int y = 5;

printf("x & y: %d\n", x & y);


printf("x | y: %d\n", x | y);
printf("x ^ y: %d\n", x ^ y);
printf("~x: %d\n", ~x);
printf("!x: %d\n", !x);
printf("!(x && y): %d\n", !(x && y));
printf("!(x || y): %d\n", !(x || y));

return 0;
}

30 #include <stdio.h>
int main() {
int x = 5;

x += 1;
printf("x += 1: %d\n", x);

x -= 2;
printf("x -= 2: %d\n", x);

x *= 3;
printf("x *= 3: %d\n", x);

x /= 4;
printf("x /= 4: %d\n", x);

x %= 5;
printf("x %%= 5: %d\n", x);

x &= 6;
printf("x &= 6: %d\n", x);

x |= 7;
printf("x |= 7: %d\n", x);

x ^= 8;
printf("x ^= 8: %d\n", x);
x <<= 2;
printf("x <<= 2: %
31-
#include <stdio.h>
int main() {
int x = 30;
int result = (x == 30) ? 100 : 200;
printf("Result: %d\n", result);

return 0;
}
The output of this program would be Result: 100

32-
#include <stdio.h>
#define LENGTH 20
#define WIDTH 10
#define NEWLINE '\n'
int main(void) {
int area = LENGTH * WIDTH;

printf("The value of area = L*W = %d", area);


printf("%c", NEWLINE);
return 0;
}
The output of this program would be The value of area = L*W = 200

33-
#include <stdio.h>
int main() {
int x = 2, y = 4;
y = x * y + pow(x, y) + sqrt(x * y);
printf("New value of y = %d\n\n", y);
return 0;
}
The output of this program would depend on the initial values of x and y.

You might also like