Using an array write a C program that will ask the user to e

Using an array write a C program that will ask the user to enter an integer number. The computer must separate the digits and display them in same order with a space between each digit. For example, if the user enters 237, the computers output should be: 2 3 7. You may use an array now to solve. Id also appreciate it to be as simple as possible, as im am quite new.               

This is the shell im supposed to use:  

int main(void)

{

return 0;

}

Solution

#include <stdio.h>

int main(void) {
int n,i=0;
int arr[100];
printf(\"Enter a number:\");
   scanf(\"%d\",&n);
   while(n!=0){
   arr[i++]=n%10;
   n=n/10;
   }

//Since is incremented one extra time the below loop starts at i-1 i.e.

//the last element which is the first digit of the number
   for(i=i-1;i>=0;i--){
   printf(\"%d \",arr[i]);
   }
   return 0;
}

Using an array write a C program that will ask the user to enter an integer number. The computer must separate the digits and display them in same order with a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site