ankitweblogic logo
W e b t u t o r i a l s

C Tutorial

Programing Approach

Algorithm

Flow Chart

Define C

Define Programming

C - Syntax

Compiler vs Interpreter

C - Variables

C - Keywords

C - Data Types

C - Comments

Turbo C - Shortcut keys

C - Operators

Hierarchy of Operators

Ex: Arithmetic Operator

C - Formatting Output

Constant Variable

C - Escape Sequence

C - if , switch

Ex: If condition

Ex: Inc / Dec Operator

C - loops

Ex: Loops

C - Nesting Of loops

Ex: Nested Loops

Jumping Statements

C - Arrays 1D

C - Arrays 2D

C - Sorting

ASCII Value

Character I/O Function

C - String Functions

Ex: Strings

Array of Strings

C - Math Functions

User-defined Function

Exercise Function

C - Types of Functions

Storage Class

C - Header Files

C - Preprocessor

C - Pointers

C - Structures

C - Typedef

C - File Handling

Ex: File Handling

Command Line Argument

MCQ

C - Arrays 1D

Arrays are the collection of variables of similar data type. For example an int array holds the elements of int types while a float array holds the elements of float types. All arrays consist of contiguous memory locations.

To declare an array, specify a variable name with its data type and the number of elements in square brackets

int arr[5];
1D Array

Array index is started from 0 and there is no limit of maximum value.

Exercise Questions : 1D - Array

  1. Input 10 numbers in array and find sum.
  2. #include<stdio.h>
    #include<conio.h>
    int main()
    {
        int a[10], i, sum=0;
    	clrscr();
        printf("Enter 10 numbers: ");
        for(i=0;i<=9;i++)
        {
            scanf("%d",&a[i]);
        }
        for(i=0;i<=9;i++)
        {
            sum = sum + a[i];
        }
        printf("Sum = %d", sum);
        getch();
    }
  3. Input 10 numbers in array and find average.
  4. Input 10 numbers in array and find largest number.
  5. #include<stdio.h>
    #include<conio.h>
    //input 10 nos in array and find greater
    void main()
    {
        int a[10], i, l=0;
        clrscr();
        printf("Enter 10 nos");
        for(i=0;i<=9;i++)
           scanf("%d",&a[i]);
        for(i=0;i<=9;i++)
        {
           if(l<a[i])
             l = a[i];
        }
        printf("Largest = %d",l);
        getch();
    }
  6. Input 10 numbers in array and find smallest number.
  7. Input 10 numbers in array and find sum of odd and even numbers separately.
  8. #include<stdio.h>
    #include<conio.h>
    //sum odd and even
    void main()
    {
        int a[10], i, odd=0, even=0;
        clrscr();
        printf("Enter 10 nos");
        for(i=0;i<=9;i++)
        scanf("%d",&a[i]);
    
        for(i=0;i<=9;i++)
        {
            if(a[i]%2==0)
            {
               even = even + a[i];
            }
            else
            {
               odd = odd + a[i];
            }
        }
        printf("\nSum of odd no = %d",odd);
        printf("\nsum of even no = %d",even);
        getch();
    }
  9. Reverse the array list.
  10. Merge 2 arrays in a sorted order.
  11. Merge 2 arrays uniquely.
  12. Insert, delete, update an element in an array.
  13. WAP that splits an array into odd and even numbers.
  14. Find factorial of each number stored in array.