C Program to Convert MB to KB

In this post, you will learn how to convert MB to KB using C Programming language.

This program asks the user to enter the size in Megabytes, then it converts the size into Kilobytes using the factor: 1 Megabyte = 1024 Kilobytes.

So, without further ado, let’s begin this tutorial.

C Program to Convert MB to KB

// C Program to Convert MB to KB
#include <stdio.h>
int main(){
    int mb, kb;
    
    // Asking for input
    printf("Enter the size in MB: ");
    scanf("%d", &mb);
    
    // MB to KB Conversion
    kb = mb * 1024;
    
    // Displaying output
    printf("%d Megabytes = %d Kilobytes", mb, kb);
    return 0;
}

Output

Enter the size in MB: 4
4 Megabytes = 4096 Kilobytes

How Does This Program Work ?

    int mb, kb;

In this program, we have declared two int data type variables named mb and kb.

    // Asking for input
    printf("Enter the size in MB: ");
    scanf("%d", &mb);

Then, the user is asked to enter the size in Megabytes.

    // MB to KB Conversion
    kb = mb * 1024;

We convert MB to KB using the factor: 1 MB = 1024 KB.

    // Displaying output
    printf("%d Megabytes = %d Kilobytes", mb, kb);

At the end, the converted size is displayed on the screen using printf() function.

Conclusion

I hope after going through this post, you understand how to convert MB to KB using C Programming language.

If you have any doubt regarding the program, then feel free to contact us in the comment section. We will be delighted to solve your query.

Also Read:

Leave a Comment

Your email address will not be published. Required fields are marked *