# How do i create variables according to user input?

How can I create new variables according to a value input by the user?

Please provide some more information like the language and some example where you want to use such kind of problem.

From the given question what I find is you want different variable names according to given input.
One such thing could be done in python :

``````a=input()
if a==1:
b=2
else:
c=1
if 'b' in globals():
print "b declared"
elif  'c' in globals():
print "c declared"
``````

Hope it Helps.

Happy Coding!!!

i want to know how to do it in c. for example, i want to accept user input as to how many people are there in a city and accordingly create variables to store time taken by them to do three things which will be input by user.

@shatakshi3901 As per your above comment, you can take input this manner:

``````scanf("%d",&n);
int a[n+1];
for(int i-0;i<n;i++)
{
scanf("%d %d %d",&a[i], &a[i],&a[i]);
}
``````

This is with reference to your above constraint that you want to take three inputs for each of the n person. Also, you can create separate arrays for the three values.

``````scanf("%d",&n);
int d1[n+1],d2[n+1],d3[n+1];
for(int i-0;i<n;i++)
{
scanf("%d %d %d",&d1[i], &d2[i],&d3[i];
}
``````

Many more ways can be there but all that depends on the factors how you want to manipulate the input or how you want to use that input and how frequently you want to access it. Like in some cases there are situation where the first two inputs have a unique value as the third input. In this case, you can create a map or if integer inputs are there , you can use a 2-d array and store the third input as the value of a[i][j](i refers to first i/p and j to the second i/p).