๐Ÿ’ป
B.TECH I YEAR โ€ข I SEMESTER โ€ข R25

Programming for Problem Solving - Lab Manual

C Programming Laboratory โ€ข Program Solution

๐Ÿ“˜ R25 Regulation ๐ŸŽ“ I Year ๐Ÿ“š I Semester ๐Ÿ’ป C Programming ๐Ÿงช Lab Program
Selected Program

Write a C program for reading elements using a pointer into an array and display the values using the array.

โ† All Lab Programs

Write a C program for reading elements using a pointer into an array and display the values using the array.

Algorithm

start
	step1: 
	step2: 
	step3: 
	step4: 
	step5: 
	step6: 
	step7: 
	step8: 
	step9: 
	step10:
stop

Flowchart


C Programming
//reading elements using a pointer into an array and display the values using the array.
#include <stdio.h>

int main() {
    int n, sum = 0, arr[10];

    // Input the number of elements
    printf("Enter the number of elements: ");
    scanf("%d", &n);

    int *ptr = arr;  
    
     printf("Enter the elements:\n");
    for (int i = 0; i < n; i++) {
        // Read element using the pointer
        scanf("%d", ptr + i);  // Pointer arithmetic to read the value
    }

    // Display the values using the array
    printf("The elements are:\n");
    for (int i = 0; i < n; i++) {
        printf("%d ", arr[i]);  // Display elements using the array
    }

    return 0;
}

OUTPUT
Enter the number of elements: 5
Enter the elements:
2 4 6 8 10
The elements are:
2 4 6 8 10 

๐Ÿ’ป Run This C Program

Write a C program for reading elements using a pointer into an array and display the values using the array.
The selected C program is loaded automatically. Edit the code, provide input through STDIN and click Run.

The compiler is embedded using OneCompiler. Your program runs in the embedded C environment; Study Glance does not execute C code directly on your web server.
โ† Back to PPS Lab Programs ๐Ÿ“š All Lab Manuals