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 9281063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:01:32+00:00 2026-06-18T18:01:32+00:00

I have an assignment that requires me to take a single scanf and perform

  • 0

I have an assignment that requires me to take a single scanf and perform some math operations to several integers. The first number in the input sets the number of integers to follow ie: 3 45 67 18 should be interpreted as N var1 var2 var3 and 4 100 23 76 92 should be interpreted as N var1 var2 var3 var4. I couldnt make the program as instructed on my first iteration but it does work as its supposed to. I accomplish storing var1 var2… varN by simply putting scanf in a loop that runs N times and storing the remaining numbers in an array n[1000]. Like I said the program works… sorta, but it doesnt work the way the assignment instructed. The sample run provided by the assignment should be:

Please enter n followed by n numbers: 3 6 12 17

Test case #1: 6 is NOT abundant.
Test case #2: 12 is abundant.
Test case #3: 17 is NOT abundant.

My program output is:

Please enter n followed by n numbers: 3
6
12
17
Test case #1: 6 is NOT abundant.
Test case #2: 12 is abundant.
Test case #3: 17 is NOT abundant.

Here is the link to my program.
I have read through many of the similar questions, but most seem to trivialize the use of scanf as opposed to other methods of capturing input from the console. This post is extremely close to the answer that I am looking for except I need a dynamically set number of variables. I have a feeling I need to use the malloc function but im just not quite sure how to use it for this and still accomplish a single line of scanf input.

Thanks

  • 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-18T18:01:33+00:00Added an answer on June 18, 2026 at 6:01 pm

    The following code worked for me:

    #include <stdio.h>
    #include <stdlib.h>
    
    
    int main(void)
    {
        int n[1000],i,j,sum,size;
    
        printf("Please enter n followed by n numbers: ");
        scanf("%d",&n[0]);
    
        for (i=1;i<=n[0];i++)
                scanf("%d",&n[i]);
    
            /* Debug: Automatically generate numbers from 1 to n[0] */
            //n[i]=i
    
        for (i=1;i<=n[0];i++)
        {
            /* Debug: See what numbers are being used in sum - Part 1*/
            //printf("\nFactors < %d of %d: ",n[i]/2,n[i]);
            sum=0;
            for (j=1;j<=n[i]/2;j++)
            {
    
                if (n[i]%j==0)
                {
                    /* Debug: See what numbers are being used in sum - Part 2*/
                    //printf("%d ",j);
                    sum+=j;
                }
    
            }
            printf("Test case #%d: %d is%sabundant.\n",i,n[i],(sum>n[i])?" ":" NOT ");
    
            /* Debug: See what numbers are being used in sum - Part 3*/
            //printf("(%d)\n",sum);
        }
        system("PAUSE");    
        return 0;
    }
    

    Aslai your answer had me perplexed because i couldnt see how your code would accomplish anything different from what i did. So while I was debugging to see what scanf returned I noticed scanf actually returns after every space instead of on “enter” or “\n” like I thought. So I simplified my first for loop and everything works. So am I correct in saying that input from one scanf will satisfy variable assignments to subsequent scanf’s as long as there are sufficient subsequent calls to scanf? In other words if I entered 3 25 17 during a single scanf I can then assign each of those numbers to variables with subsequent scanf calls without having to pressing enter?

    scanf("%d",&var1); //(where var1=3)
    scanf("%d",&var2); //(where var2=25) 
    scanf("%d",&var3); //(where var3=17)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assignment that requires me to first set up integer arrays to
My assignment requires that I have an ER diagram that shows the dependencies between
I have quite a large XSL document for an assignment that does a number
In my programming class we currently have a project that requires us to take
I have an assignment that requires us to implement a doubly linked list class.
I have this assignment due that requires the usage of FLTK. The code is
I have a class that requires a non-default copy constructor and assignment operator (it
Basically, I have an assignment that requires me to find the mode of a
So I have an assignment for school that requires me to create a fixed
So, a long story short, I have a Java homework assignment that requires a

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.