Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C++
#include<stdio.h>

int main ()
{
   char n[1000];

   printf("Please enter the number of integers you wish to enter\n");
   scanf("%s", n);

   printf("%s", n);

   return 0;
}


Solution that i want
Please enter the number of integers you wish to enter: 5
Please enter the numbers:
5
5
5
5
5
Posted
Updated 9-Oct-15 14:41pm
v2
Comments
Dave Kreskowiak 9-Oct-15 21:04pm    
and the problem would be ........?
Patrice T 9-Oct-15 21:21pm    
Try to write a couple sentences explaining what you want and what you get.

You should also follow more tutos on C and/or read documentation.

You need to use two different variables, one to hold the number of integers and one array to hold the entered values.

For example:
C++
int numberOfIntegers = 0;
int enteredValues[50];   // This should normally be a dynamic array and you could use
                         // calloc to create enough memory to hold the number of values

Code to get the number of integers:
C++
printf("Please enter the number of integers you wish to enter\n");
scanf("%d", &numberOfIntegers);


When you know the number of integers, you can use a loop to ask the user to input the correct number of values and store them in the array.

Don't forget to check that the number of integers are smaller than the length of the array.
 
Share this answer
 
v2
First of all the datatype used for integer values is int and not char.Please use %d(control string) for accepting integer values and %s usually meant for char(datatype for character). You can make use of for loops for getting the integers as per you wish.

Kindly use this for your reference:

C#
#include<stdio.h>

int main ()
{
   int n,i,values;
   printf("Please enter the number of integers you wish to enter\n");
   scanf("%d",&n);
   printf("please enter the numbers");
  for(i=0;i<n;i++)
  {
       scanf("%d",&values);
}
return 0;
}



please note:

here I have declared three integer variables.The variable n is used for getting the number of integers you wish to enter and the variable i is used for executing the for loop till it satisfies n and the third variable values is used for getting your inputs.
Kindly make use of these links for additional reference:
http://fresh2refresh.com/c/c-printf-and-scanf/[^]
http://fresh2refresh.com/c/c-data-types/[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900