Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Please fix my problems

0 votes
asked Apr 8, 2020 by pwla mea2546 (120 points)
reshown Apr 15, 2020 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.
...