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

  • SEARCH
  • Home
  • 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 7752311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:46:01+00:00 2026-06-01T11:46:01+00:00

I’m doing a homework assignment for my course in C (first programming course). Part

  • 0

I’m doing a homework assignment for my course in C (first programming course).
Part of the assignment is to write code so that a user inputs a number up to 9 digits long, and the program needs to determine whether this number is “increasing”/”truly increasing”/”decreasing”/”truly decreasing”/”increasing and decreasing”/”truly decreasing and truly increasing”/”not decreasing and not increasing”. (7 options in total)

Since this is our first assignment we’re not allowed to use anything besides what was taught in class:

do-while, for, while loops, else-if, if,
break,continue
scanf, printf ,modulo, and the basic operators

(We can’t use any library besides for stdio.h)

That’s it. I can’t use arrays or getchar or any of that stuff. The only function I can use to receive input from the user is scanf.

So far I’ve already written the algorithm with a flowchart and everything, but I need to separate the user’s input into it’s distinct digits.

For example, if the user inputs “1234…” i want to save 1 in a, 2 in b, and so on, and then make comparisons between all the digits to determine for example whether they are all equal (increasing and decreasing) or whether a > b >c … (decreasing) and so on.

I know how to separate each digit by using the % and / operator, but I can’t figure out how to “save” these values in a variable that I can later use for the comparisons.

This is what I have so far:

printf("Enter a positive number : ");

do {
    scanf ("%ld", &number);
    if (number < 0) {
        printf ("invalid input...enter a positive integer: ");
        continue;
    }
    else break;
} while (1);

while (number < 0) {
    a = number % 10;
    number = number - a;
    number = number / 10;
    b = a;
}
  • 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-06-01T11:46:02+00:00Added an answer on June 1, 2026 at 11:46 am

    Why not scan them as characters (string)? Then you can access them via an array offset, by subtracting the offset of 48 from the ASCII character code. You can verify that the character is a digit using isdigit from ctype.h.


    EDIT

    Because of the incredibly absent-minded limitations that your professor put in place:

    #include <stdio.h>
    
    int main()
    {
      int number;
      printf("Enter a positive number: ");
    
      do
      {
        scanf ("%ld", &number);
        if (number < 0)
        {
          printf ("invalid input...enter a positive integer: ");
          continue;
        }
        else break;
      } while (1);
    
      int a = -1;
      int b = -1;
      int c = -1;
      int d = -1;
      int e = -1;
      int f = -1;
      int g = -1;
      int h = -1;
      int i = -1;
    
      while (number > 0)
      {
        if (a < 0) a = number % 10;
        else if (b < 0) b = number % 10;
        else if (c < 0) c = number % 10;
        else if (d < 0) d = number % 10;
        else if (e < 0) e = number % 10;
        else if (f < 0) f = number % 10;
        else if (g < 0) g = number % 10;
        else if (h < 0) h = number % 10;
        else if (i < 0) i = number % 10;
    
        number /= 10;
      }
    
      /* Printing for verification. */
    
      printf("%i", a);
      printf("%i", b);
      printf("%i", c);
      printf("%i", d);
      printf("%i", e);
      printf("%i", f);
      printf("%i", g);
      printf("%i", h);
      printf("%i", i);
    
      return 0;
    }
    

    The valid numbers at the end will be positive, so those are the ones you validate to meet your different conditions.

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

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.