StudyLover
  • Home
  • Study Zone
  • Profiles
  • Typing Tutor
  • Contact us
  • Sign in
StudyLover Program #32 (U3): Iterate Array via Pointer Arithmetic (find max & index)
Download
  1. C Programming
  2. C Programming Practice
Program #31 (U3): Call by Value vs Reference (swap) : Program #33 (U3): Recursion — Factorial and Fibonacci
C Programming Practice

Task: Use a pointer to traverse the array and find the maximum value and its index. Print both.

 
#include <stdio.h>

 
int main(void) {

    int N, a[200];

    printf("Enter N (1..200): ");

    if(scanf("%d", &N) != 1 || N <= 0 || N > 200){ printf("Invalid N.\n"); return 0; }

    printf("Enter %d integers: ", N);

    for(int i=0;i<N;++i) scanf("%d", &a[i]);

 
    int *p = a, *end = a + N;

    int max = *p, idx = 0, i=0;

    for(; p < end; ++p, ++i){ if(*p > max){ max=*p; idx=i; } }

 
    printf("Max=%d at index %d\n", max, idx);

    return 0;

}

 

 

Program #31 (U3): Call by Value vs Reference (swap) Program #33 (U3): Recursion — Factorial and Fibonacci
Our Products & Services
  • Home
Connect with us
  • Contact us
  • +91 82955 87844
  • Rk6yadav@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website