Please fix my problems

0 votes
asked Apr 8 by pwla mea2546 (120 points)
reshown Apr 15 by pwla mea2546
Write a C  program that reads from the keyboard a natural number n with up to 9 digits and creates the text file data.out containing the number n and all its non-zero prefixes, in a single line, separated by a space, in order decreasing in value. Example: for n = 10305 the data file.out will contain the numbers: 10305 1030 103 10 1.

Program in C++:

#include <fstream>
#include <iostream>
using namespace std;
int main()
{
    unsigned long n;
    cin>>n;

   //I declare the file f and open it for data writing
   ofstream fis("file.out");
   while(n!=0)   
   {
   //write the number in the file, then delete the last digit
   fis<<n<<'\n';
   n=n/10;   
   }
   fis.close();
   return 0;
}

That's what i made in C:

#include <stdio.h>
#include <string.h>

int main()
{
    int n;
    scanf("%d",&n);
   FILE *f;
   f=fopen("date.out","w");
   while(n!=0)   
   {
   printf(n);
   f=fopen("date.out", "r");
   n=n/10;   
   }
   fclose(f);
   return 0;
}

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...