Programming Questions

Q:

Macro flowchart is also called as

A) Less Detail flowchart B) More detail flowchart
C) Simple detailed flowchart D) None of the above
 
Answer & Explanation Answer: A) Less Detail flowchart

Explanation:

A flowchart is a type of diagram that represents a workflow or process. A flowchart can also be defined as a diagrammatic representation of an algorithm, a step-by-step approach to solving a task.

Macro flowchart shows the outlines the main segments of program. Macro flowchart is also called as less detail flowchart.

Report Error

View Answer Report Error Discuss

Filed Under: Programming
Exam Prep: AIEEE , Bank Exams , CAT , GATE , GRE
Job Role: Analyst , Bank Clerk , Bank PO

12 8586
Q:

What would be the output of the following program?

main()

{

    extern int fun ( float );

    int a;

    a = fun ( 3. 14 );

    printf ("%d", a);

}

int fun ( aa )

float aa ;

{

     return ( (int) aa );

}

Answer

Error occurs because we have mixed the ANSI prototype with K & R style of function definition.


When we use ANSI prototype for a function and pass a float to the function it is promoted to a double. When the function accepts this double into a float a type mismatch occurs hence the error.


The remedy for this error could be to define the function as :


int fun (float aa)


{


  ....


}

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

9 7946
Q:

If the binary equivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what would be the output of the following program?

main()

{

    float a = 5.375 ;

    char *p;

    int i;

    p = ( char* ) &a ;

    for ( i = 0; i <= 3 ; i++ )

          printf ( " %02x ", (unsigned char ) p[i] );

}

Answer

00 00 AC 40

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

7 7486
Q:

Point out the error in the following program.

main()

{

    char mybuf[] = "Zanzibar" ;

    char yourbuf[] = " Zienckewiz";

    char * const ptr = mybuf;

     *ptr = 'a';

     ptr = yourbuf;

}

Answer

ptr pointer is constant. In ptr = yourbuf the program is trying to modify it, hence an error.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

5 6847
Q:

Write a c program for linear search.

Answer

#include<stdio.h>
int main(){

    int a[10],i,n,m,c=0;

    printf("Enter the size of an array: ");
    scanf("%d",&n);

    printf("Enter the elements of the array: ");
    for(i=0;i<=n-1;i++){
         scanf("%d",&a[i]);
    }

    printf("Enter the number to be search: ");
    scanf("%d",&m);
    for(i=0;i<=n-1;i++){
         if(a[i]==m){
             c=1;
             break;
         }
    }
    if(c==0)
         printf("The number is not in the list");
    else
         printf("The number is found");

    return 0;
}

Sample output:
Enter the size of an array: 5
Enter the elements of the array: 4 6 8 0 3
Enter the number to be search: 0
The number is found

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

2 6544
Q:

What do the functions atoi(), itoa() and gcvt () do? Show how would you use them in a program.

Answer

atoi()         Converts a string to an integer.


itoa()         Convert an integer to a string


gcvt()        Converts a floating-point number to a string


 


#include "stdlib.h"


main()


{


      char s[] = "12345";


      char buffer [15], string[20];


      int i;


      


      i = atoi (s);


      printf("\n%d",i);


 


       gcvt (20.141672, 4, buffer);


       printf ("\n%s", buffer);


 


       itoa(15, string,2);


        printf ("\n%s", string);


}

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

2 6017
Q:

What is math.floor(3.6)?

A) 6 B) 3
C) 3.5 D) 0.6
 
Answer & Explanation Answer: B) 3

Explanation:

The Math.floor() function in JavaScript is used to round off the number passed as parameter to its nearest integer in Downward direction of rounding i.g towards the lesser value.

 

Hence, math.floor(3.6) = 3.

Report Error

View Answer Report Error Discuss

5 5478
Q:

Point out the error, if any, in the following program.

#include "stdarg.h"

main()

{

     display ( 4, 12.5, 13.5, 14.5, 44.3);

}

display(int num, ...)

{

       float c; int j;

        va_list ptr;

        va_start (ptr, num);

        for ( j = 1; j <= num; j++)

        {

            c = va_arg ( ptr, float );

            printf ("\n%f", c);

         }

}

Answer

While extracting a float argument using va_arg we should have useed 


c = va_arg (ptr, double)

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

1 4785