hi guys
i was doing a exercise about invert an integer,but i have to do this using vectors .
example 321 will be 123
I did the program, it worked, but when I put a number with 3 digits or more, the last digit does not appear.
Someone can help me ?I'm not understanding the problem
thank u
my code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int n,cifra,i;
int *v;
v =(int*) malloc (n*sizeof(int));
printf("put a number:");
scanf("%i",&n);
for (i=0;i<n;i++) {
cifra=n%10;
n=n/10;
v[i]=cifra;
printf("%i",v[i]);}
return 0;}
i know how to do using loop ,but i need to do using vector
if I understand correctly you want to take the number and place each digit into a cell of a vector?
so if you have the number 1234
you want the vector to look like this?