Search This Blog

Saturday, 1 November 2014

GE6151 Computer programming 2marks with answer



APRIL/MAY 2014
                                                                                                         
2.      List different data types available in C
C has the following basic built-in datatypes.
·         Int  eg.1,45,879,..
·         Float eg.7.8,1.2,5.66
·         double
·         char eg.a,b,h,..
3.Write a program to print factorial of a given number using c programming
#include<stdio.h>
void main()
{
int num, c , factorial;
printf(“To find factorial of a given number \n”);
printf(“Enter the number :”);
scanf (“%d \n”, &num);
c =1;
factorial=1;
while ( num > 1)
{
c++ ;
factorial=factorial*c;
num= num-1;
}
printf(“The factorial of the entered number is:%d”, factorial);
}
OUTPUT:
To find factorial of a given number
Enter the number : 5
The factorial of the entered number is 120
4.   Why computer is know n as data processing system? (MAY 2009)
Any process that uses a computer program will enter data and summarize, analyze or otherwise convert data into usable information . The process may be automated and run on a computer . It involves recording, analyzing, sorting, summarizing, calculating, disseminating and storing data. Thus Computer is know n as data processing system.

6.   What are the characteristics of computers?
(JAN 2009)

·           Speed

·           Accuracy.
·           Automation.
·      Endurance.

·     Versatility.

·      Storage.

·     Cost Reduction.


7. How will you classify computer systems?(jan 2009)
Based on physical size, performance and application areas, we can generally divide computers into four major categories:
1.             Micro computer

2.             Mini Computer

3.             Mainframe computer and

4.             Super Computer

8. Expand ENIVAC, ABC, EDVAC, EDSAC and UNIVAC. (JAN2010)

ENIAC – Electronic Numerical Integrator and Calculator.

ABC – Atanasoff and Berry Computer.

EDVAC – Electronic Discrete Variable Automatic Calculator.

EDSAC – Electronic Delay Storage Automatic Calculator.

UNIVAC – UNIversal Automatic Computer.


9.
Write the binary and octal  equivalent of hexadecimal number 7BD?(apr2009)


Binary Equivalent of 7BD
= (0111 1011 1101)2


Octal Equivalent of 7BD
= (011 110 111 101) = (3675)8

10.
Give any tw o tasks, which humans perform better than  computers?(jan2009)







        Humans can communicate better than computers.
        Humans are much reliable than computers.

11. What is the use of computer in medicine and healthcare?
(JAN2009)

·           Study of biological vision system.

·           Medical Imaging.

·           Mobile healthcare technology.

·           Nano technology.

·           Bioinformatics.


12. Convert binary number 100110 into its octal equivalent?(jan2009)







Octal equivalent of 100110 = (100 110) = (46)8




















































13.
Differentiate analog and digital computers?(jan2010,june2013)







S No
Analog Computer

Digital Computer





1
Process measured data
Process discrete data






2
Analog computers are not precise
Digital computers are more precise




3
Processing speed is low.
Processing speed is high.






4
Less accuracy.
More accuracy.






14. Find the decimal equivalent of hexadecimal number  4D.C8(jan 2010)










































4D.C8= 4 X 161 + 13 X 162 + 12 X 16-1 + 8 X 16-2


=   64 + 13 +0.75 + 0.03125

=   (77.78)2

15. Convert hexadecimal number into binary equivalent of EBC (jan 2010)

Binary equivalent of EBC = (1110 1011 1100)2







16.Write code to Two dimensional array declaration (june2014)
Two-dimensional array are those type of array, which has finite number of rows and finite number of columns. The declaration form of 2-dimensional array is
Data_type    Array_name [row size][column size];
Eg:
Int a[5][5];
17.List out any 4 string handling functions in C(june2014)
Strcpy-copies one string to another
Strncpy-writes exactly n bytes
Strcat-
appends one string to another
Strncat-appends no more than n bytes
Strlen-returns the length of the string
strcmp-compares two strings

18. What is the difference between pass by value and pass by reference in c? (june2014)
Pass By Reference :
In Pass by reference address of the variable is passed to a function. Whatever changes made to the formal parameter will affect to the actual parameters
-Same memory location is used for both variables.(Formal and Actual)-
- it is useful when you required to return more then 1 values
Pass By Value:
- In this method value of the variable is passed. Changes made to formal will not affect the actual parameters.
- Different memory locations will be created for both variables.
- Here there will be temporary variable created in the function stack which does not affect the original variable.

19. Define recursive (june2014)
A recursive function is a function that calls itself during its execution. This enables the function to repeat itself several times, outputting the result and the end of each iteration.
Eg
int factorial(int n)
{
    if (n == 0)
 {
        return 1;
    }
else
{
        return n * factorial(n - 1);
    }
}
20. what is the purpose of union in c? (june2014)
A union is a special data type available in C that enables you to store different data types in the same memory location. You can define a union with many members, but only one member can contain a value at any given time. Unions provide an efficient way of using the same memory location for multi-purpose.
Eg
union Data
{
   int i;
   float f;
   char  str[20];
} data;  
21. what is the use of preprocessor directives in c? (june2014,jan 2014)
The C preprocessor or cpp is the macro preprocessor for the C and C++ computer programming languages. The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control.
Eg
Directive
Description
#define
Substitutes a preprocessor macro
#include
Inserts a particular header from another file
#undef
Undefines a preprocessor macro
#ifdef
Returns true if this macro is defined
#ifndef
Returns true if this macro is not defined





















22. define arrays (jan2014)
An array is a collection of similar data item (same type).Arrays are of two types:
  1. One-dimensional arrays
  2. Multidimensional arrays
Declaration of one-dimensional array
datatype arrayname[array_size];
 
For example:
 
int age[5];
23. Write a for loop statement to print numbers from 10 to 1. (jan2014)
For(i=10;i>=1;i--)
{
Printf(“%d”,i);
}
24. Name any two library functions used for string handling. (jan2014)
1.string.h
Common functions are
            Stpcpy
strcmp
strcat
2.ctype.h
Common functions are
Isalnum
Isalpha
Isascii
Isdigit
Islower
25. What is the need for functions? (jan2014)

A function is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions.

A function declaration tells the compiler about a function's name, return type, and parameters.

A function definition provides the actual body of the function.

return_type function_name( parameter list )
{
   body of the function
}

26. What is the uses of pointers? (jan2014)
A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location.
The general form of a pointer variable declaration is:
datatype *var-name;
-when memory is allocated dynamically at run time, pointers are needed to reference the memory.
-Used to pass the variables to function using pass by reference
27. Differentiate between structure and union.(jan2014)

Structure

Union

1.The keyword  struct is used to define a structure
1. The keyword union is used to define a union.
2. When a variable is associated with a structure, the compiler allocates the memory for each member. The size of structure is greater than or equal to the sum of  sizes of its members. The smaller members may end with unused slack bytes.
2. When a variable is associated with a union, the  compiler allocates the  memory by considering the size of the largest memory. So, size of union is equal to the size of largest member.
3. Each member within a structure is assigned unique storage area of location.
3. Memory allocated is shared by individual members of union.
4. The address of each member will be in ascending order This indicates that memory for each member will start at different offset values.
4. The address is same for all the members of a union. This indicates that every member begins at the same offset value.
5 Altering the value of a member will not affect other members of the structure.
5. Altering the value of any of the member will alter other member values.
6. Individual member can be accessed at a time
6. Only one member can be accessed at a time.
7. Several members of a structure can initialize at once.
7. Only the first member of a union can be initialized.


2 comments:

  1. C# for loop structure of C# is like an all-in-one looping utility. The C# for loop acts like the while loop only with some extra features. The syntax of a C# for loop is quite different compared to the other two looping structures.

    ReplyDelete