In: Computer Science
I need to write a program in C with the following specification
* Line one of the standard input will have the total number of people which must not be greater than 10
* Each of the subsequent lines of input will be the first name of a person and their number (ex. "Adam 85") one space between name and number
* Each name must be a maximum of 14 characters
* Put the first names into an array called names
* Put the numbers into an array called numbers
* This task must be done in a function (named getNumbers) invoked in the main
follow is the program as per your requirements if you have to need any help then comment it below...
Given:
* Line one of the standard input will have the total number of people which must not be greater than 10
* Each of the subsequent lines of input will be the first name of a person and their number (ex. "Adam 85") one space between name and number
* Each name must be a maximum of 14 characters
* Put the first names into an array called names
* Put the numbers into an array called numbers
* This task must be done in a function (named getNumbers) invoked in the main
The program here:-
#include<stdio.h>
void getNumbers(int numbers[],int number,int i) //this function gives number and put into numbers[] array...
{
numbers[i]=number;
}
int main()
{
int totalpeople,number; //variables for program that is total number of people ...
printf("enter total number of people must not greater than 10\n");
scanf("%d",&totalpeople); //give input total number of peoples which is less than 10...
char names[totalpeople][14]; //array for store the name of every person ...
int numbers[totalpeople]; //array for store the number of each person...
for(int i=0;i<totalpeople;i++)
{
printf("enter firstname and number of person\n");
scanf("%s", names[i]);
scanf("%d",&number);
getNumbers(numbers,number,i); //function is invoked from main function to store number into array...
number=0;
}
printf("here you can show both arrays firstname and numbers\n");
for (int i = 0; i < totalpeople; i++) //display all value of both array ....
{
printf("%s", names[i]);
printf(" ");
printf("%d\n", numbers[i]);
}
return(0);
}
program:-
Output:-