Find the Biggest Number in C, BUT with characters

You need to ask the user for the number that they want to insert.
Once given this you need to set the size of your arrays because you do not know their size until afterward

#include <stdio.h>

int main() {
  int i;
  int maxAge = 0, maxName = -1;
  int numberOfPeople = 0;
  scanf("%d", & numberOfPeople);
  //now we have to set the arrays to the size that we are inserting
  char peopleName[numberOfPeople][20], peopleAge[numberOfPeople];

  for (i = 0; i < numberOfPeople; i++) {
    printf("Name & Age %d :", i + 1);
    scanf("%s", & peopleName[i]);
    scanf("%d", & peopleAge[i]);
    if (peopleAge[i] > maxAge) {
      maxAge = i; //you had the actual age here, 
      //but you need the index of the highest age instead
      maxName = i;
  printf("%s %d", peopleName[maxName], peopleAge[maxAge]);

Browse More Popular Posts

Leave a Comment