Problem Solving Through Programming In C Week 12

Session: JAN-APR 2023

Course Name: Problem Solving Through Programming In C

Course Link: Click Here

These are Problem Solving Through Programming In C Assignment 12 Answers


Q1. Which of the following are themselves a collection of different data types?
a) String
b) Array
c) Character
d) Structure

Answer: d) Structure


Q2. Can we declare function inside structure of C Programming?
a) Yes
b) No
c) Compiler dependant
d) Its possible, but causes runtime errors.

Answer: b) No


These are Problem Solving Through Programming In C Assignment 12 Answers


Q3. What is the output of the following C program? #include struct p { }; int x; char y : int main() { } struct p p1[] = {1,21,69,42,64}; struct p ptrl=pl; int x = (sizeof(p1)/4); if ((x == sizeof(int) + 2sizeof(char))) printf(“True”); else printf(“False”); return 0;}
a. True
b. False
c. No output
d. Compilation error

Answer: a. True


Q4. Which of the following statements is true about the equality of two structure variables?
a) Two structure variables are equal if all their members are equal
b) Two structure variables are equal if they have the same address
c) Two structure variables cannot be compared for equality
d) None of the above

Answer: a) Two structure variables are equal if all their members are equal


These are Problem Solving Through Programming In C Assignment 12 Answers


Q5. What will be output? #include int main() { } struct insti { int x = 2; char ins[] = “IIT”; }; struct insti s1; printf(“%d”,s1.ins); printf(“%d”, s1.x); return 0;}
a) IIT
b) 2
c) IIT 2
d) Compilation error

Answer: d) Compilation error


Q6. What is the size of the following structure in bytes? struct example { char c; int i; double d; };
a) 7
b) 12
c) 16
d) 20

Answer: c) 16


These are Problem Solving Through Programming In C Assignment 12 Answers


Q7. What will be output?
a) 5 10 10
b) 10 5 15
c) 10 5 10
d) 10 15 5

Answer: c) 10 5 10


Q8. What is the output of the following C code? Assume that the address of x is 2000 (in decimal) and an integer requires four bytes of memory
a) 2036 2036 2036
b) 2012 4 2204
c) 2036 10 10
d) 2012 4 6

Answer: a) 2036 2036 2036


These are Problem Solving Through Programming In C Assignment 12 Answers


Q9. What is the output of the following code?
a) Hello, world!
b) Hello!
c) world
d) world!

Answer: d) world!


Q10. Which of the following is a disadvantage of the Trapezoidal Rule?
a) It is computationally expensive
b) It is only accurate for certain types of functions
c) It can produce inaccurate results for functions with rapidly changing curvature
d) It requires a large number of subintervals to achieve high accuracy

Answer: c) It can produce inaccurate results for functions with rapidly changing curvature


These are Problem Solving Through Programming In C Assignment 12 Answers


Problem Solving Through Programming In C Programming Assignment

Question 1

Write a program in C to find the factorial of a given number using pointers.

Solution:

void findFact(int n, long int *f)
		{
        int i;

       *f =1;
       for(i=1;i<=n;i++)
       *f=*f*i;
       }

Question 2

Write a C program to print the Record of the Student Merit wise. Here a structure variable is defined which contains student rollno, name and score.

Solution:

struct student temp;
int j;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1;j++)
{
if(s[j].score<s[j+1].score)
{
temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
}
}

These are Problem Solving Through Programming In C Assignment 12 Answers


Question 3

Write a C program to store n elements using Dynamic Memory Allocation – calloc() and find the Largest element.

Solution:

element = (float*) calloc(n, sizeof(float));

    if(element == NULL)
    {
        printf("Error!!! memory not allocated.");
        exit(0);
    }

    // Stores the number entered by the user.
    int i;
    for(i = 0; i < n; ++i)
    {
        scanf("%f", element + i);
    }

 // find the largest
    for(i = 1; i < n; ++i)
    {
       if(*element < *(element + i))
         *element = *(element + i);
    }


    printf("Largest element = %.2f\n", *element);

    return 0;
}

These are Problem Solving Through Programming In C Assignment 12 Answers


Question 4

Write a C program to add two distance given as input in feet and inches.

Solution:

sum.feet=d1.feet+d2.feet;
    sum.inch=d1.inch+d2.inch;

    if (sum.inch>=12)
    {
        sum.inch=sum.inch-12;
        ++sum.feet;
    }

These are Problem Solving Through Programming In C Assignment 12 Answers

More Weeks of Problem Solving Through Programming In C: Click Here

More Nptel courses: https://progiez.com/nptel



These are Problem Solving Through Programming In C Assignment 12 Answers