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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:37:35+00:00 2026-05-24T02:37:35+00:00

I am using Code::blocks to compile my first multiple source file, learned from C

  • 0

I am using Code::blocks to compile my first multiple source file, learned from “C Programming in easy steps” by Mike McGrath. Unfortunately my math functions seem to be having issues. Here’s the header that contains the functions:

/* this header file contains utility functions */

int square(int x);       /* function prototypes */
int multiply(int x, int y);

int square(int x) 
{ 
return (x*x);
}

int multiply(int x, int y)
{
return (x*y);
}

The only function having the problem is “square()”. It reads the input of “2” as “2293356” and outputs the square as “553755367”… What the heck?!?

Here’s the menu.c file… There’s menu.c, ops.c, calc.c, and utils.h. Abaov is the .h.
MENU.c
include

void menu();

void menu()
{

    int num;
    printf("\n\tEnter the number of an operation:\n");
    printf("\t1. Square a number\n");
    printf("\t2. Multiply two numbers\n");
    printf("\t3. Exit\n");
    scanf("%d", &num);
    switch(num)
    {
    case 1 : getnum(); break;
    case 2 : getnums(); break;
    case 3 : return;
    }
}

Here’s ops.c…

#include <stdio.h>
#include "utils.h"

void getnum();
void getnums();

void getnum()
{

    int num;
    printf("Enter an integer to be squared: ");
    scanf("%d", &num);
    printf("%d squared is %d\n, num, square(num)");
    menu();
}

void getnums()
{

    int num1, num2;
    printf("Enter two numbers to be multiplied, ");
    printf("seperated by a space: ");
    scanf("%d", &num1);
    scanf("%d", &num2);
    printf("%dx%d = %d\n", num1, num2, multiply(num1, num2));
    menu();

}

This is the last part of the program, calc.c,

#include <stdio.h>
int main()
{
    menu();
    printf("end\n");
    return 0;
}
  • 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-24T02:37:36+00:00Added an answer on May 24, 2026 at 2:37 am

    The square of 2293356 doesn’t fit into int and therefore overflows which leads to undefined behavior! As to why it reads 2 as 2293356 cannot be answered without more code.

    Update:
    And here’s your real error:

    printf("%d squared is %d\n, num, square(num)");
    

    should be

    printf("%d squared is %d\n", num, square(num));
    

    🙂

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

Sidebar

Related Questions

Using the code below, I am returning an nvarchar field from MS SQL 2005
I'm using regular expressions to try to match section blocks in an INI file.
I'm trying to compile my first legit program that I'm converting from Java (I
I'm learning about strings in c. I am using code::blocks as a compiler, even
Using Vim I often want to replace a block of code with a block
I'm using code that I found on the CodeProject.com for a low-level keyboard hook
I've recently started using code coverage tools (particularily Emma and EclEmma), and I really
I have been using code similar to this MessageDlg('', mtWarning, [mbOK], 0); throughout my
I'm using code that takes a bitmap and converts it to 24 BPP so
using the Code Snippet for sending email in VB.Net I have successfully sent an

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.