Course Content
Detailed Content of Programming in C
0/1
Introduction
0/1
Structure of C program
0/1
Answers of ‘C’ Pointers Programs
0/1
About Lesson

Program 1:

C Program to Increment every Element of the array by One & Print Incremented Array.

#include <stdio.h>
int main() {
    int i;
    int array[4] = {10, 20, 30, 40};
    // Increment every element of the array by one
    for (i = 0; i < 4; i++) {
        array[i]++;
    }
    // Print the incremented array
    printf(“Incremented array: “);
    for (i = 0; i < 4; i++) {
        printf(“%d “, array[i]);
    }
    return 0;
}

Output:

Incremented array: 11 21 31 41


Program 2:

C Program to Print the Alternate Elements in an Array. 

#include <stdio.h>
int main()
{
    int array[5]; // Assuming an array of size 10, you can change it as needed
    int i;
    printf(“Enter the elements of the arrayn”);
    for (i = 0; i < 5; i++)
    {
        scanf(“%d”, &array[i]);
    }
    printf(“Alternate elements of the given arrayn”);
    for (i = 0; i < 5; i += 2)
    {
        printf(“%dn”, array[i]);
    }
    return 0;
}

Output:

Enter the elements of the array
2
3
4
5
6
Alternate elements of the given array
2
4
6


Program 3:

C Program to accept N Numbers and arrange them in an ascending order.

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int i, j, a, n, number[30];
    // Input the value of N
    printf(“Enter the value of N: “);
    scanf(“%d”, &n);
    // Input the numbers
    printf(“Enter the numbers:n”);
    for (i = 0; i < n; i++)
        scanf(“%d”, &number[i]);
    // Sorting the numbers in ascending order using bubble sort
    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            // Compare and swap if needed
            if (number[i] > number[j])
            {
                a = number[i];
                number[i] = number[j];
                number[j] = a;
            }
        }
    }
    // Display the numbers in ascending order
    printf(“The numbers arranged in ascending order are:n”);
    for (i = 0; i < n; i++)
    {
        printf(“%dn”, number[i]);
    }
    return 0;
}

Output:

Enter the value of N: 3
Enter the numbers:
1
5
3
The numbers arranged in ascending order are:
1
3
5