Knowledge check.

- Choose one best answer from given 4 choices for each questions.
- Review before submit as you wont get a chance to review after submit.
- Max Time for quiz is 30 mins and Exam is 90 mins.
- Login is not required for an exam or a quiz.
- By submitting you formally acknowledge and accept terms and conditions mentioned here.

Question Number 1

Which of the following operator has the highest precedence in the following?

Question Number 2

The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int a, b, x, y, temp, gcd, lcm;

    printf("Enter two values : \n");
    scanf("%d%d", &x, &y);

    a = x;
    b = y;

    while (b != 0)
    {
        temp = b;
        a = temp;
    }

    b = a % b;
    gcd = a;
    lcm = (x*y) / gcd;

    printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
    printf("Least common multiple of %d and %d = %d\n", x, y, lcm);

    return 0;
}

Question Number 3

The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int a, b, x, y, temp, gcd, lcm;

    printf("Enter two values : \n");
    scanf("%d%d", &x, &y);

    a = x;
    b = y;

    while (b != 0)
    {
        temp = b;
        b = a % b;
        a = temp;
    }

    gcd = a;

    printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
    printf("Least common multiple of %d and %d = %d\n", x, y, lcm);

    return 0;
}

Question Number 4

Give the output of the following code snippet :
int main()
{
    char s[15] = "Hello";
    int i = 10;
    printf("%*s", i, s);
}

Question Number 5

Give the output of the following code snippet :
int main()
{
    int i;
#if A
    printf("Test 1");
#elif B
    printf("Test 2");
    return 0;
}

Question Number 6

The following program is used to copy a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    char ch;
    FILE *source, *target;

    if (source == NULL)
    {
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    target = fopen("Destination.txt", "w");

    if (target == NULL)
    {
        fclose(source);
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(source)) != EOF)
        fputc(ch, target);

    printf("File copied successfully.\n");

    fclose(source);
    fclose(target);

    return 0;
}

Question Number 7

The following program is used to reverse a string. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
#include < string.h>

int main()
{
    char str[100], reverse[100];
    int strlength, count, d;

    printf("Input a string\n");
    scanf("%s",str);
    strlength = strlen(str);

    for (count = strlength - 1, d = 0; count >= 0; count--, d++)
        reverse[count + 1] = str[d + 1];

    reverse[d] = '\0';
    printf("%s\n", reverse);
    return 0;
}

Question Number 8

The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
int str_compare(char[], char[]);

int main()
{
    int flag;
    char str1[100], str2[100];

    printf("Input first string\n");
    scanf("%s", str1);

    printf("Input second string\n");
    scanf("%s", str2);

    flag = str_compare(str1, str2);

    if (flag == 0)
        printf("Entered strings are equal.\n");
    else
        printf("Entered strings are not equal.\n");

    return 0;

}

int str_compare(char a[], char b[])
{
    int count = 0;

    while (a[count] == b[count])
    {
        if (a[count] == '\0' || b[count] == '\0')
            break;
        count++;
    }

    if (b[count] != '\0')
        return 0;
    else
        return -1;
}

Question Number 9

Give the output of the following code snippet :
void main()
{
#define max 37
    printf("%d", max);
}

Question Number 10

Which of the following is a valid variable initialization :

Question Number 11

The following program is used to find the maximum value in an array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
    int array[100], maximum, size, count, location = 1;

    printf("\nEnter the number of elements in array : ");
    scanf("%d", &size);

    printf("Enter %d integers : ", size);

    for (count = 0; count <  size; count++)
        scanf("\n%d", &array[count]);

    maximum = 0;

    for (count = 1; count <  size; count++)
    {
        if (array[count] > maximum)
        {
            maximum = array[count];
            location = count + 1;
        }
    }

    printf("Maximum element is present at location %d and its value is %d.\n", location, maximum);
    return 0;
}

Question Number 12

The following program is used to reverse a string. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdio.h>
#include < string.h>

int main()
{
    char str[100], reverse[100];
    int strlength, count, d;

    printf("Input a string\n");
    scanf("%s",str);
    reverse[d] = str[count];
    strlength = strlen(str);

    for (count = strlength - 1, d = 0; count >= 0; count--, d++)
        reverse[d] = '\0';
    printf("%s\n", reverse);
    return 0;
}

Question Number 13

Relational operators have greater precedence than arithmetic operators. True or false?

Question Number 14

The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int a, b, x, y, temp, gcd, lcm;

    printf("Enter two values : \n");
    scanf("%d%d", &x, &y);

    a = x;
    b = y;

    while (b != 0)
    {
        temp = b;
        b = a % b;
        a = temp;
    }

    gcd = a % b;
    lcm = (x*y) / gcd;

    printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
    printf("Least common multiple of %d and %d = %d\n", x, y, lcm);

    return 0;
}

Question Number 15

The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int a, b, x, y, temp, gcd, lcm;

    printf("Enter two values : \n");
    scanf("%d%d", &x, &y);

    a = x;
    b = y;

    gcd = a;
    lcm = (x*y) / gcd;

    while (b != 0)
    {
        temp = b;
        b = a % b;
        a = temp;
    }


    printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
    printf("Least common multiple of %d and %d = %d\n", x, y, lcm);

    return 0;
}

Question Number 16

The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int a, b, x, y, temp, gcd, lcm;

    printf("Enter two values : \n");
    scanf("%d%d", &x, &y);

    a = x;
    b = y;

    while (b != 0)
    {
        temp = b;
        b = a % b;
        a = temp;
    }

    gcd = a;
    lcm = (x*y) / gcd;

    printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
    printf("Least common multiple of %d and %d = %d\n", x, y, lcm);

    return 0;
}

Question Number 17

The following program is used to copy a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int main()
{
    char ch;
    FILE *source, *target;
    source = fopen("CopyFile.txt", "r");

    if (source == NULL)
    {
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    target = fopen("Destination.txt", "w");

    if (target == NULL)
    {
        fclose(source);
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(source)) != EOF)
        fputc(ch, target);

    printf("File copied successfully.\n");

    fclose(source);
    fclose(target);

    return 0;
}

Question Number 18

The following program is used to concatenate two strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void str_cat(char[], char[]);

int main()
{
    char str1[100], str2[100];

    printf("Input a string : \n");
    scanf("%s", str1);

    printf("Input string to concatenate : \n");
    scanf("%s", str2);

    str_cat(str1, str2);

    printf("String obtained on concatenation : %s \n", str1);

    return 0;
}

void str_cat(char str1[], char str2[])
{
    int count = 0, d = 0;

    while (str1[count] != '\0')
    {
        count++;
    }
    while (str2[d] != '\0')
    {
        str1[count] = str2[d];
        d++;
        count++;
    }
}

Question Number 19

scanf returns as its value

Question Number 20

The following program is used to find the maximum value in an array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
    int array[100], maximum, size, count, location = 1;

    printf("\nEnter the number of elements in array : ");
    scanf("%d", &size);

    printf("Enter %d integers : ", size);

    for (count = 0; count <  size; count++)
        scanf("\n%d", &array[count]);

    maximum = array[0];

    for (count = 1; count <  size; count++)
    {
        if (array[count] > maximum)
        {
            size = array[count];
            location = count + 1;
        }
    }

    printf("Maximum element is present at location %d and its value is %d.\n", location, maximum);
    return 0;
}

Question Number 21

The following program is used to add two complex numbers by passing structure to a function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
struct complex
{
    float real;
    float imag;
};
struct complex Add(complex n1, complex n2);
int main()
{
    struct complex n1, n2, temp;
    printf("For first complex number : \n");
    printf("Enter real part :\n");
    scanf("%f", &n1.real);
    printf("Enter imaginary part :\n");
    scanf("%f", &n1.imag);
    printf("For second complex number : \n");
    printf("Enter real part :\n");
    scanf("%f", &n2.real);
    printf("Enter imaginary part :\n");
    scanf("%f", &n2.imag);
    temp = Add(n1, n2);
    printf("Sum=%.1f+%.1fi", temp.real, temp.imag);
    return 0;
}
struct complex Add(struct complex n1, struct complex n2)
{
    struct complex temp;
    temp.real = n1.real + n2.real;
    temp.imag = n1.imag + n2.imag;
    return(temp);
}

Question Number 22

The following program is used to add 'n' numbers. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>

int main()
{
    int num, sum = 1, count, value;

    printf("Enter the number of integers to be added : \n");
    scanf("%d", &num);

    printf("Enter %d integers\n", num);

    for (count = 1; count < = num; count++)
    {
        scanf("%d", &value);
        sum = sum / value;
    }

    printf("Sum of entered integers = %d\n", sum);

    return 0;
}

Question Number 23

Which of the following is a valid declaration for fgets() inside the library?

Question Number 24

The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int str_compare(char[], char[]);

int main()
{
    int flag;
    char str1[100], str2[100];

    printf("Input first string\n");
    scanf("%s", str1);

    printf("Input second string\n");
    scanf("%s", str2);

    if (flag == 0)
        printf("Entered strings are equal.\n");
    else
        printf("Entered strings are not equal.\n");

    return 0;

}

int str_compare(char a[], char b[])
{
    int count = 0;

    while (a[count] == b[count])
    {
        if (a[count] == '\0' || b[count] == '\0')
            break;
        count++;
    }

    if (a[count] == '\0' && b[count] == '\0')
        return 0;
    else
        return -1;
}

Question Number 25

The following program is used to find the maximum value in an array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
    int array[100], maximum, size, count, location = 1;

    printf("\nEnter the number of elements in array : ");
    scanf("%d", &size);

    printf("Enter %d integers : ", size);

    for (count = 0; count <  size; count++)
        scanf("\n%d", &array[count]);

    maximum = array[0];

    for (count = 1; count <  size; count++)
    {
        maximum = array[count];
        location = count + 1;
    }

    printf("Maximum element is present at location %d and its value is %d.\n", location, maximum);
    return 0;
}

Question Number 26

The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    FILE *fs1, *fs2, *ft;
    char ch;

    fs1 = fopen("File1.txt", "r");
    fs2 = fopen("File2.txt", "r");

    if (fs1 == NULL || fs2 == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    ft = fopen("Final.txt", "w");

    if (ft == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(fs1)) != EOF)
        fputc(ch, ft);

    while ((ch = fgetc(fs2)) != EOF)
        fputc(ch, ft);

    printf("Two files have been merged successfully");

    fclose(fs1);
    fclose(fs2);
    fclose(ft);

    return 0;
}

Question Number 27

Which of the following conversion specifiers is used to display a pointer value (memory address) in an implementation defined manner.

Question Number 28

The following program is used to add two distances ( inch to feet ) using structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
struct Distance
{
    int feet;
    float inch;
};
struct Distance dist1, dist2, sum;

void main()
{
    printf("Enter information for 1st distance\n");
    printf("Enter feet: ");
    scanf("%d", &dist1.feet);
    printf("Enter inch: ");
    scanf("%f", &dist1.inch);
    printf("\nEnter information for 2nd distance\n");
    printf("Enter feet: ");
    scanf("%d", &dist2.feet);
    printf("Enter inch: ");
    scanf("%f", &dist2.inch);
    sum.feet = dist1.feet + dist2.feet;
    sum.inch = dist1.inch + dist2.inch;

    if (sum  <  0)
    {
        sum.inch = sum.inch - 12.0;
        ++sum.feet;
    }
    printf("\nSum of distances=%d\'-%.1f\"", sum.feet, sum.inch);
}

Question Number 29

The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);

int main()
{
    int arry1[100], arry2[100], num1, num2, c, result[200];

    printf("Input number of elements in first array\n");
    scanf("%d", &num1);

    printf("Input %d integers\n", num1);
    for (c = 0; c <  num1; c++)
    {
        scanf("%d", &arry1[c]);
    }

    printf("Input number of elements in second array\n");
    scanf("%d", &num2);

    printf("Input %d integers\n", num2);
    for (c = 0; c <  num2; c++)
    {
        scanf("%d", &arry2[c]);
    }

    MergeArrays(arry1, num1, arry2, num2, result);

    printf("Result array:\n");

    for (c = 0; c <  num1 + num2; c++)
    {
        printf("%d\n", result[c]);
    }
    return 0;
}

void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
    int i, j, k;
    j = k = 0;

    for (i = 0; i <  num1 + num2;)
    {
        if (j <  num1 && k <  num2)
        {

            if (arry1[j] <  arry2[k])
            {
                result[i] = arry1[j];
                j++;
            }
            else
            {
                result[i] = arry2[k];
                k++;
            }
            i++;
        }

        else if (j == num1)
        {
            {
                result[i] = arry2[k];
                k++;
                i++;
            }
        }

        else
        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry1[j];
                j++;
                i++;
            }
        }
    }
}

Question Number 30

Give the output of the following code snippet :
void main()
{
    short int x=205;
    int y=10;
    short int z;
    z=x % y;

    printf("%d",z);
}

Question Number 31

The following program is used to copy a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    char ch;
    FILE *source, *target;

    if (source == NULL)
    {
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    target = fopen("Destination.txt", "w");

    if (target == NULL)
    {
        fclose(source);
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(source)) != EOF)
        fputc(ch, target);

    printf("File copied successfully.\n");

    fclose(source);
    fclose(target);

    return 0;
}

Question Number 32

Give the output of the following code snippet :
void main()
{
    float x = 0.1;
    printf("%d, ", x);
    printf("%f", x);
}

Question Number 33

The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);

int main()
{
    int arry1[100], arry2[100], num1, num2, c, result[200];

    printf("Input number of elements in first array\n");
    scanf("%d", &num1);

    printf("Input %d integers\n", num1);
    for (c = 0; c <  num1; c++)
    {
        scanf("%d", &arry1[c]);
    }

    printf("Input number of elements in second array\n");
    scanf("%d", &num2);

    printf("Input %d integers\n", num2);
    for (c = 0; c <  num2; c++)
    {
        scanf("%d", &arry2[c]);
    }

    MergeArrays(arry1, num1, arry2, num2, result);

    printf("Result array:\n");

    for (c = 0; c <  num1 + num2; c++)
    {
        printf("%d\n", result[c]);
    }
    return 0;
}

void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
    int i, j, k;
    j = k = 0;

    if (j <  num1 && k <  num2)
    {

        if (arry1[j] <  arry2[k])
        {
            result[i] = arry1[j];
            j++;
        }
        else
        {
            result[i] = arry2[k];
            k++;
        }
        i++;
    }

    else if (j == num1)
    {
        for (; i <  num1 + num2;)
        {
            result[i] = arry2[k];
            k++;
            i++;
        }
    }

    else
    {
        for (; i <  num1 + num2;)
        {
            result[i] = arry1[j];
            j++;
            i++;
        }

    }
}

Question Number 34

The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int a, b, x, y, temp, gcd, lcm;

    printf("Enter two values : \n");
    scanf("%d%d", &x, &y);

    a = x;
    b = y;

    while (b != 0)
    {
        b = a % b;
        temp = b;
        a = temp;
    }

    gcd = a;
    lcm = (x*y) / gcd;

    printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
    printf("Least common multiple of %d and %d = %d\n", x, y, lcm);

    return 0;
}

Question Number 35

The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
int str_compare(char[], char[]);

int main()
{
    int flag;
    char str1[100], str2[100];

    printf("Input first string\n");
    scanf("%s", str1);

    printf("Input second string\n");
    scanf("%s", str2);

    flag = str_compare(str1, str2);

    if (flag == str1)
        printf("Entered strings are equal.\n");
    else
        printf("Entered strings are not equal.\n");

    return 0;

}

int str_compare(char a[], char b[])
{
    int count = 0;

    while (a[count] == b[count])
    {
        if (a[count] == '\0' || b[count] == '\0')
            break;
        count++;
    }

    if (a[count] == '\0' && b[count] == '\0')
        return 0;
    else
        return -1;
}

Question Number 36

The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    FILE *fs1, *fs2, *ft;
    char ch;

    fs1 = fopen("File1.txt", "r");
    fs2 = fopen("File2.txt", "r");

    if (fs1 == NULL || fs2 == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    ft = fopen("Final.txt", "w");

    if (ft == fs1)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(fs1)) != EOF)
        fputc(ch, ft);

    while ((ch = fgetc(fs2)) != EOF)
        fputc(ch, ft);

    printf("Two files have been merged successfully");

    fclose(fs1);
    fclose(fs2);
    fclose(ft);

    return 0;
}

Question Number 37

The following program is used to add two complex numbers by passing structure to a function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
structure complex
{
    float real;
    float imag;
};
struct complex Add(struct complex n1, struct complex n2);
int main()
{
    struct complex n1, n2, temp;
    printf("For first complex number : \n");
    printf("Enter real part :\n");
    scanf("%f", &n1.real);
    printf("Enter imaginary part :\n");
    scanf("%f", &n1.imag);
    printf("For second complex number : \n");
    printf("Enter real part :\n");
    scanf("%f", &n2.real);
    printf("Enter imaginary part :\n");
    scanf("%f", &n2.imag);
    temp = Add(n1, n2);
    printf("Sum=%.1f+%.1fi", temp.real, temp.imag);
    return 0;
}
struct complex Add(struct complex n1, struct complex n2)
{
    struct complex temp;
    temp.real = n1.real + n2.real;
    temp.imag = n1.imag + n2.imag;
    return(temp);
}

Question Number 38

The following program is used to check if the given number is odd or even. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int value;
    printf("Enter the value to be checked : ");
    scanf("%d", &value);
    printf("%d is even", value);
    else
        printf("%d is odd ", value);
    return 0;
}

Question Number 39

The following program is used to concatenate two strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void str_cat(char[], char[]);

int main()
{
    char str1[100], str2[100];

    printf("Input a string : \n");
    scanf("%s", str1);

    printf("Input string to concatenate : \n");
    scanf("%s", str2);

    str_cat(str1, str2);

    printf("String obtained on concatenation : %s \n", str1);

    return 0;
}

void str_cat(char str1[], char str2[])
{
    int count = 0, d = 0;

    while (str1[count] != '\0')
    {
        count++;
    }
    while (str2[count] == '\0')
    {
        str1[count] = str2[d];
        d++;
        count++;
    }

    str1[count] = '\0';
}

Question Number 40

Give the output of the following code snippet :
void main()
{
    int x = 98;
    char y = x;
    printf("%c\n", y);
}

Question Number 41

The following program is used to display the student details using structures. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?

{
    char name[50];
    int studId;
    int marks;
};

int main()
{
    struct student stud[10];
    int i, num;
    printf("Enter number of students : \n");
    scanf("%d",&num);
    printf("Enter information of students:\n");
    for (i = 0; i<  num; ++i)
    {
        stud[i].studId = i + 1;
        printf("\nStudent ID %d\n", stud[i].studId);
        printf("Enter name: ");
        scanf("%s", stud[i].name);
        printf("Enter marks: ");
        scanf("%d", &stud[i].marks);
        printf("\n");
    }
    printf("Student Information :\n\n");
    for (i = 0; i<  num; ++i)
    {
        printf("\nStudent ID %d:\n", i + 1);
        printf("Name: %s", stud[i].name);
        printf("Marks: %d", stud[i].marks);
    }
    return 0;
}

Question Number 42

The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?


#include < stdio.h>

int main()
{
    int count, n, num1 = 0, num2 = 1, result = 0;
    printf("Enter number of terms: ");
    scanf("%d", &n);
    printf("Fibonacci Series:\n %d  %d  ", num1, num2);
    count = 2;
    while (count != n)
    {
        result = num1 + num2;
        num1 = num2;
        num2 = result;
        ++count;
        printf("%d ", result);
    }
    return 0;
}

Question Number 43

The following program is used to add two complex numbers by passing structure to a function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
struct complex
{
    float real;
    float imag;
};
complex Add(struct complex n1, struct complex n2);
int main()
{
    struct complex n1, n2, temp;
    printf("For first complex number : \n");
    printf("Enter real part :\n");
    scanf("%f", &n1.real);
    printf("Enter imaginary part :\n");
    scanf("%f", &n1.imag);
    printf("For second complex number : \n");
    printf("Enter real part :\n");
    scanf("%f", &n2.real);
    printf("Enter imaginary part :\n");
    scanf("%f", &n2.imag);
    temp = Add(n1, n2);
    printf("Sum=%.1f+%.1fi", temp.real, temp.imag);
    return 0;
}
struct complex Add(struct complex n1, struct complex n2)
{
    struct complex temp;
    temp.real = n1.real + n2.real;
    temp.imag = n1.imag + n2.imag;
    return(temp);
}

Question Number 44

Give the output of the following code snippet :
int main()
{
    int a;
    printf("%d\n",a);
    return 0;
}

Question Number 45

The following program is used to find the substring in a string without using string function. Which of the following statement(s) given in the choices should reordered to make the program compile, link and run and give the desired output?
int main()
{
    char str[100], sub[100];
    int position, length, count = 0;

    printf("Input a string  : \n");
    scanf("%s",str);

    printf("Enter the position and length of substring\n");
    scanf("%d%d", &position, &length);
    sub[count] = str[position + count - 1];

    while (count <  length)
    {
        count++;
    }
    sub[count] = '\0';

    printf("Required substring is %s\n", sub);

    return 0;
}

Question Number 46

Which of the following can be used for random number generation?

Question Number 47

The function to generate a sequence of pseudo-random integers is defined in which header file?

Question Number 48

The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);

int main()
{
    char str[100], dest[100];

    printf("Input a string\n");
    scanf("%s",str);

    copy_str(dest, str);

    printf("Source string:      %s\n", str);
    printf("Destination string: %s\n", dest);

    return 0;
}

void copy_str(char d[], char s[])
{
    int count = 0;

    while (s[count] != '\0')
    {
        d[count] = s[count];
    }
    count++;
    d[count] = '\0';
}

Question Number 49

The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);

int main()
{
    char str[100], dest[100];

    printf("Input a string\n");
    scanf("%s",str);

    copy_str(dest, str);

    printf("Source string:      %s\n", str);
    printf("Destination string: %s\n", dest);

    return 0;
}

void copy_str(char d[], char s[])
{
    int count = 0;

    while (s[count] != '\0')
    {
        s[count] = '\0';
        count++;
    }
    d[count] = '\0';
}

Question Number 50

The following program is used to add two complex numbers by passing structure to a function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct complex
{
    float real;
    float imag;
};
struct complex Add(struct complex n1, struct complex n2);
int main()
{
    struct complex n1, n2, temp;
    printf("For first complex number : \n");
    printf("Enter real part :\n");
    scanf("%f", &n1.real);
    printf("Enter imaginary part :\n");
    scanf("%f", &n1.imag);
    printf("For second complex number : \n");
    printf("Enter real part :\n");
    scanf("%f", &n2.real);
    printf("Enter imaginary part :\n");
    scanf("%f", &n2.imag);
    printf("Sum=%.1f+%.1fi", temp.real, temp.imag);
    return 0;
}
struct complex Add(struct complex n1, struct complex n2)
{
    struct complex temp;
    temp.real = n1.real + n2.real;
    temp.imag = n1.imag + n2.imag;
    return(temp);
}

Question Number 51

Give the output of the following code snippet :
void main()
{

    printf("%d %d",printf("Hello World "));

}

Question Number 52

The following program is used to swap two strings. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int main()
{
    char str1[100], str2[100], temp[50];

    printf("Enter the str1 string\n");
    scanf("%s", str1);

    printf("Enter the str2 string\n");
    scanf("%s", str2);

    printf("\nBefore Swapping\n");
    printf("First string: %s\n", str1);
    printf("Second string: %s\n\n", str2);

    strcpy(temp, str1);
    strcpy(str2, temp);

    printf("After Swapping\n");
    printf("First string: %s\n", str1);
    printf("Second string: %s\n", str2);

    return 0;
}

Question Number 53

The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int a, b, x, y, temp, gcd, lcm;

    printf("Enter two values : \n");
    scanf("%d%d", &x, &y);

    a = x;
    b = y;
    temp = b;

    while (b != 0)
    {
        b = a % b;
        a = temp;
    }

    gcd = a;
    lcm = (x*y) / gcd;

    printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
    printf("Least common multiple of %d and %d = %d\n", x, y, lcm);

    return 0;
}

Question Number 54

Give the output of the following code snippet :
void main()
{
    float double x;
    x=100.50;
    x++;
    printf("%d",x);
}

Question Number 55

What type of argument needs to be passed to the getc() function in C?

Question Number 56

The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?


#include < stdio.h>

int main()
{
    int count, n, num1 = 0, num2 = 1, result = 0;
    printf("Enter number of terms: ");
    scanf("%d", &n);
    printf("Fibonacci Series:\n %d  %d  ", num1, num2);
    count = 2;
    while (count< n)
    {
        result = num1 / num2;
        num1 = num2;
        num2 = result;
        ++count;
        printf("%d ", result);
    }
    return 0;
}

Question Number 57

The following program is used to sort an array of structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>

struct student
{
    char name[50];
    int studId;
    int marks;
};

int main()
{
    struct student stud[10],temp;
    int i, num;
    printf("Enter number of students : \n");
    scanf("%d", &num);
    printf("Enter information of students:\n");
    for (i = 0; i<  stud; ++i)
    {
        printf("Enter student ID: ");
        scanf("%d", &stud[i].studId);
        printf("Enter name: ");
        scanf("%s", stud[i].name);
        printf("Enter marks: ");
        scanf("%d", &stud[i].marks);
        printf("\n");
    }

    for (i = 0; i <  num; i++)
        for (int j = 0; j <  i; j++)
            if (stud[i].studId <  stud[j].studId)
            {
                temp = stud[i];
                stud[i] = stud[j];
                stud[j] = temp;
            }

    printf("Student Information :\n\n");
    for (i = 0; i<  num; ++i)
    {
        printf("\nStudent ID %d:\n",stud[i].studId);
        printf("Name: %s", stud[i].name);
        printf("Marks: %d", stud[i].marks);
    }
    return 0;
}

Question Number 58

For a given C program, where is the execution started?

Question Number 59

The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int a, b, x, y, temp, gcd, lcm;

    printf("Enter two values : \n");
    scanf("%d%d", &x, &y);

    a = x;
    b = y;

    while (b != 0)
    {
        temp = b / a;
        b = a % b;
        a = temp;
    }

    gcd = a;
    lcm = (x*y) / gcd;

    printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
    printf("Least common multiple of %d and %d = %d\n", x, y, lcm);

    return 0;
}

Question Number 60

Give the output of the following code snippet :

{
    int a = 5, b = -7, c = 0, d;
    d = ++a && ++b || ++c;
    printf("%d  %d  %d  %d  ", a,b, c, d);
}

Question Number 61

The following program is used to add 'n' numbers. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>

int main()
{
    int num, sum = 0, count, value;

    printf("Enter the number of integers to be added : \n");
    scanf("%d", &num);

    printf("Enter %d integers\n", num);

    for (count = 1; count < = num; count++)
    {
        scanf("%d", &value);
        sum = sum * value;
    }

    printf("Sum of entered integers = %d\n", sum);

    return 0;
}

Question Number 62

The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);

int main()
{
    int arry1[100], arry2[100], num1, num2, c, result[200];

    printf("Input number of elements in first array\n");
    scanf("%d", &num1);

    printf("Input %d integers\n", num1);
    for (c = 0; c <  num1; c++)
    {
        scanf("%d", &arry1[c]);
    }

    printf("Input number of elements in second array\n");
    scanf("%d", &num2);

    printf("Input %d integers\n", num2);
    for (c = 0; c <  num2; c++)
    {
        scanf("%d", &arry2[c]);
    }

    MergeArrays(arry1, num1, arry2, num2, result);

    printf("Result array:\n");

    for (c = 0; c <  num1 + num2; c++)
    {
        printf("%d\n", result[c]);
    }
    return 0;
}

void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
    int i, j, k;
    j = k = 0;

    for (i = 0; i <  num1 + num2;)
    {
        if (j <  num1 && k <  num2)
        {

            if (arry1[j] == arry2[k])
            {
                result[i] = arry1[j];
                j++;
            }
            else
            {
                result[i] = arry2[k];
                k++;
            }
            i++;
        }

        else if (j == num1)
        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry2[k];
                k++;
                i++;
            }
        }

        else
        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry1[j];
                j++;
                i++;
            }
        }
    }
}

Question Number 63

What are the restrictions places on the names of variables and constants in C?

Question Number 64

Give the output of the following code snippet :
int main()
{
    const int a = 10;

    printf("%d\n",a);
    return 0;
}

Question Number 65

The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    FILE *fs1, *fs2, *ft;
    char ch;

    fs1 = fopen("File1.txt", "r");
    fs2 = fopen("File2.txt", "r");

    if (fs1 == NULL || fs2 == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    if (ft == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(fs1)) != EOF)
        fputc(ch, ft);

    while ((ch = fgetc(fs2)) != EOF)
        fputc(ch, ft);

    printf("Two files have been merged successfully");

    fclose(fs1);
    fclose(fs2);
    fclose(ft);

    return 0;
}

Question Number 66

The following program is used to copy a file. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    char ch;
    FILE *source, *target;
    source = fopen("CopyFile.txt", "r");

    if (source == NULL)
    {
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    target = fopen("Destination.txt", "w");

    if (target == NULL)
    {
        fclose(source);
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(target)) != EOF)
        fputc(ch, source);

    printf("File copied successfully.\n");

    fclose(source);
    fclose(target);

    return 0;
}

Question Number 67

The function ungetc() may be used with which of the following functions?

Question Number 68

Give the output of the following code snippet :

void main()
{
    int b = 5 & 4 & 6;
    printf("%d", b);
}

Question Number 69

Give the output of the following code snippet :
void fun()
{
    printf("%d\n", max * 10);
}
int main()
{
#define max 10
    fun();
    return 0;
}

Question Number 70

The following program is used to reverse a string. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
#include < stringlength.h>

int main()
{
    char str[100], reverse[100];
    int strlength, count, d;

    printf("Input a string\n");
    scanf("%s",str);
    strlength = strlen(str);

    for (count = strlength - 1, d = 0; count >= 0; count--, d++)
        reverse[d] = str[count];

    reverse[d] = '\0';
    printf("%s\n", reverse);
    return 0;
}

Question Number 71

Which of the following statements is true about a character constant in C :

Question Number 72

The following program is used to reverse a string. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
#include < string.h>

int main()
{
    char str[100], reverse[100];
    int strlength, count, d;

    printf("Input a string\n");
    scanf("%s",str);
    strlength = strlen();

    for (count = strlength - 1, d = 0; count >= 0; count--, d++)
        reverse[d] = str[count];

    reverse[d] = '\0';
    printf("%s\n", reverse);
    return 0;
}

Question Number 73

The following program is used to find length of a string without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int string_length(char[]);

int main()
{
    char str[100];
    int length;

    printf("Input a string\n");
    length = string_length(str);
    printf("Length of string %s = %d\n", str, length);

    return 0;
}

int string_length(char s[])
{
    int count = 0;

    while (s[count] != '\0')
        count++;

    return count;
}

Question Number 74

Give the output of the following code snippet :
#define CUBE(x)((x)*(x)*(x))
void fun()
{
    int x=2,y=1;
    int z=CUBE(++x + --y);
    printf("%d ",y);
}
void main()
{
    int a=3,b=10,c=5;
    int d;
    fun();
    b=CUBE(a+3)/b+c-a;
    printf("%d",b);
}

Question Number 75

The following program is used to check if the given number is a prime number or not. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include< stdio.h>

int main()
{
    int value, i, flag = 0;
    printf("Enter a positive value: ");
    scanf("%d", &value);
    for (i = 2; i < = value / 2; ++i)
    {
        if (value % i == 0)
        {
            break;
        }
    }
    if (flag == 0)
        printf("%d is a prime number", value);
    else
        printf("%d is not a prime number", value);
    return 0;
}

Question Number 76

The following program is used to find length of a string without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void string_length(char[]);

int main()
{
    char str[100];
    int length;

    printf("Input a string\n");
    scanf("%s", str);
    length = string_length(str);
    printf("Length of string %s = %d\n", str, length);

    return 0;
}

int string_length(char s[])
{
    int count = 0;

    while (s[count] != '\0')
        count++;

    return count;
}

Question Number 77

Give the output of the following code :
int main()
{
    int a=100, b=200, c;
    c = (a == 100 || b > 200);
    printf("%d\n", c);
    return 0;
}

Question Number 78

The following program is used to display the student details using structures. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct student
{
    char name[50];
    int studId;
    int marks;
};

int main()
{
    struct student stud[10];
    int i, num;
    printf("Enter number of students : \n");
    scanf("%d",&num);
    printf("Enter information of students:\n");
    for (i = 0; i<  num; ++i)
    {
        stud[i].studId = i + 1;
        printf("\nStudent ID %d\n", stud[i].studId);
        printf("Enter name: ");
        scanf("%s", stud[i].name);
        printf("Enter marks: ");
        scanf("%d", &stud[i].marks);
        printf("\n");
    }
    printf("Student Information :\n\n");
    for (i = 0; i<  num; ++i)
    {
        printf("\nStudent ID %d:\n", i + 1);
        printf("Name: %s", stud[i].name);
        printf("Marks: %d", stud[i].marks);
    }
    return 0;
}

Question Number 79

Which of the following fall under the category of multiplicative operators?

Question Number 80

The macro va_start initializes the argument pointer to point to ?

Question Number 81

Which of the following are types of C constants ?

Question Number 82

The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?


#include < stdio.h>

int main()
{
    int count, n, num1 = 0, num2 = 1, result = 0;
    printf("Enter number of terms: ");
    scanf("%d", &n);
    printf("Fibonacci Series:\n %d  %d  ", num1, num2);
    count = 2;
    while (count< n)
    {
        num1 = num2;
        num2 = result;
        ++count;
        printf("%d ", result);
    }
    result = num1 + num2;
    return 0;
}

Question Number 83

The following program is used to find length of a string without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
int string_length(char[]);

int main()
{
    char str[100];
    int length;

    printf("Input a string\n");
    scanf("%s", str);
    length = string_length(str);
    printf("Length of string %s = %d\n", str, length);

    return 0;
}

int string_length(char s[])
{
    int count = 0;

    while (s != '\0')
        count++;

    return count;
}

Question Number 84

The following program is used to check if the given number is odd or even. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int value;
    printf("Enter the value to be checked : ");
    scanf("%d", &value);
    if ((value % 2) == -1)
        printf("%d is even", value);
    else
        printf("%d is odd ", value);
    return 0;
}

Question Number 85

The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?


#include < stdio.h>

int main()
{
    int count, n, num1 = 0, num2 = 1, result = 0;
    printf("Enter number of terms: ");
    scanf("%d", &n);
    printf("Fibonacci Series:\n %d  %d  ", num1, num2);
    count = 2;
    if (count == n)
    {
        result = num1 + num2;
        num1 = num2;
        num2 = result;
        ++count;
        printf("%d ", result);
    }
    return 0;
}

Question Number 86

The following program is used to print the IP address of the system. Which of the following statement(s) given in the choices should be added to make the program compile, link and run and give the desired output?
#include < stdio.h>
#include < stdlib.h>


int main()
{
    return 0;
}

Question Number 87

Which type of files can’t be opened using fopen()?

Question Number 88

Give the output of the following code :
void main()
{
    char c='a';
    printf("Initial value = %c", c);
    scanf("%d",&c);
    printf("New value=%d",c);
}
Assume that the input given  is c='12'. Give the final value of c :

Question Number 89

The following program is used to delete an element from an array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
    int array[100], position, count, n;

    printf("Enter number of elements in array : \n");
    scanf("%d", &n);

    printf("Enter %d elements : \n", n);

    for (count = 0; count <  n; count++)
        scanf("%d", &array);

    printf("Enter the location where you wish to delete element : \n");
    scanf("%d", &position);

    if (position >= n + 1)
        printf("Deletion not possible.\n");
    else
    {
        for (count = position - 1; count <  n - 1; count++)
            array[count] = array[count + 1];

        printf("Resultant array : ");

        for (count = 0; count <  n - 1; count++)
            printf("%d\n", array[count]);
    }

    return 0;
}

Question Number 90

What is a FILE in C?

Question Number 91

The following program is used to concatenate two strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void str_cat(char[], char[]);

int main()
{
    char str1[100], str2[100];

    printf("Input a string : \n");
    scanf("%s", str1);

    printf("Input string to concatenate : \n");
    scanf("%s", str2);

    str_cat(str1, str2);

    printf("String obtained on concatenation : %s \n", str1);

    return 0;
}

void str_cat(char str1[], char str2[])
{
    int count = 0, d = 0;

    while (str1[count] != '\0')
    {
        count++;
    }
    while (str2[d] != '\0')
    {
        count++;
    }

    str1[count] = '\0';
}

Question Number 92

The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);

int main()
{
    int arry1[100], arry2[100], num1, num2, c, result[200];

    printf("Input number of elements in first array\n");
    scanf("%d", &num1);

    printf("Input %d integers\n", num1);
    for (c = 0; c <  num1; c++)
    {
        scanf("%d", &arry1[c]);
    }

    printf("Input number of elements in second array\n");
    scanf("%d", &num2);

    printf("Input %d integers\n", num2);
    for (c = 0; c <  num2; c++)
    {
        scanf("%d", &arry2[c]);
    }

    MergeArrays(arry1, num1, arry2, num2, result);

    printf("Result array:\n");

    for (c = 0; c <  num1 + num2; c++)
    {
        printf("%d\n", result[c]);
    }
    return 0;
}

void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
    int i, j, k;
    j = k = 0;

    for (i = 0; i <  num1 + num2;)
    {
        if (j <  num1 && k <  num2)
        {

            if (arry1[j] <  arry2[k])
            {
                result[i] = arry1[j];
                j++;
            }
            else
            {
                result[i] = arry2[k];
                k++;
            }
            i++;
        }

        else if (j == num1)
        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry2[k];
                k++;
                i++;
            }
        }


    }
}

Question Number 93

The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    FILE *fs1, *fs2, *ft;
    char ch;

    fs1 = fopen("File1.txt", "r");
    fs2 = fopen("File2.txt", "r");

    if (fs1 == NULL || fs2 == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    ft = fopen("Final.txt", "w");

    if (ft == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    if ((ch = fgetc(fs1)) != EOF)
        fputc(fs2, ft);

    while ((ch = fgetc(fs2)) != EOF)
        fputc(ch, ft);

    printf("Two files have been merged successfully");

    fclose(fs1);
    fclose(fs2);
    fclose(ft);

    return 0;
}

Question Number 94

Which of the following is the general declaration of the minprintf() function?

Question Number 95

The following program is used to generate the palindrome of a number. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
    int value,num, reverse = 0;

    printf("Enter a number to reverse : ");
    scanf("%d", &value);

    num = 0;

    while (num != 0)
    {
        reverse = reverse * 10;
        reverse = reverse + num % 10;
        num = num / 10;
    }

    if (value == reverse)
        printf(" %d is a Palindrome",value);
    else
        printf(" %d is not a Palindrome", value);

    return 0;
}

Question Number 96

How many characters of pushback are guaranteed per file when ungetc() is used.

Question Number 97

The following program is used to add two complex numbers by passing structure to a function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct complex
{
    float real;
    float imag;
};
struct complex Add(struct complex n1, struct complex n2);
int main()
{
    struct complex n1, n2, temp;
    printf("For first complex number : \n");
    printf("Enter real part :\n");
    scanf("%f", &n1.real);
    printf("Enter imaginary part :\n");
    scanf("%f", &n1.imag);
    printf("For second complex number : \n");
    printf("Enter real part :\n");
    scanf("%f", &n2.real);
    printf("Enter imaginary part :\n");
    scanf("%f", &n2.imag);
    temp = Add(n1, n2);
    printf("Sum=%.1f+%.1fi", temp.real, temp.imag);
    return 0;
}
struct complex Add(struct complex n1, struct complex n2)
{
    struct complex temp;
    temp.imag = n1.imag + n2.imag;
    return(temp);
}

Question Number 98

The following program is used to delete a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int status;
    status = remove("Input.txt");

    printf("File has been deleted successfully\n");
    else
    {
        printf("Unable to delete the file\n");
        perror("Error");
    }
    return 0;
}

Question Number 99

The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?


#include < stdio.h>

int main()
{
    int count, n, num1 = 0, num2 = 1, result = 0;
    printf("Enter number of terms: ");
    scanf("%d", &n);
    printf("Fibonacci Series:\n %d  %d  ", num1, num2);
    count = 0;
    while (count< n)
    {
        result = num1 + num2;
        num1 = num2;
        num2 = result;
        ++count;
        printf("%d ", result);
    }
    return 0;
}

Question Number 100

The following program is used to swap two values. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
    int value1, value2, temp;

    printf("\nEnter the value of value1 : ");
    scanf("%d", &value1);
    printf("\nEnter the value of value2 : ");
    scanf("%d", &value2);

    printf("Before Swapping\nvalue1 = %d\nvalue2 = %d\n", value1, value2);

    temp = value1;
    value2 = temp;

    printf("After Swapping\nvalue1 = %d\nvalue2 = %d\n", value1, value2);

    return 0;
}

Question Number 101

The following program is used to find length of a string without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
int string_length(char[]);

int main()
{
    char str[100];
    int length;

    printf("Input a string\n");
    scanf("%s", str);
    length = string_length(str);
    printf("Length of string %s = %d\n", str, length);

    return 0;
}

void string_length(char s[])
{
    int count = 0;

    while (s[count] != '\0')
        count++;

    return count;
}

Question Number 102

The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?


#include < stdio.h>

int main()
{
    int count, n, num1 = 0, num2 = 1, result = 0;
    printf("Enter number of terms: ");
    scanf("%d", &n);
    printf("Fibonacci Series:\n %d  %d  ", num1, num2);
    count = 2;
    if (count< n)
    {
        result = num1 + num2;
        num1 = num2;
        num2 = result;
        ++count;
        printf("%d ", result);
    }
    return 0;
}

Question Number 103

In printf function in C, which is the format specifier used to print characters?

Question Number 104

Give the output of the following code snippet :
void main()
{
    int b = 5 + 7 * 4 - 9 * (3-2);
    printf("%d", b);
}

Question Number 105

What is the output of the mathematical function sin(x)?

Question Number 106

Right shifting an unsigned quantity, always filled the vacated bits with :

Question Number 107

The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);

int main()
{
    char str[100], dest[100];

    printf("Input a string\n");
    scanf("%s",str);

    copy_str(dest, str);

    printf("Source string:      %s\n", str);
    printf("Destination string: %s\n", dest);

    return 0;
}

void copy_str(char d[], char s[])
{
    int count = 0;

    while (s[count] != '\0')
    {
        count++;
    }
    d[count] = '\0';
}

Question Number 108

The following program is used to sort an array of values using Bubble sort technique. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void bubble_sort(int arry[], int n);
int main()
{
    int array[100], n, c;

    printf("Enter number of elements\n");
    scanf("%d", &n);

    printf("Enter %d integers\n", n);

    for (c = 0; c <  n; c++)
        scanf("%d", &array[c]);

    bubble_sort(array, n);

    printf("Sorted array in ascending order:\n");

    for (c = 0; c <  n; c++)
        printf("%d\n", array[c]);

    return 0;
}

void bubble_sort(int arry[], int n)
{
    int c, d, temp;

    for (c = 0; c <  (n - 1); c++)
    {
        for (d = 0; d <  n - c - 1; d++)
        {
            if (arry[d] > arry[d + 1])
            {

                temp = arry[d];
                arry[d] = arry[d + 1];
                arry[d + 1] = arry[d - 1];
            }
        }
    }
}

Question Number 109

C preprocessor is conceptually the first step during compilation.

Question Number 110

Give the output of the following code snippet :
void main()
{
#define const float
    const float val = 100.25;
    printf("%.2f", val);
}

Question Number 111

The following program is used to add two distances ( inch to feet ) using structures. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?

{
    int feet;
    float inch;
};
struct Distance dist1, dist2, sum;

void main()
{
    printf("Enter information for 1st distance\n");
    printf("Enter feet: ");
    scanf("%d", &dist1.feet);
    printf("Enter inch: ");
    scanf("%f", &dist1.inch);
    printf("\nEnter information for 2nd distance\n");
    printf("Enter feet: ");
    scanf("%d", &dist2.feet);
    printf("Enter inch: ");
    scanf("%f", &dist2.inch);
    sum.feet = dist1.feet + dist2.feet;
    sum.inch = dist1.inch + dist2.inch;

    if (sum.inch>12.0)
    {
        sum.inch = sum.inch - 12.0;
        ++sum.feet;
    }
    printf("\nSum of distances=%d\'-%.1f\"", sum.feet, sum.inch);
}

Question Number 112

The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    FILE *fs1, *fs2, *ft;
    char ch;
    if (fs1 == NULL || fs2 == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }


    fs1 = fopen("File1.txt", "r");
    fs2 = fopen("File2.txt", "r");

    ft = fopen("Final.txt", "w");

    if (ft == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(fs1)) != EOF)
        fputc(ch, ft);

    while ((ch = fgetc(fs2)) != EOF)
        fputc(ch, ft);

    printf("Two files have been merged successfully");

    fclose(fs1);
    fclose(fs2);
    fclose(ft);

    return 0;
}

Question Number 113

Give the output of the following code snippet :
void main()
{
    long int x=258L;
    int y=10;
    long int z;
    z=x % y;

    printf("%d",z);
}

Question Number 114

The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);

int main()
{
    char str[100], dest[100];

    printf("Input a string\n");
    scanf("%s",str);

    copy_str(dest, str);

    printf("Source string:      %s\n", str);
    printf("Destination string: %s\n", dest);

    return 0;
}

void copy_str(char d[], char s[])
{
    int count = 0;

    while (s[count] != '\0')
    {
        d = s;
        count++;
    }
    d[count] = '\0';
}

Question Number 115

The following program is used to find the substring in a string without using string function. Which of the following statement(s) given in the choices should corrected to make the program compile, link and run and give the desired output?
int main()
{
    char str[100], sub[100];
    int position, length, count = 0;

    printf("Input a string  : \n");
    scanf("%s",str);

    printf("Enter the position and length of substring\n");
    scanf("%d%d", &position, &length);

    if (count <  length)
    {
        sub[count] = str[position + count - 1];
        count++;
    }
    sub[count] = '\0';

    printf("Required substring is %s\n", sub);

    return 0;
}

Question Number 116

The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);

int main()
{
    int arry1[100], arry2[100], num1, num2, c, result[200];

    printf("Input number of elements in first array\n");
    scanf("%d", &num1);

    printf("Input %d integers\n", num1);
    for (c = 0; c <  num1; c++)
    {
        scanf("%d", &arry1[c]);
    }

    printf("Input number of elements in second array\n");
    scanf("%d", &num2);

    printf("Input %d integers\n", num2);
    for (c = 0; c <  num2; c++)
    {
        scanf("%d", &arry2[c]);
    }

    MergeArrays(arry1, num1, arry2, num2, result);

    printf("Result array:\n");

    for (c = 0; c <  num1 + num2; c++)
    {
        printf("%d\n", result[c]);
    }
    return 0;
}

void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
    int i, j, k;
    j = k = 0;

    if (arry1[j] <  arry2[k])
    {
        result[i] = arry1[j];
        j++;
    }
    else
    {
        result[i] = arry2[k];
        k++;
    }
    i++;
}

else if (j == num1)
{
    for (; i <  num1 + num2;)
    {
        result[i] = arry2[k];
        k++;
        i++;
    }
}

else
{
    for (; i <  num1 + num2;)
    {
        result[i] = arry1[j];
        j++;
        i++;
    }
}
}
}

Question Number 117

The following program is used to add two distances ( inch to feet ) using structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
struct Distance
{
    int feet;
    float inch;
} dist1, dist2, sum;

void main()
{
    printf("Enter information for 1st distance\n");
    printf("Enter feet: ");
    scanf("%d", &dist1.feet);
    printf("Enter inch: ");
    scanf("%f", &dist1.inch);
    printf("\nEnter information for 2nd distance\n");
    printf("Enter feet: ");
    scanf("%d", &dist2.feet);
    printf("Enter inch: ");
    scanf("%f", &dist2.inch);
    sum.feet = dist1.feet + dist2.feet;
    sum.inch = dist1.inch + dist2.inch;

    if (sum.inch>12.0)
    {
        sum.inch = sum.inch - 12.0;
        ++sum.feet;
    }
    printf("\nSum of distances=%d\'-%.1f\"", sum.feet, sum.inch);
}

Question Number 118

The following program is used to add two distances ( inch to feet ) using structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
struct Distance
{
    int feet;
    float inch;
};
struct Distance dist1, dist2, sum;

void main()
{
    printf("Enter information for 1st distance\n");
    printf("Enter feet: ");
    scanf("%d", &dist1.feet);
    printf("Enter inch: ");
    scanf("%f", &dist1.inch);
    printf("\nEnter information for 2nd distance\n");
    printf("Enter feet: ");
    scanf("%d", &dist2.feet);
    printf("Enter inch: ");
    scanf("%f", &dist2.inch);
    sum = dist1.feet + dist2.feet;
    sum = dist1.inch + dist2.inch;

    if (sum.inch>12.0)
    {
        sum.inch = sum.inch - 12.0;
        ++sum.feet;
    }
    printf("\nSum of distances=%d\'-%.1f\"", sum.feet, sum.inch);
}

Question Number 119

The following program is used to swap two values. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
    int value1, value2, temp;

    printf("\nEnter the value of value1 : ");
    scanf("%d", &value1);
    printf("\nEnter the value of value2 : ");
    scanf("%d", &value2);

    printf("Before Swapping\nvalue1 = %d\nvalue2 = %d\n", value1, value2);

    value2 = temp;

    printf("After Swapping\nvalue1 = %d\nvalue2 = %d\n", value1, value2);

    return 0;
}

Question Number 120

The following program is used to concatenate two strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void str_cat(char[], char[]);

int main()
{
    char str1[100], str2[100];

    printf("Input a string : \n");
    scanf("%s", str1);

    printf("Input string to concatenate : \n");
    scanf("%s", str2);

    str_cat(str1, str2);

    printf("String obtained on concatenation : %s \n", str1);

    return 0;
}

void str_cat(char str1[], char str2[])
{
    int count = 0, d = 0;

    while (str1[count] != '\0')
    {
        count++;
    }
    if (str2[d] == '\0')
    {
        str1[count] = str2[d];
        d++;
        count++;
    }

    str1[count] = '\0';
}

Question Number 121

Which of the following sequences are not valid in C language?

Question Number 122

The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);

int main()
{
    int arry1[100], arry2[100], num1, num2, c, result[200];

    printf("Input number of elements in first array\n");
    scanf("%d", &num1);

    printf("Input %d integers\n", num1);
    for (c = 0; c <  num1; c++)
    {
        scanf("%d", &arry1[c]);
    }

    printf("Input number of elements in second array\n");
    scanf("%d", &num2);

    printf("Input %d integers\n", num2);
    for (c = 0; c <  num2; c++)
    {
        scanf("%d", &arry2[c]);
    }

    MergeArrays(arry1, num1, arry2, num2, result);

    printf("Result array:\n");

    for (c = 0; c <  num1 + num2; c++)
    {
        printf("%d\n", result[c]);
    }
    return 0;
}

void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
    int i, j, k;
    j = k = 0;

    for (i = 0; i <  num1 + num2;)
    {
        if (j <  num1 && k <  num2)
        {

            if (arry1[j] <  arry2[k])
            {
                result[i] = arry1[j];
                j++;
            }
            else
            {
                result[i] = arry2[k];
                k++;
            }
            i++;
        }

        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry2[k];
                k++;
                i++;
            }
        }

        else
        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry1[j];
                j++;
                i++;
            }
        }
    }
}

Question Number 123

Give the output of the following code snippet :

#define A B + 2
#define B C + 4
#define C A + 5
int main()
{
    int var = A * B - C;
    printf("%d\n", var);
}

Question Number 124

Which of the following data types do not fall under the integral types classification in C?

Question Number 125

The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);

int main()
{
    int arry1[100], arry2[100], num1, num2, c, result[200];

    printf("Input number of elements in first array\n");
    scanf("%d", &num1);

    printf("Input %d integers\n", num1);
    for (c = 0; c <  num1; c++)
    {
        scanf("%d", &arry1[c]);
    }

    printf("Input number of elements in second array\n");
    scanf("%d", &num2);

    printf("Input %d integers\n", num2);
    for (c = 0; c <  num2; c++)
    {
        scanf("%d", &arry2[c]);
    }

    MergeArrays(arry1, num1, arry2, num2, result);

    printf("Result array:\n");

    for (c = 0; c <  num1 + num2; c++)
    {
        printf("%d\n", result[c]);
    }
    return 0;
}

void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
    int i, j, k;
    j = k = 0;

    for (i = 0; i <  num1 - num2; i++)
    {
        if (j <  num1 && k <  num2)
        {

            if (arry1[j] <  arry2[k])
            {
                result[i] = arry1[j];
                j++;
            }
            else
            {
                result[i] = arry2[k];
                k++;
            }
            i++;
        }

        else if (j == num1)
        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry2[k];
                k++;
                i++;
            }
        }

        else
        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry1[j];
                j++;
                i++;
            }
        }
    }
}

Question Number 126

The following program is used to generate the palindrome of a number. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
    int value,num, reverse = 0;

    printf("Enter a number to reverse : ");
    scanf("%d", &value);

    num = value;

    while (num != 0)
    {
        reverse = reverse * 10;
        reverse = reverse + num % 10;
        num = num / 10;
    }

    if (value == num)
        printf(" %d is a Palindrome",value);
    else
        printf(" %d is not a Palindrome", value);

    return 0;
}

Question Number 127

Give the output of the following code snippet :
#define SQR(x)(x*x)

int main()
{
    int a, b=3;
    a = SQR(b+2);
    printf("%d\n", a);
    return 0;
}

Question Number 128

Which of the following data types fall under the integral types classification in C?

Question Number 129

The following program is used to generate the palindrome of a number. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
    int value,num, reverse = 0;

    printf("Enter a number to reverse : ");
    scanf("%d", &value);

    num = value;

    while (num != 0)
    {
        reverse = reverse * 10;
        reverse = reverse + num % 10;
    }

    if (value == reverse)
        printf(" %d is a Palindrome",value);
    else
        printf(" %d is not a Palindrome", value);

    return 0;
}

Question Number 130

Give the output of the following code snippet :
#define MAX(x,y) (x)>(y)?(x):(y)

int main()
{

    int i=10,j=9,k=0;

    k=MAX(i++,++j);

    printf("%d %d %d",i,j,k);

    return 0;
}

Question Number 131

Give the output of the following code snippet :
#define CUBE(X) X*X*X
void main()
{
    printf("%d  ", CUBE(3));
    printf("%d", CUBE(2+3));
}

Question Number 132

The following program is used to find the maximum value in an array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
    int array[100], maximum, size, count, location = 1;

    printf("\nEnter the number of elements in array : ");
    scanf("%d", &size);

    printf("Enter %d integers : ", size);

    maximum = array[0];

    for (count = 1; count <  size; count++)
    {
        if (array[count] > maximum)
        {
            maximum = array[count];
            location = count + 1;
        }
    }

    printf("Maximum element is present at location %d and its value is %d.\n", location, maximum);
    return 0;
}

Question Number 133

Which of the following are types of C constants ?

Question Number 134

The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int str_compare(char[], char[]);

int main()
{
    int flag;
    char str1[100], str2[100];

    printf("Input first string\n");
    scanf("%s", str1);

    printf("Input second string\n");
    scanf("%s", str2);

    flag = str_compare(str1, str2);

    if (flag == 0)
        printf("Entered strings are equal.\n");
    else
        printf("Entered strings are not equal.\n");

    return 0;

}

int str_compare(char a[], char b[])
{
    int count = 0;

    while (a[count] == b[count])
    {
        break;
        count++;
    }

    if (a[count] == '\0' && b[count] == '\0')
        return 0;
    else
        return -1;
}

Question Number 135

Give the output of the following code snippet :
int main()
{
    const int a;
    a=10;
    printf("%d\n",a);
    return 0;
}

Question Number 136

Give the output of the following code snippet :
void main()
{

    printf("%.*f", 2, 98.736);

}

Question Number 137

The group of statements in a C program are enclosed within what type of brackets?

Question Number 138

Give the output of the following code snippet :
#define A 4-2

#define B 3-1

int main()
{

    int ratio=A/B;

    printf("%d ",ratio);

    return 0;
}

Question Number 139

The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);

int main()
{
    char str[100], dest[100];

    printf("Input a string\n");
    scanf("%s",str);

    copy_str(dest, str);

    printf("Source string:      %s\n", str);
    printf("Destination string: %s\n", dest);

    return 0;
}

void copy_str(char d[], char s[])
{
    int count = s[0];

    while (s[count] != '\0')
    {
        d[count] = s[count];
        count++;
    }
    d[count] = '\0';
}

Question Number 140

Give the output of the following code snippet :
#define var 20);
int main()
{
    printf("%d\n", var
}

Question Number 141

Which of the following are types of C constants ?

Question Number 142

The following program is used to find the substring in a string without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int main()
{
    char str[100], sub[100];
    int position, length, count = 0;

    printf("Input a string  : \n");
    scanf("%s",str);

    printf("Enter the position and length of substring\n");
    scanf("%d%d", &position, &length);

    while (count <  length)
    {
        sub[count] = str[position + count - 1];
        count++;
    }
    sub[count] = '\0';

    printf("Required substring is %s\n", sub);

    return 0;
}

Question Number 143

The following program is used to copy a file. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    char ch;
    FILE *source, *target;
    ch = fopen("CopyFile.txt");

    if (source == NULL)
    {
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    target = fopen("Destination.txt", "w");

    if (target == NULL)
    {
        fclose(source);
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(source)) != EOF)
        fputc(ch, target);

    printf("File copied successfully.\n");

    fclose(source);
    fclose(target);

    return 0;
}

Question Number 144

Which of the following are examples of derived data types?

Question Number 145

The following program is used to find the maximum value in an array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
    int array[100], maximum, size, count, location = 1;

    printf("\nEnter the number of elements in array : ");
    scanf("%d", &size);

    printf("Enter %d integers : ", size);

    for (count = 0; count <  size; count++)
        scanf("\n%d", &array[count]);

    for (count = 1; count <  size; count++)
    {
        if (array[count] > maximum)
        {
            maximum = array[count];
            location = count + 1;
        }
    }

    printf("Maximum element is present at location %d and its value is %d.\n", location, maximum);
    return 0;
}

Question Number 146

The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    FILE *fs1, *fs2, *ft;
    char ch;

    fs1 = fopen("File1.txt", "r");
    fs2 = fopen("File2.txt", "r");

    if (fs1 == NULL || fs2 == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    ft = fopen("Final.txt", "w");

    if (ft == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(fs1)) != EOF)
        fputc(ch, ft);

    while ((ch = fopen(ft)) != EOF)
        fputc(ch, ft);

    printf("Two files have been merged successfully");

    fclose(fs1);
    fclose(fs2);
    fclose(ft);

    return 0;
}

Question Number 147

The following program is used to swap two strings. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
int main()
{
    char str1[100], str2[100], temp[50];

    printf("Enter the str1 string\n");
    scanf("%s", str1);

    printf("Enter the str2 string\n");
    scanf("%s", str2);

    printf("\nBefore Swapping\n");
    printf("First string: %s\n", str1);
    printf("Second string: %s\n\n", str2);
    strcpy(str1, str2);
    strcpy(temp, str1);
    strcpy(str2, temp);

    printf("After Swapping\n");
    printf("First string: %s\n", str1);
    printf("Second string: %s\n", str2);

    return 0;
}

Question Number 148

Give the output of the following code snippet :
void main()
{
    int k = 8;
    int m = 7;
    int z = k <  m ? k++ : m++;
    printf("%d", z);
}

Question Number 149

The following program is used to find the factorial of a number. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int n, count;
    int fact = -1;
    printf("Enter a value: ");
    scanf("%d", &n);
    if (n<  0)
        printf("Factorial of negative number does not exist");
    else
    {
        for (count = 1; count < = n; ++count)
        {
            fact = fact * count;
        }
        printf("Factorial of %d is %d ",n,fact);
    }
    return 0;
}

Question Number 150

The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?


#include < stdio.h>

int main()
{
    int count, n, num1 = 0, num2 = 1, result = 0;
    printf("Enter number of terms: ");
    scanf("%d", &n);
    printf("Fibonacci Series:\n %d  %d  ", num1, num2);
    count = 2;
    while (count< n)
    {
        result = num1 + num2;
        ++count;
        printf("%d ", result);
    }
    return 0;
}

Question Number 151

The following program is used to add two distances ( inch to feet ) using structures. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Distance
{
    int feet;
    float inch;
};
struct Distance dist1, dist2, sum;

void main()
{
    printf("Enter information for 1st distance\n");
    printf("Enter feet: ");
    scanf("%d", &dist1.feet);
    printf("Enter inch: ");
    scanf("%f", &dist1.inch);
    printf("\nEnter information for 2nd distance\n");
    printf("Enter feet: ");
    scanf("%d", &dist2.feet);
    printf("Enter inch: ");
    scanf("%f", &dist2.inch);
    sum.inch = dist1.inch + dist2.inch;

    if (sum.inch>12.0)
    {
        sum.inch = sum.inch - 12.0;
        ++sum.feet;
    }
    printf("\nSum of distances=%d\'-%.1f\"", sum.feet, sum.inch);
}

Question Number 152

The following program is used to concatenate two strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void str_cat(char[], char[]);

int main()
{
    char str1[100], str2[100];

    printf("Input a string : \n");
    scanf("%s", str1);

    printf("Input string to concatenate : \n");
    scanf("%s", str2);

    str_cat(str1, str2);

    printf("String obtained on concatenation : %s \n", str1);

    return 0;
}

void str_cat(char str1[], char str2[])
{
    int count = 0, d = 0;

    while (str1[count] == str2[count])
    {
        count++;
    }
    while (str2[d] != '\0')
    {
        str1[count] = str2[d];
        d++;
        count++;
    }

    str1[count] = '\0';
}

Question Number 153

The following program is used to concatenate two strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void str_cat(char[], char[]);

int main()
{
    char str1[100], str2[100];

    printf("Input a string : \n");
    scanf("%s", str1);

    printf("Input string to concatenate : \n");
    scanf("%s", str2);

    printf("String obtained on concatenation : %s \n", str1);

    return 0;
}

void str_cat(char str1[], char str2[])
{
    int count = 0, d = 0;

    while (str1[count] != '\0')
    {
        count++;
    }
    while (str2[d] != '\0')
    {
        str1[count] = str2[d];
        d++;
        count++;
    }

    str1[count] = '\0';
}

Question Number 154

The following program is used to copy a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    char ch;
    source = fopen("CopyFile.txt", "r");

    if (source == NULL)
    {
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    target = fopen("Destination.txt", "w");

    if (target == NULL)
    {
        fclose(source);
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(source)) != EOF)
        fputc(ch, target);

    printf("File copied successfully.\n");

    fclose(source);
    fclose(target);

    return 0;
}

Question Number 155

The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);

int main()
{
    char str[100], dest[100];

    printf("Input a string\n");
    scanf("%s",str);

    copy_str(dest, str);

    printf("Source string:      %s\n", str);
    printf("Destination string: %s\n", dest);

    return 0;
}

void copy_str()
{
    int count = 0;

    while (s[count] != '\0')
    {
        d[count] = s[count];
        count++;
    }
    d[count] = '\0';
}

Question Number 156

Give the output of the following code snippet :
void fun();
int main()
{
#define max 10
    fun();
    return 0;
}
void fun()
{
    printf("%d\n", max * 10);
}

Question Number 157

The following program is used to copy a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    char ch;
    FILE *source, *target;

    if (source == NULL)
    {
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    target = fopen("Destination.txt", "w");

    if (target == NULL)
    {
        fclose(source);
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(source)) != EOF)
        fputc(ch, target);

    printf("File copied successfully.\n");

    fclose(source);
    fclose(target);

    return 0;
}

Question Number 158

Give the output of the following code snippet :
int func(float y);
void main()
{
    int b=func(10.5);
    printf("%d",b);
}
int func(float x)
{
    float a=200.25;
    return (a);
}

Question Number 159

Give the output of the following code snippet :
void main()
{
#define const float
    const val = 100.25;
    printf("%.2f", val);
}

Question Number 160

The following program is used to sort an array of values using Bubble sort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void bubble_sort(int arry[], int n);
int main()
{
    int array[100], n, c;

    printf("Enter number of elements\n");
    scanf("%d", &n);

    printf("Enter %d integers\n", n);

    for (c = 0; c <  n; c++)
        scanf("%d", &array[c]);

    bubble_sort(array, n);

    printf("Sorted array in ascending order:\n");

    for (c = 0; c <  n; c++)
        printf("%d\n", array[c]);

    return 0;
}

void bubble_sort(int arry[], int n)
{
    int c, d, temp;

    for (c = 0; c <  (n - 1); c++)
    {
        for (d = 0; d <  n - c - 1; d++)
        {
            if (arry[d] > arry[d + 1])
            {

                temp = arry[d];
                arry[d + 1] = temp;
            }
        }
    }
}

Question Number 161

The following program is used to copy a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    char ch;
    FILE *source, *target;
    source = fopen("CopyFile.txt", "r");

    if (source == NULL)
    {
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    target = fopen("Destination.txt", "w");

    if (target == NULL)
    {
        fclose(source);
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    fputc(ch, target);

    printf("File copied successfully.\n");

    fclose(source);
    fclose(target);

    return 0;
}

Question Number 162

The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?


#include < stdio.h>

int main()
{
    int count, n, num1 = 0, num2 = 1, result = 0;
    printf("Enter number of terms: ");
    scanf("%d", &n);
    printf("Fibonacci Series:\n %d  %d  ", num1, num2);
    count = 2;
    while (count< n)
    {
        result = num1 + num2;
        num1 = num2;
        num2 = result;
        ++count;
        printf("%d ", result);
    }
    return 0;
}

Question Number 163

The following program is used to copy a file. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    char ch;
    FILE *source, *target;
    source = fopen("CopyFile.txt", "r");
    fclose(source);

    if (source == NULL)
    {
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    target = fopen("Destination.txt", "w");

    if (target == NULL)
    {
        fclose(source);
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(source)) != EOF)
        fputc(ch, target);

    printf("File copied successfully.\n");

    fclose(target);

    return 0;
}

Question Number 164

The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);

int main()
{
    int arry1[100], arry2[100], num1, num2, c, result[200];

    printf("Input number of elements in first array\n");
    scanf("%d", &num1);

    printf("Input %d integers\n", num1);
    for (c = 0; c <  num1; c++)
    {
        scanf("%d", &arry1[c]);
    }

    printf("Input number of elements in second array\n");
    scanf("%d", &num2);

    printf("Input %d integers\n", num2);
    for (c = 0; c <  num2; c++)
    {
        scanf("%d", &arry2[c]);
    }

    MergeArrays(arry1, num1, arry2, num2, result);

    printf("Result array:\n");

    for (c = 0; c <  num1 + num2; c++)
    {
        printf("%d\n", result[c]);
    }
    return 0;
}

void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
    int i, j, k;
    j = k = 0;

    for (i = 0; i <  num1 / num2; i++)
    {
        if (j <  num1 && k <  num2)
        {

            if (arry1[j] <  arry2[k])
            {
                result[i] = arry1[j];
                j++;
            }
            else
            {
                result[i] = arry2[k];
                k++;
            }
            i++;
        }

        else if (j == num1)
        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry2[k];
                k++;
                i++;
            }
        }

        else
        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry1[j];
                j++;
                i++;
            }
        }
    }
}

Question Number 165

Give the output of the following code snippet :
int a;
int main()
{

    printf("%d\n",a);
    return 0;
}

Question Number 166

The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    FILE *fs1, *fs2, *ft;
    char ch;

    fs1 = fopen("File1.txt", "r");
    fs2 = fopen("File2.txt", "r");

    if (fs1 == NULL || fs2 == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    ft = fopen("Final.txt", "w");

    if (ft == 0)
    {
        perror("Error ");
        break;
    }

    while ((ch = fgetc(fs1)) != EOF)
        fputc(ch, ft);

    while ((ch = fgetc(fs2)) != EOF)
        fputc(ch, ft);

    printf("Two files have been merged successfully");

    fclose(fs1);
    fclose(fs2);
    fclose(ft);

    return 0;
}

Question Number 167

Which of the following statements are true about macros in C?

Question Number 168

The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int a, b, x, y, temp, gcd, lcm;

    printf("Enter two values : \n");
    scanf("%d%d", &x, &y);

    a = x;
    b = y;

    while (b != 0)
    {
        temp = b;
        a = temp;
    }

    gcd = a;
    lcm = (x*y) / gcd;

    printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
    printf("Least common multiple of %d and %d = %d\n", x, y, lcm);

    return 0;
}

Question Number 169

The following program is used to find length of a string without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int string_length(char[]);

int main()
{
    char str[100];
    int length;

    printf("Input a string\n");
    scanf("%s", str);
    length = string_length(str);
    printf("Length of string %s = %d\n", str, length);

    return 0;
}

int string_length(char s[])
{
    int count = 0;

    while (s[count] != '\0')
        count++;

    return count;
}

Question Number 170

What is the escape sequence in C to add a backspace?

Question Number 171

The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);

int main()
{
    int arry1[100], arry2[100], num1, num2, c, result[200];

    printf("Input number of elements in first array\n");
    scanf("%d", &num1);

    printf("Input %d integers\n", num1);
    for (c = 0; c <  num1; c++)
    {
        scanf("%d", &arry1[c]);
    }

    printf("Input number of elements in second array\n");
    scanf("%d", &num2);

    printf("Input %d integers\n", num2);
    for (c = 0; c <  num2; c++)
    {
        scanf("%d", &arry2[c]);
    }

    MergeArrays(arry1, num1, arry2, num2, result);

    printf("Result array:\n");

    for (c = 0; c <  num1 + num2; c++)
    {
        printf("%d\n", result[c]);
    }
    return 0;
}

void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
    int i, j, k;
    j = k = 0;

    for (i = 0; i <  num1 + num2;)
    {
        if (j == num1 && k == num2)
        {

            if (arry1[j] <  arry2[k])
            {
                result[i] = arry1[j];
                j++;
            }
            else
            {
                result[i] = arry2[k];
                k++;
            }
            i++;
        }

        else if (j == num1)
        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry2[k];
                k++;
                i++;
            }
        }

        else
        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry1[j];
                j++;
                i++;
            }
        }
    }
}

Question Number 172

The following program is used to sort an array of structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>

struct student
{
    char name[50];
    int studId;
    int marks;
};

int main()
{
    struct student stud[10],temp;
    int i, num;
    printf("Enter number of students : \n");
    scanf("%d", &num);
    printf("Enter information of students:\n");
    for (i = 0; i<  num; ++i)
    {
        printf("Enter student ID: ");
        scanf("%d", &stud[i].studId);
        printf("Enter name: ");
        scanf("%s", stud[i].name);
        printf("Enter marks: ");
        scanf("%d", &stud[i].marks);
        printf("\n");
    }

    for (i = 0; i <  num; i++)
        for (int j = 0; j <  i; j++)
            if (stud[i].studId <  stud[j].studId)
            {
                temp[i] = stud[i];
                stud[i] = stud[j];
                stud[j] = temp;
            }

    printf("Student Information :\n\n");
    for (i = 0; i<  num; ++i)
    {
        printf("\nStudent ID %d:\n",stud[i].studId);
        printf("Name: %s", stud[i].name);
        printf("Marks: %d", stud[i].marks);
    }
    return 0;
}

Question Number 173

The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?

int main()
{
    int flag;
    char str1[100], str2[100];

    printf("Input first string\n");
    scanf("%s", str1);

    printf("Input second string\n");
    scanf("%s", str2);

    flag = str_compare(str1, str2);

    if (flag == 0)
        printf("Entered strings are equal.\n");
    else
        printf("Entered strings are not equal.\n");

    return 0;

}

int str_compare(char a[], char b[])
{
    int count = 0;

    while (a[count] == b[count])
    {
        if (a[count] == '\0' || b[count] == '\0')
            break;
        count++;
    }

    if (a[count] == '\0' && b[count] == '\0')
        return 0;
    else
        return -1;
}

Question Number 174

The following program is used to generate the palindrome of a number. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>
int main()
{
    int value,num, reverse = 0;

    printf("Enter a number to reverse : ");
    scanf("%d", &value);

    while (num != 0)
    {
        reverse = reverse * 10;
        reverse = reverse + num % 10;
        num = num / 10;
    }

    if (value == reverse)
        printf(" %d is a Palindrome",value);
    else
        printf(" %d is not a Palindrome", value);

    return 0;
}

Question Number 175

Which of the following data types fall under the floating types classification in C?

Question Number 176

The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    FILE *fs1, *fs2, *ft;
    char ch;

    fs1 = fclose("File1.txt", "r");
    fs2 = fopen("File2.txt", "r");

    if (fs1 == NULL || fs2 == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    ft = fopen("Final.txt", "w");

    if (ft == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(fs1)) != EOF)
        fputc(ch, ft);

    while ((ch = fgetc(fs2)) != EOF)
        fputc(ch, ft);

    printf("Two files have been merged successfully");

    fclose(fs1);
    fclose(fs2);
    fclose(ft);

    return 0;
}

Question Number 177

The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?


#include < stdio.h>

int main()
{
    int count, n, num1 = 0, num2 = 1, result = 0;
    printf("Enter number of terms: ");
    scanf("%d", &n);
    printf("Fibonacci Series:\n %d  %d  ", num1, num2);
    count = 2;
    while (count< n)
    {
        result = num1 + num2;
        num1 = num2;
        num2 = result;
        printf("%d ", result);
    }
    ++count;
    return 0;
}

Question Number 178

Binary operators % and + have what priority ?

Question Number 179

Give the output of the following code snippet :
# define max

void main()
{
    max;

}

Question Number 180

The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    FILE *fs1, *fs2, *ft;
    char ch;

    fs1 = fopen("File1.txt", "r");
    fs2 = fopen("File2.txt", "r");

    if (fs1 == NULL || fs2 == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    ft = fopen("Final.txt", "w");

    if (ft == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(fs1)) != EOF)
        fputc(ch, ft);

    if ((ch = fgetc(fs2)) != -1)
        fputc(ch, ft);

    printf("Two files have been merged successfully");

    fclose(fs1);
    fclose(fs2);
    fclose(ft);

    return 0;
}

Question Number 181

The following program is used to reverse a string. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>
#include < strlen.h>

int main()
{
    char str[100], reverse[100];
    int strlength, count, d;

    printf("Input a string\n");
    scanf("%s",str);
    strlength = strlen(str);

    for (count = strlength - 1, d = 0; count >= 0; count--, d++)
        reverse[d] = str[count];

    reverse[d] = '\0';
    printf("%s\n", reverse);
    return 0;
}

Question Number 182

Give the output of the following code snippet :
#define X (4+Y)
#define Y (X+3)

int main()
{
    printf("%d\n", 4*X+2);
    return 0;
}

Question Number 183

The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
int str_compare(char[], char[]);

int main()
{
    int flag;
    char str1[100], str2[100];

    printf("Input first string\n");
    scanf("%s", str1);

    printf("Input second string\n");
    scanf("%s", str2);


    if (flag == 0)
        printf("Entered strings are equal.\n");
    else
        printf("Entered strings are not equal.\n");

    flag = str_compare(str1, str2);
    return 0;

}

int str_compare(char a[], char b[])
{
    int count = 0;

    while (a[count] == b[count])
    {
        if (a[count] == '\0' || b[count] == '\0')
            break;
        count++;
    }

    if (a[count] == '\0' && b[count] == '\0')
        return 0;
    else
        return -1;
}

Question Number 184

Give the output of the following code snippet :
int main()
{
#ifdef Hello
    printf("Hello\t");
#else
    printf("World\t");
#endif
}

Question Number 185

The following program is used to reverse a string. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#include < stdio.h>
#include < string.h>

int main()
{
    char str[100], reverse[100];
    int strlength, count, d;

    printf("Input a string\n");
    scanf("%s",str);
    strlength = strlen(str);
    reverse[d] = '\0';

    for (count = strlength - 1, d = 0; count >= 0; count--, d++)
        reverse[d] = str[count];

    printf("%s\n", reverse);
    return 0;
}

Question Number 186

Give the output of the following code snippet :
#define GT >
#define LT <
#define AND &&
#define OR ||
void main()
{
    int x=100,y=200,z=300;
    if(((x + y GT z) == 0) OR ((x +y LT z) ==0))
        printf("%d",x+y+z);
    else
        printf("%d",z-y-x);
}

Question Number 187

The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    FILE *fs1, *fs2, *ft;
    char ch;

    if (fs1 == NULL || fs2 == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    ft = fopen("Final.txt", "w");

    if (ft == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(fs1)) != EOF)
        fputc(ch, ft);

    while ((ch = fgetc(fs2)) != EOF)
        fputc(ch, ft);

    printf("Two files have been merged successfully");

    fclose(fs1);
    fclose(fs2);
    fclose(ft);

    return 0;
}

Question Number 188

The following program is used to copy a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    char ch;
    FILE *source, *target;
    source = fopen("CopyFile.txt", "r");

    if (source == NULL)
    {
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    target = fopen("Destination.txt", "w");

    if (target == NULL)
    {
        fclose(source);
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(source)) != EOF)
        fputc(ch, target);

    printf("File copied successfully.\n");


    return 0;
}

Question Number 189

Give the output of the following code snippet :
#if -2+5-6/2
int main()
{
    printf("Hello");
    return 0;
}
#else
int main()
{
    printf("World");
    return 0;
}
#endif

Question Number 190

The following program is used to add two distances ( inch to feet ) using structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
struct Distance
{
    int feet;
    float inch;
};
Distance dist1, dist2, sum;

void main()
{
    printf("Enter information for 1st distance\n");
    printf("Enter feet: ");
    scanf("%d", &dist1.feet);
    printf("Enter inch: ");
    scanf("%f", &dist1.inch);
    printf("\nEnter information for 2nd distance\n");
    printf("Enter feet: ");
    scanf("%d", &dist2.feet);
    printf("Enter inch: ");
    scanf("%f", &dist2.inch);
    sum.feet = dist1.feet + dist2.feet;
    sum.inch = dist1.inch + dist2.inch;

    if (sum.inch>12.0)
    {
        sum.inch = sum.inch - 12.0;
        ++sum.feet;
    }
    printf("\nSum of distances=%d\'-%.1f\"", sum.feet, sum.inch);
}

Question Number 191

Give the output of the following code snippet :
#define Hello
int main()
{
#ifdef Hello
    printf("Hello\t");
#undef Hello
#endif
#ifdef Hello
    printf("World\t");
#endif
}

Question Number 192

The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int str_compare(char[], char[]);

int main()
{
    int flag;
    char str1[100], str2[100];

    printf("Input first string\n");
    scanf("%s", str1);

    printf("Input second string\n");
    scanf("%s", str2);

    flag = str_compare(str1, str2);

    if (flag == 0)
        printf("Entered strings are equal.\n");
    else
        printf("Entered strings are not equal.\n");

    return 0;

}

int str_compare(char a[], char b[])
{
    int count = 0;

    while (a[count] == b[count])
    {
        if (a[count] == '\0' || b[count] == '\0')
            break;
        count++;
    }
    return -1;
}

Question Number 193

Give the output of the following code snippet :
int main()
{
    int a = 10, b = 5, c = 3;
    b += !a;
    c = !!a;
    printf("%d\t%d", b, c);
}

Question Number 194

The following program is used to concatenate two strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void str_cat(char[], char[]);

int main()
{
    char str1[100], str2[100];

    printf("Input a string : \n");
    scanf("%s", str1);

    printf("Input string to concatenate : \n");
    scanf("%s", str2);

    str_cat(int,int);

    printf("String obtained on concatenation : %s \n", str1);

    return 0;
}

void str_cat(char str1[], char str2[])
{
    int count = 0, d = 0;

    while (str1[count] != '\0')
    {
        count++;
    }
    while (str2[d] != '\0')
    {
        str1[count] = str2[d];
        d++;
        count++;
    }

    str1[count] = '\0';
}

Question Number 195

Give the output of the following code snippet :
#define A 1 + 2
#define B 3 + 4
int main()
{
    int var = A * B;
    printf("%d\n", var);
}

Question Number 196

Which of the following functions are declared in the header file math.h?

Question Number 197

Give the output of the following code snippet :
int main()
{
    int i = -3;
    int k = i % 2;
    printf("%d\n", k);
}

Question Number 198

The following program is used to add two complex numbers by passing structure to a function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct complex
{
    float real;
    float imag;
};
struct complex Add(struct complex n1, struct complex n2);
int main()
{
    struct complex n1, n2, temp;
    printf("For first complex number : \n");
    printf("Enter real part :\n");
    scanf("%f", &n1.real);
    printf("Enter imaginary part :\n");
    scanf("%f", &n1.imag);
    printf("For second complex number : \n");
    printf("Enter real part :\n");
    scanf("%f", &n2.real);
    printf("Enter imaginary part :\n");
    scanf("%f", &n2.imag);
    temp = Add(n1, n2);
    printf("Sum=%.1f+%.1fi", temp.real, temp.imag);
    return 0;
}
struct complex Add(struct complex n1, struct complex n2)
{
    struct complex temp;
    temp.real = n1.real + n2.real;
    temp.imag = n1.imag + n2.imag;
    return(temp);
}

Question Number 199

Which of the following statements is true about the feof() function in C?

Question Number 200

The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    FILE *fs1, *fs2, *ft;
    char ch;

    if (fs1 == NULL || fs2 == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    ft = fopen("Final.txt", "w");

    if (ft == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(fs1)) != EOF)
        fputc(ch, ft);

    while ((ch = fgetc(fs2)) != EOF)
        fputc(ch, ft);

    printf("Two files have been merged successfully");

    fclose(fs1);
    fclose(fs2);
    fclose(ft);

    return 0;
}

Question Number 201

The following program is used to merge the contents of two files. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    FILE *fs1, *fs2, *ft;
    char ch;

    fs1 = fopen("File1.txt", "r");
    fs2 = fopen("File2.txt", "r");

    if (fs1 == NULL || fs2 == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    ft = fopen("Final.txt", "w");

    if (ft == NULL)
    {
        perror("Error ");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(fs1)) != EOF)
        fputc(ch, ft);

    while ((ch = fgetc(fs2)) != EOF)
        fclose( ft);

    printf("Two files have been merged successfully");

    fclose(fs1);
    fclose(fs2);
    fclose(ft);

    return 0;
}

Question Number 202

The preprocessor provides the ability for which of the following options?

Question Number 203

The following program is used to concatenate two strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void str_cat();

int main()
{
    char str1[100], str2[100];

    printf("Input a string : \n");
    scanf("%s", str1);

    printf("Input string to concatenate : \n");
    scanf("%s", str2);

    str_cat(str1, str2);

    printf("String obtained on concatenation : %s \n", str1);

    return 0;
}

void str_cat(char str1[], char str2[])
{
    int count = 0, d = 0;

    while (str1[count] != '\0')
    {
        count++;
    }
    while (str2[d] != '\0')
    {
        str1[count] = str2[d];
        d++;
        count++;
    }

    str1[count] = '\0';
}

Question Number 204

The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);

int main()
{
    int arry1[100], arry2[100], num1, num2, c, result[200];

    printf("Input number of elements in first array\n");
    scanf("%d", &num1);

    printf("Input %d integers\n", num1);
    for (c = 0; c <  num1; c++)
    {
        scanf("%d", &arry1[c]);
    }

    printf("Input number of elements in second array\n");
    scanf("%d", &num2);

    printf("Input %d integers\n", num2);
    for (c = 0; c <  num2; c++)
    {
        scanf("%d", &arry2[c]);
    }

    MergeArrays(arry1, num1, arry2, num2, result);

    printf("Result array:\n");

    for (c = 0; c <  num1 + num2; c++)
    {
        printf("%d\n", result[c]);
    }
    return 0;
}

void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
    int i, j, k;
    j = k = 0;

    for (i = 0; i <  num1 + num2;)
    {
        if (j <  num1 && k <  num2)
        {

            if (arry1[j] != arry2[k])
            {
                result[i] = arry1[j];
                j++;
            }
            else
            {
                result[i] = arry2[k];
                k++;
            }
            i++;
        }

        else if (j == num1)
        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry2[k];
                k++;
                i++;
            }
        }

        else
        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry1[j];
                j++;
                i++;
            }
        }
    }
}

Question Number 205

The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
int str_compare(char[], char[]);

int main()
{
    int flag;
    char str1[100], str2[100];

    printf("Input first string\n");
    scanf("%s", str1);

    printf("Input second string\n");
    scanf("%s", str2);

    flag = str_compare(str1, str2);

    if (flag == 0)
        printf("Entered strings are equal.\n");
    else
        printf("Entered strings are not equal.\n");

    return 0;

}

int str_compare(char a[], char b[])
{
    int count = 0;

    if (a[count] == b[count])
    {
        if (a[count] == '\0' || b[count] == '\0')
            break;
        count++;
    }

    if (a[count] == '\0' && b[count] == '\0')
        return 0;
    else
        return -1;
}

Question Number 206

Give the output of the following code snippet :
#define Hello

int main()
{
#ifdef Hello
    printf("Hello\t");
#else
    printf("World\t");
#endif
}

Question Number 207

The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
int str_compare(char[], char[]);

int main()
{
    int flag;
    char str1[100], str2[100];

    printf("Input first string\n");
    scanf("%s", str1);

    printf("Input second string\n");
    scanf("%s", str2);

    flag = str_compare(str1, str2);

    if (flag == 0)
        printf("Entered strings are equal.\n");
    else
        printf("Entered strings are not equal.\n");

    return 0;

}

int str_compare(char a[], char b[])
{
    int count = 0;

    while (a[count] == b[count])
    {
        while (a[count] == '\0' || b[count] == '\0')
            continue;
        count++;
    }

    if (a[count] == '\0' && b[count] == '\0')
        return 0;
    else
        return -1;
}

Question Number 208

Which of the following cannot be used with ungetc?

Question Number 209

The following program is used to find the maximum value in an array. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include< stdio.h>
int main()
{
    int array[100], maximum, size, count, location = 1;

    printf("\nEnter the number of elements in array : ");
    scanf("%d", &size);

    printf("Enter %d integers : ", size);

    for (count = 0; count <  size; count++)
        scanf("\n%d", &array[count]);

    maximum = array[0];
    {
        if (array[count] > maximum)
        {
            maximum = array[count];
            location = count + 1;
        }
    }

    printf("Maximum element is present at location %d and its value is %d.\n", location, maximum);
    return 0;
}

Question Number 210

In printf function in C, which is the format specifier used to print hexadecimal values?

Question Number 211

The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int a, b, x, y, temp, gcd, lcm;

    printf("Enter two values : \n");
    scanf("%d%d", &x, &y);

    a = x;
    b = y;

    while (b != 0)
    {
        temp = b;
        b = a % b;
        a = temp;
    }

    lcm = (x*y) / gcd;

    printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
    printf("Least common multiple of %d and %d = %d\n", x, y, lcm);

    return 0;
}

Question Number 212

Give the output of the following code snippet :
#define MAX(a, b) (a > b ? a : b)

int main()
{
    int x;
    x = MAX(3+3, 2+5);
    printf("%d\n", x);
    return 0;
}

Question Number 213

The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);

int main()
{
    char str[100], dest[100];

    copy_str(dest, str);
    printf("Input a string\n");
    scanf("%s",str);

    printf("Source string:      %s\n", str);
    printf("Destination string: %s\n", dest);

    return 0;
}

void copy_str(char d[], char s[])
{
    int count = 0;

    while (s[count] != '\0')
    {
        d[count] = s[count];
        count++;
    }
    d[count] = '\0';
}

Question Number 214

The following program is used to sort an array of values using Bubble sort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int main()
{
    int array[100], n, c;

    printf("Enter number of elements\n");
    scanf("%d", &n);

    printf("Enter %d integers\n", n);

    for (c = 0; c <  n; c++)
        scanf("%d", &array[c]);

    bubble_sort(array, n);

    printf("Sorted array in ascending order:\n");

    for (c = 0; c <  n; c++)
        printf("%d\n", array[c]);

    return 0;
}

void bubble_sort(int arry[], int n)
{
    int c, d, temp;

    for (c = 0; c <  (n - 1); c++)
    {
        for (d = 0; d <  n - c - 1; d++)
        {
            if (arry[d] > arry[d + 1])
            {

                temp = arry[d];
                arry[d] = arry[d + 1];
                arry[d + 1] = temp;
            }
        }
    }
}

Question Number 215

Binary operators + and - have what priority ?

Question Number 216

Which of the following statements is true about EOF in C?

Question Number 217

Give the output of the following code snippet:
void main()
{
    int c;
    scanf ("%d",c);
    printf("Obtained value is %d", c);
}

Question Number 218

Give the output of the following code snippet :
int main(int argc, char **argv)
{
    char s[10] = "Hello";
    int i = 4;
    printf("%10.*s", i, s);
}

Question Number 219

Give the output of the following code snippet :
void func(int a);
void main()
{
    func(10);
    printf("%d",a);
}

Question Number 220

Give the output of the following code :

void main()
{
    int x = 1, y = 0, z = 5;
    int a = x && y && z;

    printf("%d", a);
}

Question Number 221

Give the output of the following code snippet :
void main()
{
    int x=1,y=2;
    int a=x&y;
    int b=x&&y;
    printf("%d %d",a,b);
}

Question Number 222

The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
int str_compare(char[], char[]);

int main()
{
    int flag;
    char str1[100], str2[100];

    printf("Input first string\n");
    scanf("%s", str1);

    printf("Input second string\n");
    scanf("%s", str2);

    flag = str_compare(str1, str2);

    if (flag == 0)
        printf("Entered strings are equal.\n");
    else
        printf("Entered strings are not equal.\n");

    return 0;

}

int str_compare(char a[], char b[])
{
    int count = 0;

    while (a[count] == 0)
    {
        if (a[count] == '\0' || b[count] == '\0')
            break;
        count++;
    }

    if (a[count] == '\0' && b[count] == '\0')
        return 0;
    else
        return -1;
}

Question Number 223

The following program is used to compare two strings without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int str_compare(char[], char[]);

int main()
{
    int flag;
    char str1[100], str2[100];

    printf("Input first string\n");
    scanf("%s", str1);

    printf("Input second string\n");
    scanf("%s", str2);

    flag = str_compare(str1, str2);

    if (flag == 0)
        printf("Entered strings are equal.\n");
    else
        printf("Entered strings are not equal.\n");

    return 0;

}

int str_compare(char a[], char b[])
{
    int count = 0;

    while (a[count] == b[count])
    {
        if (a[count] == '\0' || b[count] == '\0')
            break;
        count++;
    }

    if (a[count] == '\0' && b[count] == '\0')
        return 0;
    else
        return -1;
}

Question Number 224

The following program is used to sort an array of structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>

struct student
{
    char name[50];
    int studId;
    int marks;
};

int main()
{
    struct student stud[10],temp;
    int i, num;
    printf("Enter number of students : \n");
    scanf("%d", &num);
    printf("Enter information of students:\n");
    for (i = 0; i<  num; ++i)
    {
        printf("Enter student ID: ");
        scanf("%d", &stud[i].studId);
        printf("Enter name: ");
        scanf("%s", stud[i].name);
        printf("Enter marks: ");
        scanf("%d", &stud[i].marks);
        printf("\n");
    }

    for (i = 0; i <  num; i++)
        for (int j = 0; j <  i; j++)
            if (stud[i].studId == stud[j].studId)
            {
                temp = stud[i];
                stud[i] = stud[j];
                stud[j] = temp;
            }

    printf("Student Information :\n\n");
    for (i = 0; i<  num; ++i)
    {
        printf("\nStudent ID %d:\n",stud[i].studId);
        printf("Name: %s", stud[i].name);
        printf("Marks: %d", stud[i].marks);
    }
    return 0;
}

Question Number 225

Which of the following statements is not true about the scanf() function in C?

Question Number 226

Preprocessor directive #undef can be used only on a macro that has #define earlier : State true or false :

Question Number 227

Give the output of the following code snippet :
#define MAN(x, y) ((x)>(y)) ? (x):(y);

int main()
{
    int i=10, j=5, k=0;
    k = MAN(i, j);
    printf("%d, %d, %d\n", i, j, k);
    return 0;
}

Question Number 228

Give the output of the following code snippet :
#define CUBE(p)(p*p*p);
void main()
{
    int a=3,b=10,c=5;
    int x=CUBE(a);
    int y=CUBE(b+c);
    printf("%d %d",x,y);
}

Question Number 229

The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be removed to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);

int main()
{
    char str[100], dest[100];

    printf("Input a string\n");
    scanf("%s",str);

    copy_str(dest, str);

    printf("Source string:      %s\n", str);
    printf("Destination string: %s\n", dest);

    return 0;
}

void copy_str(char d[], char s[])
{
    int count = 0;

    while (s[count] != '\0')
    {
        d[count] = s[count];
        d[count] = d[count-1];
        count++;
    }
    d[count] = '\0';
}

Question Number 230

The following program is used to find the substring in a string without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int main()
{
    char str[100], sub[100];
    int position, length, count = 0;

    printf("Input a string  : \n");
    scanf("%s",str);

    printf("Enter the position and length of substring\n");
    scanf("%d%d", &position, &length);

    sub[count] = '\0';

    printf("Required substring is %s\n", sub);

    return 0;
}

Question Number 231

The following program is used to find length of a string without using string function. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int string_length(char[]);

int main()
{
    char str[100];
    int length;

    printf("Input a string\n");
    scanf("%s", str);
    length = string_length(str);
    printf("Length of string %s = %d\n", str, length);

    return 0;
}

int string_length(char s[])
{
    int count = 0;

    count++;
    return count;
}

Question Number 232

Give the output of the following code snippet :
void main()
{
    int long;
    long=10;
    printf("%d",long);
}

Question Number 233

The following program is used to delete a file. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int status;
    status = remove();
    if (status == 0)
        printf("File has been deleted successfully\n");
    else
    {
        printf("Unable to delete the file\n");
        perror("Error");
    }
    return 0;
}

Question Number 234

The following program is used to add 'n' numbers. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include< stdio.h>

int main()
{
    int num, sum, count, value;
    printf("Enter the number of integers to be added : \n");
    scanf("%d", &num);

    printf("Enter %d integers\n", num);

    for (count = 1; count < = num; count++)
    {
        scanf("%d", &value);
        sum = sum + value;
    }

    printf("Sum of entered integers = %d\n", sum);

    return 0;
}

Question Number 235

Give the output of the following code snippet :
void main()
{

    printf("%+07d\n", 762);

}

Question Number 236

The type va_list is used in an argument list to :

Question Number 237

The following program is used to copy strings without using string function. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
void copy_str(char[], char[]);

int main()
{
    char str[100], dest[100];

    printf("Input a string\n");
    scanf("%s",str);

    copy_str(dest, str);

    printf("Source string:      %s\n", str);
    printf("Destination string: %s\n", dest);

    return 0;
}

void copy_str(char d[], char s[])
{
    int count = 0;

    d[count] = s[count];
    while (s[count] != '\0')
    {
        count++;
    }
    d[count] = '\0';
}

Question Number 238

The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int a, b, x, y, temp, gcd, lcm;

    printf("Enter two values : \n");
    scanf("%d%d", &x, &y);

    a = x;
    b = y;

    while (b == 0)
    {
        temp = b;
        b = a % b;
        a = temp;
    }

    gcd = a;
    lcm = (x*y) / gcd;

    printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
    printf("Least common multiple of %d and %d = %d\n", x, y, lcm);

    return 0;
}

Question Number 239

Give the output of the following code snippet :
#define CUBE(x) (x*x*x)
#define M 10
#define N M+1

int main()
{

    int volume =CUBE(3+2);

    printf("%d %d ",volume,N);

    return 0;
}

Question Number 240

The following program is used to swap two strings. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
int main()
{
    char str1[100], str2[100], temp[50];

    printf("Enter the str1 string\n");
    scanf("%s", str1);

    printf("Enter the str2 string\n");
    scanf("%s", str2);

    printf("\nBefore Swapping\n");
    printf("First string: %s\n", str1);
    printf("Second string: %s\n\n", str2);

    strcpy(temp, str1);
    strcpy(str1, str2);
    strcpy(str2, str1);

    printf("After Swapping\n");
    printf("First string: %s\n", str1);
    printf("Second string: %s\n", str2);

    return 0;
}

Question Number 241

The following program is used to copy a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    char ch;
    FILE *source, *target;
    source = fopen("CopyFile.txt", "r");
    {
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    target = fopen("Destination.txt", "w");

    if (target == NULL)
    {
        fclose(source);
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    while ((ch = fgetc(source)) != EOF)
        fputc(ch, target);

    printf("File copied successfully.\n");

    fclose(source);
    fclose(target);

    return 0;
}

Question Number 242

Which of the following type specifiers are used to denote a floating point value in the scanf() function?

Question Number 243

The following program is used to sort an array of structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>

struct student
{
    char name[50];
    int studId;
    int marks;
};

int main()
{
    struct student stud[10],temp;
    int i, num;
    printf("Enter number of students : \n");
    scanf("%d", &num);
    printf("Enter information of students:\n");
    for (i = 0; i<  num; ++i)
    {
        printf("Enter student ID: ");
        scanf("%d", &stud[i].studId);
        printf("Enter name: ");
        scanf("%s", stud[i].name);
        printf("Enter marks: ");
        scanf("%d", &stud[i].marks);
        printf("\n");
    }

    for (i = 0; i <  num; i++)
        for (int j = 0; j <  i; j++)
            if (student[i].studId <  student[j].studId)
            {
                temp = stud[i];
                stud[i] = stud[j];
                stud[j] = temp;
            }

    printf("Student Information :\n\n");
    for (i = 0; i<  num; ++i)
    {
        printf("\nStudent ID %d:\n",stud[i].studId);
        printf("Name: %s", stud[i].name);
        printf("Marks: %d", stud[i].marks);
    }
    return 0;
}

Question Number 244

The following program is used to delete a file. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int status;
    status = remove("Input.txt");
    while (status == -1)
        printf("File has been deleted successfully\n");
    else
    {
        printf("Unable to delete the file\n");
        perror("Error");
    }
    return 0;
}

Question Number 245

The following program is used to generate the fibonacci series. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?


#include < stdio.h>

int main()
{
    int count, n, num1 = 0, num2 = 1, result = 0;
    printf("Enter number of terms: ");
    scanf("%d", &n);
    printf("Fibonacci Series:\n %d  %d  ", num1, num2);
    count = 2;
    while (count< n)
    {
        result = num1 + num2;
        num1 = num2;
        printf("%d ", result);
    }
    return 0;
}

Question Number 246

Which of the following statements is true about the scanf() function in C?

Question Number 247

The following program is used to merge two arrays into a single array. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
void MergeArrays (int[], int, int[], int, int[]);

int main()
{
    int arry1[100], arry2[100], num1, num2, c, result[200];

    printf("Input number of elements in first array\n");
    scanf("%d", &num1);

    printf("Input %d integers\n", num1);
    for (c = 0; c <  num1; c++)
    {
        scanf("%d", &arry1[c]);
    }

    printf("Input number of elements in second array\n");
    scanf("%d", &num2);

    printf("Input %d integers\n", num2);
    for (c = 0; c <  num2; c++)
    {
        scanf("%d", &arry2[c]);
    }

    MergeArrays(arry1, num1, arry2, num2, result);

    printf("Result array:\n");

    for (c = 0; c <  num1 + num2; c++)
    {
        printf("%d\n", result[c]);
    }
    return 0;
}

void MergeArrays (int arry1[], int num1, int arry2[], int num2, int result[])
{
    int i, j, k;
    j = k = 0;

    for (i = 0; i <  num1;)
    {
        if (j <  num1 && k <  num2)
        {

            if (arry1[j] <  arry2[k])
            {
                result[i] = arry1[j];
                j++;
            }
            else
            {
                result[i] = arry2[k];
                k++;
            }
            i++;
        }

        else if (j == num1)
        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry2[k];
                k++;
                i++;
            }
        }

        else
        {
            for (; i <  num1 + num2;)
            {
                result[i] = arry1[j];
                j++;
                i++;
            }
        }
    }
}

Question Number 248

The following program is used to delete a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{

    status = remove("Input.txt");

    if (status == 0)
        printf("File has been deleted successfully\n");
    else
    {
        printf("Unable to delete the file\n");
        perror("Error");
    }
    return 0;
}

Question Number 249

Give the output of the following code snippet :
int x;
float y;
void main()
{

    printf("%d %.2f",x,y);
}

Question Number 250

The following program is used to delete a file. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int status;
    remove(status);
    if (status == 0)
        printf("File has been deleted successfully\n");
    else
    {
        printf("Unable to delete the file\n");
        perror("Error");
    }
    return 0;
}

Question Number 251

The following program is used to add two distances ( inch to feet ) using structures. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
struct Distance
{
    int feet;
    float inch;
};
struct Distance dist1, dist2, sum;

void main()
{
    printf("Enter information for 1st distance\n");
    printf("Enter feet: ");
    scanf("%d", &dist1.feet);
    printf("Enter inch: ");
    scanf("%f", &dist1.inch);
    printf("\nEnter information for 2nd distance\n");
    printf("Enter feet: ");
    scanf("%d", &dist2.feet);
    printf("Enter inch: ");
    scanf("%f", &dist2.inch);
    sum = dist1.feet + dist2.feet;
    sum.inch = dist1.inch + dist2.inch;

    if (sum.inch>12.0)
    {
        sum.inch = sum.inch - 12.0;
        ++sum.feet;
    }
    printf("\nSum of distances=%d\'-%.1f\"", sum.feet, sum.inch);
}

Question Number 252

The following program is used to find the GCD and LCM of two numbers. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include < stdio.h>

int main()
{
    int a, b, x, y, temp, gcd, lcm;

    printf("Enter two values : \n");
    scanf("%d%d", &x, &y);

    a = x;
    b = y;

    while (temp < = 0)
    {
        temp = b;
        b = a % b;
        a = temp;
    }

    gcd = a;
    lcm = (x*y) / gcd;

    printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
    printf("Least common multiple of %d and %d = %d\n", x, y, lcm);

    return 0;
}

Question Number 253

Which preprocessor operator allows to convert any argument in a macro function to a string?

Question Number 254

The following program is used to execute a command in the OS. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#include< stdio.h>
#include< stdlib.h>

int main()
{
    int files;

    printf("Executing command : 'DIR'\n");
    files = systems("dir");

    printf("Returned value is: %d.\n", files);
    return 0;
}

Question Number 255

The following program is used to copy a file. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#include < stdlib.h>

int main()
{
    char ch;
    FILE *source, *target;
    source = fopen("CopyFile.txt", "r");

    if (source == NULL)
    {
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    target = fopen("Destination.txt", "w");

    if (target == NULL)
    {
        fclose(source);
        printf("Press any key to exit...\n");
        exit(EXIT_FAILURE);
    }

    printf("File copied successfully.\n");

    fclose(source);
    fclose(target);

    return 0;
}