0% found this document useful (0 votes)
15 views6 pages

Assignment 2 Anshuman

The document contains a series of C programming questions and tasks, including code analysis, output prediction, and programming assignments. It covers various concepts such as arithmetic operations, conditional expressions, loops, and function-based programs. Additionally, it provides specific outputs for the analyzed code snippets and outlines tasks for writing programs related to prime numbers, palindromes, and Pascal's Triangle.

Uploaded by

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

Assignment 2 Anshuman

The document contains a series of C programming questions and tasks, including code analysis, output prediction, and programming assignments. It covers various concepts such as arithmetic operations, conditional expressions, loops, and function-based programs. Additionally, it provides specific outputs for the analyzed code snippets and outlines tasks for writing programs related to prime numbers, palindromes, and Pascal's Triangle.

Uploaded by

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

ASSIGNMENT-02

Code Analysis Questions:


Q1. Analyze the following C program and predict the output:
int main() {
OUTPUT:-
int x, y, z;
x = -3 + 4 * 5 - 6;
x=11 y=0 z=0

y = -3 * 4 % -6 / 5;
z = y == x;

printf("x=%d y=%d z=%d\n", x, y, z); }

Q2. Analyze the following C program:


int main() {
int x , y , z;
OUTPUT:-
x = 5 + 2 * 3;
x=11 y=4 z=5
y = 5 / 2 * 2;
z = 2 * 5 / 2;

printf(" x= %d y = %d z = %d", x, y, z); }

Q3. Analyze and predict the output:


int main( ) {
float a = 5; OUTPUT:-

int b = 8, c = 4, res = 0; res = 10


res = a * b % c;

printf(" res = %d ", res); }

Q4.Evaluate the expression and determine the output:


int main() {

int a = 10, b = 5, c = 3; OUTPUT:- 0


int res = a > b > c;
printf("%d\n", res); }
Q5. Analyze the following conditional expression:
int main() {
int x = -5; OUTPUT:-
if (x < sizeof(int)) printf(" x is lesser than size of int");
x is lesser than size of int
else printf(" x is greater than size of int");
return 0;

Q6. Study and predict the output:


int main() {
int x, y, z;
x = 2;
y = 1;
z = 0;
OUTPUT:-
z += -x++ + ++y; x=3 y=2 z=0
printf("x=%d\t y=%d\t z=%d\n", x, y, z);
x=4 y=2 z=1
z = ++x || ++y && ++z;
printf("x=%d\t y=%d\t z=%d\n", x, y, z); x=2 y=3 z=4
x = 2;
y = 2;
z = 2;
z += x < y ? x++ : y++;
printf("x=%d\t y=%d\t z=%d\n", x, y, z); }

Q7. Predict the output for the following code:


int main() {

int a = 1, b = 1, c = 1, res;

res = a == b > c; OUTPUT:-


printf(" res = %d ", res); res = 0 res = 1
a = 1, b = 5, c = 2;

res = a == b > c;

printf(" res = %d ", res); }


Q8. Evaluate the logical expression:
int main( ) {

int a = 5, b = 10, c = 0; OUTPUT:-

a > b && (c = a); a = 5 b = 10 c = 0


printf("a = %d b = %d c = %d ", a, b, c); }

Programming Tasks:
Q1. Write a C program to print the range of prime numbers in a given interval.

Q2. Write a program in C to check whether a given number is a palindrome.


Q3. Write a C program to find the frequency of each digit in a given integer.

*
Q4. Write a program in C to print a pyramid of stars: * * *
*****

Output Analysis Questions:


Q1. Evaluate the following program:
int main(void) {

int k = 5; OUTPUT:- 7
if (++k < 5 && k++ / 5 || ++k < 8);

printf("%d\n”, k);

Q2. Predict the value of j:


int main() {
int i = 23, j = 0;
if (i >= 25) if (i % 2 == 0) j = 111; OUTPUT:- 0
else j = 222;
printf(" %d ", j); return 0; }
Q3. Analyze the loop structure:
int main() {
int a, b; OUTPUT:-
for (a = 0; a < 10; a++); 10 10
for (b = 25; b > 9; b -= 3);
printf("%d %d", a, b);
return(0); } OUTPUT:-
Q4. Debug and correct the following program: I = 0, J = 0 I = 6, J = 6
I = 1, J = 1 I = 7, J = 7
int main() {
I = 2, J = 2
int i, j; I = 8, J = 8
I = 3, J = 3
for (i = j = 0; i < 5 || j < 10; i++, j++) { I = 9, J = 9
I = 4, J = 4
printf("I = %d ,J = %d", i, j); } } I = 5, J = 5 I = 10, J = 10

Function-Based Programs
Q1. Write a program in C to check if a number is binary using functions.

Q2. Write a C program to check whether a number is prime, Armstrong, or a


perfect number using functions.
Q3. Write a C program to print Pascal’s Triangle up to n rows using functions.

You might also like