Thursday, 26 February 2015

series

/*
Write a program to determine the sum of the following series:
    S = 1 – 3 + 5 – 7 + ...(n terms)
Read the value of n from the user.

*/
#include<stdio.h>

main()
{
    int n, s=0,i,sign=1;
    printf("\nEnter value of n=");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        s=s+sign*(2*i-1);   
        sign=sign*(-1);
    }
    printf("\nThe sum of the series=%d",s);
}

Write a function that returns 1 if the two matrices passed to it as argument are equal and 0 otherwise

#include<stdio.h>

int IsEqual(int [][100],int,int, int[][100],int,int);
main()
{
    int m1[100][100],m2[100][100],r1,r2,c1,c2,i,j;
    printf("\nEnter row and column number of the first matrix=");
    scanf("%d%d",&r1,&c1);
    printf("\nEnter the elements of the first matrix\n");
    for(i=0;i<r1;i++)
    {
        for(j=0;j<c1;j++)
        {
            scanf("%d",&m1[i][j]);
        }
    }
    printf("\nThe first matrix\n");
    for(i=0;i<r1;i++)
    {
        for(j=0;j<c1;j++)
        {
            printf("%6d",m1[i][j]);
        }
        printf("\n");
    }
    printf("\nEnter row and column number of the second matrix=");
    scanf("%d%d",&r2,&c2);
    printf("\nEnter the elements of the first matrix\n");
    for(i=0;i<r2;i++)
    {
        for(j=0;j<c2;j++)
        {
            scanf("%d",&m2[i][j]);
        }
    }
    printf("\nThe second matrix\n");
    for(i=0;i<r2;i++)
    {
        for(j=0;j<c2;j++)
        {
            printf("%6d",m2[i][j]);
        }
        printf("\n");
    }
    if(IsEqual(m1,r1,c1,m2,r2,c2)==1)
        printf("\nThe matrices are equal");
    else
        printf("\nThe matrices are not equal");
}

int IsEqual(int a[][100],int r1,int c1, int b[][100],int r2,int c2)
{
    int i,j;
    if(r1!=r2 || c1!=c2)
        return 0;
    for(i=0;i<r1;i++)
    {
        for(j=0;j<c1;j++)
        {
            if(a[i][j]!=b[i][j])
            {
                return 0;
            }
        }
    }
    return 1;
   
}

Write a function which accepts an array of size n containing integer values and returns average of all values. Call the function from main program.

#include<stdio.h>

int avg(int [],int);

main()
{
    int a[100], n,i,avrg;
    printf("\nEnter number of terms=");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    avrg=avg(a,n);
    printf("\nThe average=%d",avrg);
}
int avg(int a[],int n)
{
    int i,s=0;
    for(i=0;i<n;i++)
    {
        s=s+a[i];
    }
    return s/n;
}

Tuesday, 24 February 2015

DOEACC A3-R3 January, 2009 Question paper

5.
a)    What are the commonly used input functions in ‘C’? Write their syntax and explain the purpose of each.
b)    Develop a flowchart and then write a program to compute the roots of a quadratic equation A*X^2 + B*X + C = 0. Allow the possibility that (B^2 – 4*A*C) <= 0.
(6+9)
6.
a)    What are logical, syntactic and execution errors? Give examples of each. Which is most difficult to find and why?
b)    Enumerate features of a good ‘C’ program. Describe the commonly used techniques as to how ‘C’ programs can be made highly readable and modifiable.
c)    What is an algorithm? Develop an algorithm to test whether a given number is a prime number.
(5+5+5)
7.
a)    Develop loops using
    i)    While statement
    ii)    Do-while statement
    iii)    For statement
that will calculate the sum of every third integer, beginning with k=2 for all values of k <= 100.
b)    Write a function that will compute
        Y = X^n
    Where Y and X are floating point numbers and n is an integer number. Use this function and print the output
     X         n        Y
    ...         ...        ...

Check for possible exceptions that may occur during computations with regard to the magnitude of computed values.

(6+9)
8.
a)    How does an array differ from a structure? Give and explain the syntax of array and structure as defined in ‘C’.
b)    How are one-dimensional and two-dimensional arrays stored in computer memory? Illustrate with an example.
c)    Develop a program to multiply two matrices with sizes 3x4 and 4x5. Your program should take care of the fact that no element of either matrix can be negative. Include appropriate documentation.

(6+2+7)
9.
a)    Give the main advantage of storing data as a file. Describe various ways in which data files can be categorized in ‘C’. Illustrate by examples.
b)    What is an indirection operator? Explain its usage to access a multidimensional array element. Illustrate your answer by an example.
c)    ‘C’ compiler supports many pre-processor commands. Write their names only.

(6+6+3)
 

DOEACC A3-R3 July, 2008 Question paper

5.
a)    What is structured programming? Explain and give examples of relevant constructs using pseudo-code. Highlight the advantages and disadvantages of structured programming.
b)    What is an execution error? Differentiate it from syntactic error. Give examples.
c)    It is said that ‘C’ is a middle level assembly language. Mention those features of ‘C’ which enable this description.

(8+3+4)
6.
a)    Write and explain the action of WHILE statement. Develop a program in ‘C’ language to compute the average of every third integer number lying between 1 and 100. Include appropriate documentation.
b)    Develop a function to calculate sum of n even integers starting from a given even integer.
c)    Identify all the compound statements which appear in the following program segment:

{
    sum=0;
    do
    {
        scanf(“%d”, &i);
        if (i < 0)
        {
            i=-i;
            ++flag;
        }
        sum += i;
    } while (i != 0);
}

(7+5+3)
7.
a)    Define an array. How are arrays processed in ‘C’? Illustrate by taking two-dimensional arrays as examples.
b)    What are subscripts? How are they specified? What restrictions apply to the values that can be assigned to subscripts in ‘C’ language?
c)    Write a ‘C’ program that will enter a line of text, store in an array and then display backwards. The length of the line should be undefined, (being terminated by ENTER key), but less than 80 characters.

(4+4+7)
8.
a)    What is a pointer in ‘C’? How is a pointer variable declared? Give examples and explain. Enumerate the utility of pointer variables.
b)    A program in ‘C’ language contains the following declaration:
    static int x[8] = {1,2,3,4,5,6,7,8};
    i)    What is the meaning of x?
    ii)    What is the meaning of (x + 2)?
    iii)    What is the meaning of *x?
    iv)    What is the meaning of (*x + 2)?
    v)    What is the meaning of *(x + 2)?
c)    What is a structure? How does a structure differ from a union? Give examples. For what kind of applications, union data structure is useful? How are arrays different from structure?
(4+5+6)
9.
a)    How can a procedure be defined in ‘C’? Give an example. Bring out the differences between function and procedure.
b)    Draw a flowchart and then develop an interactive ‘C’ program which finds whether a given integer number is prime or not. Make use of a function subprogram.
(6+9)

Thursday, 19 February 2015

Newton Raphson Method

/*
Write a C program to solve algebraic equation x3-8x-4=0 by using Newton Raphson Method.
*/
#include<stdio.h>
#include<math.h>
float f(float);
float df(float);
main()
{
    float a,x,h,err=0.00001;
    printf("\nEnter initial value=");
    scanf("%f",&a);
    x=a;
    do
    {
        h=-(f(x)/df(x));
        a=x;
        x=x+h;
    }while(fabs(x-a)>=err);
    printf("\nThe approximate value is %f",x);
}

float f(float x)
{
    return(x*x*x-8*x-4);
}

float df(float x)
{
    return(3*x*x-8);
}

Wednesday, 18 February 2015

DOEACC A3-R3 January, 2008 Question paper

5.
a)    The sequence of Fibonacci numbers is defined as below:
        f(i) = f(i-1) + f(i-2) with f(0) = 1 and f(1) = 1
    Draw a flowchart and then develop a ‘C’ program to calculate and display Fibonacci numbers.
b)    Write a ‘C’ program to calculate the frequencies of different alphabets, present in a given string. The string of alphabets is to be taken as input from the keyboard.
(7+8)
6.
a)    Write a ‘C’ program to do the following:
i)    Accept a sequence of integer numbers from the keyboard
ii)    Sort the sequence in ascending order
iii)    Output the position of each element of the input sequence in the sorted array.
Develop a flowchart and then develop ‘C’ program to find the union of two set of characters, taken as input from the keyboard.

(8+7)
7.
a)    Write a ‘C’ program to accept any 3 digit integer number from the keyboard and display the word equivalent representation of the given number.
b)    Write a ‘C’ program to accept a date in the format DD/MM/YYYY and add an integer to get the resultant date.

(9+6)
8.    Define a suitable data structure to store the information like student name, roll number, enrolment centre and marks of five different subjects. Write a ‘C’ function to insert sufficient data in your data structure and function to print the name of the student and the total obtained marks who have secured highest total marks for each and every enrolment centre
(15)
9.
a)    Define a self referential structure to represent a set of integer numbers in linked list form.
b)    Write a ‘C’ function to split the list in several sub-lists depending on the number of digits representing the integers i.e. single digit integers will form a list, double digit numbers will form another list and so on.

(3+12)
 

Monday, 16 February 2015

DOEACC A3-R3 July, 2007 Question paper

5.
a)    Write a ‘C’ program to compute the following series:
        1 – x + x2 /2 – x3 /6 + x4 /24 +...+ (-1)n xn /n!
Where n and x is to be accepted by the user.
b)    Develop a flowchart and then write a ‘C’ program to sort strings passed to the program through the command line arguments. Also display the sorted strings.
(6+9)
6.
a)    Define a structure to store roll_no, name and marks of a student.
b)    Using the structure of Q6. a), above write a ‘C’ program to create a file “student.dat”. There must be one record for every student in the file. Accept the data from the user.
c)    Using the “student.dat” of Q6. b), above write a ‘C’ program to search for the details of the student whose name is entered by the user.
(3+6+6)
 7.
a)    Write a ‘C’ function to reverse a singly linked list by traversing it only once.
b)    Write a ‘C’ function to remove those nodes of a singly linked list which have duplicate data. Assume that the linked list is already in ascending order.

(7+8)
8.
a)    What do you understand by loading and linking of a program?
b)    Write a ‘C’ function to generate the following figure for n = 7.
    
The value of n is passed to the function as an argument. Print the triangle only if n is odd otherwise print an error message.
c)    Write a ‘C’ function to arrange the elements of an integer array in such a way that all the negative elements are before the positive elements. The array is passed to it as an argument.


(3+6+6) 
9.
a)    Write a recursive function in ‘C’ to count the number of nodes in a singly linked list.
b)    Develop a flowchart and then write a ‘C’ program to add two very large positive integers using arrays. The maximum number of digits in a number can be 15.
(5+10)
 

DOEACC A3-R3 January, 2007 Question paper

5.
a)    Develop a flowchart and then write a C program to display all prime numbers less than the number entered by the user.
b)    Explain the difference between an array, structure and an enumerated data type.

(10+5)
6. Write an algorithm and then develop a program to evaluate the roots of a quadratic equation. Define and use a function cal_roots() to calculate the roots such that roots are also available in calling function i.e. use pointers.
(15)

7. Develop a flowchart and then write a C program to find the occurrence (single or multiple) of a substring in a given string. The substring and string are entered by the user. Also point out the location at which the substring occurs.
(15)

8.
a)    Explain the difference between parameter passing mechanism “Call by value” and “Call by reference”. Which is more efficient and why?
b)    Develop a flowchart and logic to implement the stack data structure using link list.
(5+10)

9.
a)    Draw a flowchart and then write a C program to enter the roll number and marks of any three subjects of few students from the keyboard and write to a file.
b)    It is said that “C is a middle level language and is good for system level programming.” Describe three facilities available in ‘C’ which support this statement.
(10+5)

Sunday, 15 February 2015

#include<stdio.h>

main()
{
    float mon_sale, income;
    printf("\nEnter monthly sale=");
    scanf("%f",&mon_sale);
    if(mon_sale>=50000)
        income=375+0.16*mon_sale;
    else if(mon_sale<50000 && mon_sale>=40000)
        income=350+0.14*mon_sale;
    else if(mon_sale<40000 && mon_sale>=30000)
        income=325+0.12*mon_sale;
    else if(mon_sale<30000 && mon_sale>=20000)
        income=300+0.09*mon_sale;
    else if(mon_sale<20000 && mon_sale>=10000)
        income=250+0.05*mon_sale;
    else if(mon_sale<10000)
        income=200+0.03*mon_sale;
    printf("\nIncome=%f",income);
}

DOEACC A3-R3 July, 2006 Question paper

5.
a)    Write the C Statements (all necessary statements) that open the file inf.dat for reading, and open the file outf.dat for writing.
b)    Write the C program to write
        “Introduction to C-Programming”
    to the file outf.dat.
c)    Write a C program that reads integers from the file scores.dat. After all the integers have been read, the program writes the sum of all the nonnegative integers to the video display. Assume that the file scores.dat contains at least one integer.
Monthly SalesIncome
Greater than or equal to Rs.50,000 375 plus 16% of sales
Less than Rs. 50,000 but Greater than or equal to Rs. 40,000 350 plus 14% of sales
Less than Rs. 40,000 but Greater than or equal to Rs. 30,000 325 plus 12% of sales
Less than Rs. 30,000 but Greater than or equal to Rs. 20,000 300 plus 9% of sales
Less than Rs. 20,000 but Greater than or equal to Rs. 10,000 250 plus 5% of sales
Less than Rs. 10,000 200 plus 3% of sales

b)    What is printed after execution of each of the following C-programs?
1.
void main()
{
    float reals[5];
    *(reals+1) = 245.8;
    *reals = *(reals + 1);
    printf(“ %f”, reals[0] );
}

2.
void main( )
{
    int nums[3];
    int *ptr = nums;
    nums[0] = 100;
    nums[1] = 1000;
    nums[2] = 10000;
    printf( “%d\n”, ++*ptr );
    printf( “%d”, *ptr );
}

3.
void main()
{
    int digit = 0;
    while (digit <= 9)
        printf( “%d\n”, digit++);
}
4.
void main()
{
    int a=7, b=6;
    fun1(a,b);
    printf(“\n a is %d b is %d”, a, b);
}
int fun1(int c,int d)
{
    int e;
    e = c * d;
    d = 7 * c;
    printf(:\n c is %d d is %d e is %d”, c, d, e);
    return;
}
(7+[2x4])
7.
a)    Write a C function word_count() to count the number of words in a given string and then call in Main().
b)    Write a C function print_upper() to prints its character argument in uppercase.
c)    Write a macro that clears an array to zero.
(7+4+4)

8.
a)    What is a Structure? Define a structure that contains the following members:
    i)    An integer quantity called acct_no
    ii)    A character called acct_type
    iii)    A 40-element character array called name
    iv)    A floating-point quantity called balance
    v)    A structure variable called last payment, of type date: defined as an integer called month; an integer called day; an integer called year
    vi)    Include the user_defined data type account within the definition.
    vii)    Include structure variable customer, which is 100-element array of structures called account.

b)    What is Pointer in C? How Pointers and Arrays are related?


(8+7)
9
a)    Write short notes on any three of the following:
b)    Switch statement (give proper syntax and examples)
c)    What do you mean by Loop? How while-loop and do-loop differs?
d)    What is C Preprocessor? Explain any two C preprocessor commands with example.
e)    Break and Continue Statements

(3x5)

DOEACC A3-R3 January, 2006 Question paper

5.
a) Discuss with the help of examples the action of break statement and the continue statement.
b) Does the null statement have any uses besides indication that the body of a loop is empty? Explain.
c) What is the purpose of the \? Escape sequence?
(8+4+3)

(4+2+9)

7.
a) If a pointer is an address, what does the expression like p + j mean?
b) Is i[a] same as a[i]? Justify your answer.
c) Write the following function:

Bool search(int a[], int n, int x);
 
Where a is an array to be searched, n is the number of elements in the array, and x is the search key. “search” should return TRUE if x matches some element of a, FALSE if it doesn’t. Use pointer arithmetic to visit array elements. Include appropriate documentation in your program.
(4+2+9)
8.
a) Develop an algorithm to do the following:
Read an array of 20 elements and then send all negative elements of the array to the end without altering the original sequence.
b) Draw a flow chart and then write a ‘C’ program to generate first 15 members of the following sequence.
1, 3, 4, 7, 11, 18, 29, ...

(5+10)
9.
Develop a flowchart and then write a program for analyzing a line of text stored in a file by examining each of the characters and displaying into which of several different categories vowels, constants, digits, white spaces it falls. Count of the number of vowels, consonants, digits and white space characters. Include an appropriate documentation in your program.
(15)



Thursday, 12 February 2015

Method of False position

/*
Q1. Write a C program to solve algebraic equations x3-2x-5=0 by using Method of False position. 
*/ 
#include<stdio.h>
#include<math.h>

float f(float);

main()
{
float x0,x1,x2,err=0.00001;
printf("\nEnter the value of x0: ");
scanf("%f",&x0);
printf("\nEnter the value of x1: ");
scanf("%f",&x1);
if(f(x0)*f(x1)>0)
printf("\nRoot does not lies between %f and %f",x0,x1);
else
{
do
{
x2=x0-((f(x0)*(x1-x0))/(f(x1)-f(x0)));
printf("\nx0=%f, f(x0)=%f, x1=%f, f(x1)=%f, x2=%f, f(x2)=%f",x0,f(x0),x1,f(x1),x2,f(x2));
if(f(x0)*f(x2)<0)
{
x1=x2;
}
else
{
x0 = x2;
}
}while(fabs(f(x2))>err);
printf("\n\nApp.root = %f",x2);
}
}

float f(float x)
{
return(x*x*x-2*x-5);
}

Wednesday, 11 February 2015

Bisection method C program


 /*
 Write a C program to solve algebraic equation x2-x-1=0 by using Method of Bisection
*/
#include<stdio.h>
#include<math.h>

float f(float);
main()
{
    float x,a,b,err=0.00001;
    printf("\nEnter values of a and b=");
    scanf("%f%f",&a,&b);
    if(f(a)*f(b)>0)
        printf("\nRoot does not lies between %f and %f",a,b);
    else
    {
        do
        {
            x=(a+b)/2;
            if(f(x)==0)
            {
                break;
            }
            else if(f(a)*f(x)<0)
                b=x;
            else
                a=x;
        }while(fabs(b-a)>=err);
        printf("\nRoot of the equation=%f",x);
    }
   
}

float f(float x)
{
    return(x*x-x-1);
}