Write a program that calculate maximum number and it’s index in c
Here is the program that calculate the maximum number and it’s index in c.
This program is quite easy but confusing when you write carelessly because I am also careless in using format specifier for unsigned long long integer so that I have done mistake but you don’t need to get worry but clap this article or like or login in this article don’t forget to follow me:
#include <stdio.h>
#define N 5
int main(void){
unsigned long long int arr[N];
unsigned long long int i, maxIndex, maxNum;
for(i = 0; i < N; i++){
printf(“Enter %lld number with the index %lld: “, i + 1, i);
scanf(“%ll7d”, &arr[i]);
}
maxIndex = 0;
maxNum = arr[0];
for(i = 1; i < N; i++){
if(arr[i] > arr[maxIndex]){
maxIndex = i;
maxNum = arr[i];
}
}
printf(“Index of max digit is: %lld whereas max digit is %lld\n”, maxIndex, maxNum);
return 0;
}
Thanks you from “Himal Aryal”