Friday, 16 June 2017

Array program in C

/*
    Write a C program using function to
    i)    insert elements into an array.
    ii)    display array elements
    iii)    return maximum element of a array
    iv)    search a element given by the user and return the location of the element. return -1 if element is not found in the array.
    v)    sort the elements in ascending order using "bubble sort".
    vi)    Delete an element from the end of the array.
    vi)    Delete an element from the front of the array.
    vii)    Delete an element from a given position. If given position is not valid return give error message.

    viii)    Add element at the end.
    ix)    Add element at the bigining
    x)    Add an element in a given position. If given position is not valid return give error message.
    xi)    Reverse the elements of the array.
    xii)    Create two arrays from the given array. In the new arrays, one will contain the even elements and other will contain odd elements.
    xiii)    Create two arrays from the given array. In the new arrays, one will contain the positive elements and other will contain negative elements.

*/
#include<stdio.h>
void insert(int [], int );
void show(int [], int );
int max(int [], int);
int search(int [], int,int);
void bubble(int [],int);
void del_end(int [],int *);
void del_front(int [],int *);
void del_pos(int [], int *, int);

void add_end(int [],int *);
void add_beg(int [],int *);
void add_pos(int [],int *);
void reverse(int [],int);
void create_odd_even(int [],int ,int [],int *,int [], int *);
void create_pos_neg(int [],int ,int [],int *,int [], int *);

int main()
{
    int a[100]={1,2,3,4,5,6,7,8},n=8,ele,temp;
    /*printf("\nEnter number of elements=");
    scanf("%d",&n);
    printf("\nEnter the elements=");
    insert(a,n);
    printf("\nThe array is\n");
    show(a,n);*/
    printf("\nThe maximum element=%d",max(a,n));
/*
    printf("\n Enter an element to be searched=");
    scanf("%d",&ele);
    temp=search(a,n,ele);
    if(temp==-1)
        printf("\n%d is not present in the array\n",ele);
    else
        printf("\n%d is present at %d location in  the array\n",ele,temp);
    */
    printf("\nBefore sorting\n");
    show(a,n);
    bubble(a,n);
    printf("\nAfter sorting\n");
    show(a,n);

    del_pos(a,&n,4);
    show(a,n);
    del_pos(a,&n,3);
    show(a,n);
    return 0;
}

void insert(int a[], int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
}

void show(int a[], int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        printf("%10d",a[i]);
    }
    printf("\n");
}

int max(int a[], int n)
{
    int mx,i;
    mx=a[0];
    for(i=1;i<n;i++)
    {
        if(mx<a[i])
            mx=a[i];
    }
    return mx;
}

int search(int a[], int n,int ele)
{
    int i,found=0;
    for(i=0;i<n;i++)
    {
        if(ele==a[i])
        {
            found=1;
            break;
        }
    }
    if(found==0)
        return -1;
    else
        return i;
}

void bubble(int a[],int n)
{
    int i,j,temp;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n-i-1;j++)
        {
            if(a[j]>a[j+1])
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
        }
    }
}

void del_end(int a[],int *n)
{
   
    (*n)--;
}

void del_front(int a[],int *n)
{
    int i;
    for(i=0;i<(*n)-1;i++)
    {
        a[i]=a[i+1];
    }
   
    (*n)--;
}

void del_pos(int a[], int *n, int pos)
{
    int i=pos;
   
    if(pos<0 || pos>=(*n))
    {
        printf("\nEnter a valid position");
        return;   
    }
    if(pos==0)
        del_front(a,n);
    else if(pos==(*n)-1)
        del_end(a,n);
    else
    {
        while(i<(*n)-1)
        {
            a[i]=a[i+1];
            i++;
        }
        (*n)--;
    }
}

Sunday, 19 March 2017

ASTU: Introduction To Computing syllabus

Subject Code : CS131105
Subject: Introduction To Computing
L-T-P: 2-0-0
Credit 2
Expected Weeks :12
 
Modules
Topics
Course Content
Hours
I
INTRODUCTION
Definition of algorithm and computer programming. Use of Flow Charts. Symbols and their uses. Introduction to Editing Tools
2
II
PROGRAM DEVELOPMENT AND PROGRAMMING LANGUAGES
Brief discussion on different types of programming languages. Introduction to C language,
4
III
PROGRAMMING IN C LANGUAGE
Identifiers, data types, operators in C language. Header and Library files. Simple programs using assignment statements
4
IV
CONDITIONAL CONTROL STATEMENTS
If, nested if, switch-case etc. Ex- Conversion between 3◦F & ◦c, Simple Interest, Compound Interest etc.
4
V
ARRAYS:
Definition and example of arrays. Single dimension and multi dimensional arrays. Ex. Sorting in ascending & descending , Minimum & Maximum of an array, Reverse of an array elements, Palindrom, roots of an Second degree equation etc.
4
VI
FUNCTIONS:
Type Of Functions, Function Definition ,Function prototype, declaration, function calling. Formal argument & actual argument. Parameter passing technique.
4
VII
INFORMATION TECHNOLOGY
Elements of Information Technology.

2
Total
36
 
Text/Reference Books:
1. Computer Programming in C (PHI ) Rajaraman
2. Computer Fundamentals and Programming in C(Oxford) – Reema Thareja
3. Mastering C (Tata McGraw Hill) – Venugopal and Prasad
4. Let us C (Bpb) –Yashawant kanetkar
5.Balaguruswamy.


Subject Code : CS131115
Subject: Introduction to Computing Lab
L-T-P: 0-0-2
Credit 1
Expected Weeks :12
 
Experiment
Experiment Title
Hours
I
(a)    Write a program to display Hello World.
(b)   Write a program to find:
   i.            Addition of two numbers
  1. Subtraction of two numbers.
  2. Multiplication of two numbers.
  3. Division of two numbers.
1
II
(a)    Write a program to find area of :
( i)  Rectangle.
(ii) Circle.
(iii) Triangle.
(b) Write a program to find simple interest, compound interest and amount.
1
III
(a)    Write a program to check whether the number is odd or even.
(b)   Write a program to find the greater of two numbers.
(c)    Write a program to do swapping of two numbers using third variable.
(d)   Write a program to find the greatest of three numbers using if else.
1
IV
(a)    Write a program to calculate the sum of all the numbers from 1 to 50 using for loop.
(b)   Write a program to display your name upto 10 times using while loop.
(c)    Write a program to print even numbers from 1 to 50.
1
V
(a)    Write a program to add the digits of a 4 digit number.
(b)   Write a program to covert temperature from C to F and F to C.
(c)    Write a program to check whether a year is leap year or not.
1
VI
(a)    Write a program to display an array of elements.
(b)   Write a program to find the factorial of a number.
(c)    Write a program to print all the numbers divisible by 2 and 3 between 1 and 50.
1
VII
(a)    Write a program to find the greatest among 10 numbers.
(b)   Write a program to perform a multiplication table of a user given number.
(c)    Write a program to reverse a number.
1
VIII
(a)    Write a program to find the area of a triangle,rectangle and circle using switch case.
(b)   Write a program to calculate the grade using nested if and else statements.
(c)    Write a program to perform addition, subtraction & multiplication of two numbers using switch case.
1
IX
(a)    Write a program to find the smallest among 10 numbers.
(b)   Write a program for swapping of two numbers using functions.
(c)    Write a program to find the factorial of a number using function.
1
X
(a)    Write a program to copy a string using library function.
(b)   Write a program to calculate x=a*(b*c)/(b-c).
(c)    Write a program to calculate sum of even numbers from 1 to 50.
(d)    Write a program to find the sum of numbers divisible by 7.
1
XI
(a)    Write a program to display your name upto 10 times using for loop.
(b)   Write a program to find the length of a string using library function.
(c)    Write a program to reverse a string using library function.
(d)   Write a program to concatenate a string using library function.
1
XII
Revision of the Experiments and Internal Viva
1
Total
12