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 onefor (i = 0; i < 4; i++) {array[i]++;}// Print the incremented arrayprintf(“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 neededint 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 Nprintf(“Enter the value of N: “);scanf(“%d”, &n);// Input the numbersprintf(“Enter the numbers:n”);for (i = 0; i < n; i++)scanf(“%d”, &number[i]);// Sorting the numbers in ascending order using bubble sortfor (i = 0; i < n; i++){for (j = i + 1; j < n; j++){// Compare and swap if neededif (number[i] > number[j]){a = number[i];number[i] = number[j];number[j] = a;}}}// Display the numbers in ascending orderprintf(“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