Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 414561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:17:41+00:00 2026-05-12T18:17:41+00:00

void distinct (void) { char sent; int n1, n2, n3, n4, n5, n6, n7;

  • 0
void distinct (void) {
 char sent;
 int n1, n2, n3, n4, n5, n6, n7;
 FILE *fp2 = fopen ("distinct.txt", "w");

 while (sent != 'n') {
  for (n1=2;n1<=9;n1++) {
   for (n2=2;n2<=9;n2++) {
    if (n2 != n1) {
     for (n3=2;n3<=9;n3++) {
      if (n3 != n2 && n3 != n1) {
       for (n4=2;n4<=9;n4++) {
        if (n4 != n3 && n4 != n2 && n4 != n1) {
         for (n5=2;n5<=9;n5++) {
          if (n5 != n4 && n5 != n3 && n5 != n2 && n5 != n1) {
           for (n6=2;n6<=9;n6++) {
            if (n6 != n5 && n6 != n4 && n6 != n3 && n6 != n2 && n6 != n1) {
             for (n7=2;n7<=9;n7++) {
              if (n7 != n6 && n7 != n5 && /* you get the idea */ && n7 != n1) {
               fprintf (fp2, "%d", n1);
               fprintf (fp2, "%d", n2);
               fprintf (fp2, "%d", n3);
               fprintf (fp2, "%d", n4);
               fprintf (fp2, "%d", n5);
               fprintf (fp2, "%d", n6);
               fprintf (fp2, "%d\n", n7);
              }
             }
            }
           }
          }
         }
        }
       }
      }
     }
    }
   }
  }
  printf ("Press any key to continue or 'n' to stop writing the file\n");
  scanf ("%c", &sent);
 }
 fclose (fp2);
}

I want the loop to pause whenever the first digit changes to ask whether to continue or stop.

2xxxxxx
2xxxxxx
2xxxxxx
Press any key to continue or 'n' to stop writing the file
    // continues if 'y' is entered //
3xxxxxx
3xxxxxx
3xxxxxx
Press any key to continue or 'n' to stop writing the file
    // stops when 'n' is entered //

The program I wrote doesn’t work as I wish…T___T

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:17:41+00:00Added an answer on May 12, 2026 at 6:17 pm

    I think in terms of readability, you’re better putting it at the top of the relevant loop. Get rid of the outer while altogether and change:

    char sent;
    : :
    for (n1=2;n1<=9;n1++) {
        for (n2=2;n2<=9;n2++) {
    

    into:

    char sent[100];
    : :
    for (n1=2;n1<=9;n1++) {
        if (n1 > 2) {
            printf("press any key to continue or 'n' to stop writing the file\n");
            scanf("%s",sent);
            if (*sent == 'n') break;
        }
        for (n2=2;n2<=9;n2++) {
    

    The change of sent from a character to a string is so you don’t need to worry about getting linefeeds as characters (if you type yENTER, you’ll get the next two sections since y is one character and ENTER is another – even worse if you enter yesENTER). The use of a fixed size string and scanf() is dangerous however and shouldn’t be used in production code. I include it here only yo make your life a little easier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

void test() { unsigned char c; c = (~0)>>1 ; printf(c is %u\n,c); }
I need use this method with three distinct classes: Orders, Customers, Suppliers public void
- (void)TargetHit:(int)target{ void (^threadBlock)(void) = ^{ NSLog(@respond to selector %d, [self respondsToSelector:@selector(changeImageOfTarget:)]); [[NSOperationQueue mainQueue]
void foo(Node* p[], int size){ _uint64 arr_of_values[_MAX_THREADS]; for (int i=0 ; i < size
void say(char msg[]) { // using pointer to print out the first char of
The following code is in my switchviewcontroller.m file - (void)viewDidLoad { MainView *mainController=[[MainView alloc]
void outputString(const string &ss) { cout << outputString(const string& ) + ss << endl;
#include <stdio.h> #include <string.h> #define MAXLINES 5000 char *lineptr[MAXLINES]; int readlines(char *lineptr[], int nlines);
- (void)viewDidLoad{ [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource:@VidName ofType:@mov]; NSURL *url =
- (void)connectionDidFinishLoading:(NSURLConnection *)connection { self.listFeedConnection = nil; // release our connection [UIApplication sharedApplication].networkActivityIndicatorVisible =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.