UPDATED:

How To Make A Simple Calculator By C Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... This blog is under construction!!!!
Namecheap.com
Showing posts with label learn programming. Show all posts
Showing posts with label learn programming. Show all posts

Friday, December 23, 2016

Variables and Constants

Data must be stored continuously during the program sequence or data must be read in. When the user makes an input, this input must be stored somewhere in order to be able to evaluate it later. To store data, there are basically two possibilities: storage in memory or in a file. A database is ultimately only one file.

The main memory has two main problems: it is volatile, so the data is lost at the latest when you turn off the PC. And its capacity is usually too limited to accommodate larger amounts of data. The latter is increasingly relativized by falling prices for memory modules, but compared to hard disk sizes it is still "small". In addition, the requirements are always increasing with the calculation work. 

But the memory has an advantage: It is fast! Much faster than any hard drive. How fast depends on the type of memory and its construction. In principle, the closer to the processor, the faster the memory module should be. So L1 cache before L2 cache before RAM modules. This topic is not intended to deal with this issue.

To process data, you will always load it into the working memory. At least part of it, depending on the size of the data and the available memory. If data are also available after the end of the program, they are stored in a file or transferred to a database management system. I will treat the file access in a later post.

Now to the actual topic:  To store data in the working memory, one needs in the programming variables. 
Variables are certainly known to you from mathematics. Here they stand for placeholders. This is similar in programming. A variable reserves a certain amount of memory in memory. Thus, a variable can reserve about two bytes, in which data can then be stored.

Variables can be of different types (data types). Depending on the type, the reserved memory space is of a different size and different data can be stored. For example, variables of type int have a size of 2 or 4 bytes. How much accurately depends on the word length of the processor register and the compiler used. A register is an internal memory space of a processor. This is the fastest available memory for the CPU. For this purpose, the number of registers and thus the memory size is strongly limited. Say: There are only a few.

You can determine how much memory a variable actually needs on your system using the size of operator (more on this later). Depending on the type, however, not only a differently large memory space is reserved, but different values can also be stored. For example, int can only store integers (about -10, 12, or 20007, and you will see that characters such as "a" can be stored as a number); floating-type variables record floating-point numbers (about 1.3, 40.345313) can.

Constants must be distinguished from variables. A constant corresponds to a variable, but with a fixed, non-variable value. This means that a constant must be initialized (defined) at its declaration. So if you want a constant, you must assign a value to it. And it keeps this as long as it exists (which does not necessarily have to be the end of the program).

C compilers do not complain about this (no error, no warning) if you do not perform the initialization, but you can not begin with the constant at a later time. For example, if you try to assign a value to the constant a, you get the error message from GCC: Error: assignment of the read-only variable »a«. You only have the "opportunity" at the declaration.

A declaration is the announcement to the compiler that something (here: the variable) exists. If a is declared as int, the compiler knows: The variable a exists and has the type int. If a variable is assigned a value before its use, especially at the declaration (ie an initial value), it is referred to as an initialization.

If a value is assigned, it is called a definition. Initialization is a special form of definition. As far as the linguistic subtleties that had to be mentioned. As shown in Fig.

Declaration
Notification, e.g. Tell the compiler that a variable exists, which identifier (name) it carries, and what type it is.
Definition
value assignment, e.g. A previously declared variable is now assigned a value.

To declare a variable, you need to know two things:

How do I call my variable? Each variable requires a name (identifier), which can be used to address them. What is my variable to be? Depending on which values are to be stored, a different type must be selected. Sometimes it is also necessary to consider the storage space consumption. When you choose the name (identifier), you are bound by some rules. The name can only consist of alphanumeric characters (such as "a", "X" or "3", BUT NOT "§" or "$"), and the underscore "_". The name must start with a letter or the underline. There must therefore be no number at the beginning of the name.

By default, the identifier should not contain more than 32 characters. In addition, there are some other things to consider that make sense, but are not a duty. The identifier should be as meaningful as possible so that you can know later what the variable is good for. This is difficult for variables such as a, k1, j, and y3.

The identifier should therefore indicate the purpose of the variable. The purpose of the data storage is, of course, clear, but the question arises, which data should be stored and when and why the variable is used. However, try to keep the length of the identifier as short as possible. So as short as possible, as long as necessary.

So better count than This_is_my_newvariable as an identifier. Count variables are often also designated with the letters i, j, k, etc. Here, therefore, only i (like index) would be used.

Let's look at a variable declaration:

Int i;

You already know the integer type int. From this, the variable i exists after this line. The declaration is indicated by a semicolon; completed. In general it can be said:

Type identifier;

Several variables can be easily declared in one line. Example:

Int a, b, c;

As you can see, each identifier must be separated by commas. In the example above, the variables a, b, and c were declared int (each type int). If you also need one or more variables of a different type, this declaration must be placed in an extra line. Such as:

Int a, b, c;
Char z;

Here the variable z of type char was also declared. Because char is a type other than int, the declaration must be on its own line. In principle, you could also write the second declaration in the same line if it is after the semicolon. There is the semicolon.

IMPORTANT: In ANSI-C (C89 / C90), it is not allowed to simply place the variable declaration anywhere in the statement block. Declarations must ALWAYS be at the beginning of an instruction block. 
Example:

Int main ()
{
  Int a, b, c;
  Char z;

  / * Only now follow further instructions ... * /

  Return 0;
}


Attention: The next two programs contain an error!
These examples will not work with real (older) C compilers.

Example 1:

#include <stdio.h>

Int main ()
{
  / * ERROR: Program code BEFORE the variable declaration! * /
  Printf ("The program has started ...");

  Int a, b, c; / * The declaration is only made here ... /
  Char z;

  / * Only now follow further instructions ... * /

  Return 0;
}

Example 2:

Int main ()
{
  ; Int a, b, c; / * Pay attention to the semicolon at the beginning! * /
  Char z;

  / * Only now follow further instructions ... * /

  Return 0;
}

In Example 1, you will probably find the error easier than in Example 2. In the first example, there is an entire "meaningful" statement before the variable declaration. In the second example, the programmer is much more difficult. The only thing that is wrong here is a "lost" semicolon. It is before the variable declaration and is therefore considered by the compiler as an entire statement. Therefore, a mistake.

By the way: The line / * Only now follow further statements * / is marked with / * and * / as comment. Comments are ignored by the compiler. I'll go into later.

Now to practice: 

All upper "wrong" examples work with GCC - without error messages, without warnings. This is because GCC is also a C ++ compiler and also supports the newer C standards. As of C99, variable declarations are no longer required at the beginning of the statement block. In C ++ anyway not. Even with the command-line parameter -std = c89, the source code can be easily translated. GCC should still allow newer extensions as long as they do not conflict with the old C standard. The "error simulation" becomes perfect only if you also add the parameter -pedantic.

If you want to test an old, ancient C compiler, you can try Borland Turbo C. But please do not make any complaints to me, something should not work as desired (or Turbo C do not run). ;-) Turbo C comes in version 2 from the year 1989. Turbo C also knows no new standards guaranteed.

Although this is not the case, in this tutorial, variable declarations are always at the beginning of an instruction block. If you want to write pure C code, you should do that too.

A constant is declared by placing the const keyword before the type. Keywords are reserved identifiers. These are names that you can not use as identifiers. They may, for example, Do not declare a variable with the name "const". An example of a constant:

Const float PI = 3.14159;

Here the constant PI was declared and initialized (defined). Otherwise, the same applies to the declaration of variables.

Thursday, June 2, 2016

How to find circle area using πr ² formula in C

πr² is a common formula to us.But can you find a circle area value by C?
if not,try this.It's help you to know how to find/print the value of a circle 
area in C programming language.


Code to print the value:


#include<stdio.h>

#define PI 3.1416

int main()
{
    float circle_area, r;

    printf("Enter the value of radius: \n");
    scanf("%f", &r);

    circle_area = PI *r * r;

    printf("The circle area is: %.2f\n", circle_area);


return 0;

}


OR,


#include<stdio.h>



int main()

{
    float circle_area, r, PI=3.1416;

    printf("Enter the value of radius: \n");

    scanf("%f", &r);

    circle_area = PI * r * r;


    printf("The circle area is: %.2f\n", circle_area);



return 0;


}


The Output is:




Face problems?No problem.You can share your problems by commenting below.or you can leave a massage us.Thank you.

make a currency converter By C programming language

We can make a simple currency converter by C programming language.

Lets see the code:

#include <stdio.h>
double convert(void);
int main(void){

    double taka;

    taka=convert();
    printf("In taka= %0.2lf\n",taka);

    return 0;
}

double convert(void)
{
    double dollars,multi_value;
    multi_value=80.0;

    printf("enter dollar amount: \n");
    scanf("%lf", &dollars);

    return dollars*multi_value;

}

Output:

It is really great.But if you face any problem or have any question,please comment below.

Thursday, May 26, 2016

How to make simple calculator by C

We are going to make a simple calculator by C.By this calculator we can do summation,subtraction,multiplication and division.Lets have a look to the program.


how to make a simple calculator by c
#include <stdio.h>
#include <conio.h>

int main()
{
    float a,b,sum,sub,mul,div;
    char ch;

    printf("Enter a number: \n");
    scanf("%f", &a);

    printf("Enter another number: \n");
    scanf("%f", &b);

    sum=a+b;
    sub=a-b;
    mul=a*b;
    div=a/b;

    printf("What do you want?\n");
    printf("a: summation.\t b: subtraction.\nc: multiplication.\t d: division.\n");

    scanf(" %c",&ch);

    if(ch == 'a')
    {

        printf("summation value: %.2f\n",sum);

    }
    else if(ch == 'b')
    {

        printf("subtraction value: %.2f\n",sub);

    }
       else if(ch == 'c')
    {

        printf("multiplication value: %.2f\n",mul);

    }
       else if(ch == 'd')
    {

        printf("division value: %.2f\n",div);

    }
    else
    {

        printf("something went wrong!!\n");
    }

    return 0;
    }


Now Try it by yourself.If you face any problem and you have any question regarding the program you can comment below.
Thank you.

Friday, March 4, 2016

Summation,Subtraction,Multiplication and Division by C

Now we are going to do summation with C.Write down the following program and compile it.Then see what happen.


Program Code


#include <stdio.h>
int main ()
{
    int a;
    int b;
    int sum;
    a = 50;
    b = 60;
    sum = a + b;
    printf("sum is %d",sum);
    return 0;
}





Program details:

At first we named three variables as our wish.I took a,b, and sum.Here i assigned 50 for a and 60 for b.sum= a+b means i assigned a value in sum which is equal to a+b.You already know about the printf function.Here it commanded to print the value of sum.

Work for you:

Now you have to do subtraction,multiplication and division following this program.When you done post your program in comment box here or in our facebook group Coder Mania BD.

## If you face any problem with C program join our facebook group C Clinic by Coder Mania BD to get solution.

Thanks for being with Coder Mania BD.

Friday, February 26, 2016

DATA TYPE,VARIABLES,INPUT AND OUTPUT

DATATYPE: C has five types of basic Data.such as int,double,float,char and void.Today we are going to learn int Type data programming.int stand for integer.Integers are 0,1,2,3......

VARIABLES: A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.




The name of a variable can be composed of letters, digits, and the underscore character. It must begin with either a letter or an underscore.Upper and lowercase letters are distinct because C is case-sensitive.
Now write this program on your compiler:

code:

           #include <stdio.h>

           int main()
           {
               int x,y;
               x = 5;
               y = 6;

               printf("%d",x);

           return 0;
           }

Output: 5



Description of the program: Here i wrote int x,y;int stand for integer and here i declared two variables x & y.You can declare many variables.You can not write variables like 1x,$a,#x,+y,show-ans etc.You can use this operators or signs or numbers (1,$,+,#) after characters.And you can use show_ans.
In printf function i used "%d" for showing integer which i mentioned after it.

Can you do summation,subtraction,multiplication and division by C?See in my next post.
Thanks for being with coder mania BD.

First program in C

We are going to write our first program in C a compiler.I write a program like this:

Code:

/*This is our first program.*/

#include <stdio.h> 


int main()         

{
    printf("Hello Worid.");
    
return 0;
}

Output is: Hello World.

coder mania bd

When i run this program it shows me "Hello World".

Why and How it works?

At first i wrote a comment between /*.......*/.The compiler do not read any comment in a program.You can write comment in a program for making a program easily readable to others or our next development.You can write single line comment and multi-line comment.For single line comment you have to use // this and for multi-line comment you have to use /*........*/ this.

After that we used #include <stdio.h>.#include means i linked something in this program from C library.Actually i linked a header file.C has many header file.All file have specific uses.The <stdio.h> file is for input and output operation.<std(standard)i(input)o(output).h(header)> .

Then i wrote int main().int means integer and the main() is a function.C has many functions but main() is the principle function for C language.

{...statements.....},The second brackets keep the statements.printf("Hello Worid."); this is a statement.Every statement must have to end with ; semicolon.

Now printf("Hello World."); printf is a function.It helps the program to give output.After the printf,there are  two quotation mark between two braces.Between the quotation mark you can  write anything which you want to show on your console.

return 0;This statement tells the program to end his works.

This was our first program.Many programmer start their programming with this program Hello World.If you face any problem to understand then feel free to contact us.You can comment here or visit our Facebook page Coder Mania BD and Facebook group .
Thanks for being with coder mania bd.

Friday, February 19, 2016

The Basic structure of C.


If you want to be a good programmer,You need to know the basic structure of a language (C).

In C basically there are two parts.Like Include Files Part & Main function () part.


Include files like header files.There are many header files stored In C language library.such as #include <stdio.h>, #include <math.h>,#include <conio.h> etc.
Main function usually declare the variables and call the library functions,user defined functions.Every C program starts with main ().You can not think C without main ().In C,there can be many functions along with main ().Every function has specific work.
“Other functions” part is under main () function.Main () function call different types of library functions like, clrscr(),getch(),sqrt(),printf(),scanf(). And also call user defined functions.


Now I am going to describe a program sections.


You can write comments in the document section.To write single line comment use // and for multiline comment use /*……*/.
You have to link a header file in the link section.Header files define the library functions and keywords.Header files executes the program.
Symbolic constants are defined in the definition section.
Global variables are declared in the Global variable declaration section.Global variables can be used in several function.
Main function is a function where a program call the library functions and user defined functions.C program starts from compile and executes main() function.

Main function consist of two parts:

(1)Declaration part:- It declare all variables which are used in executable part.

(2)Executable part:- Executable part contains with  minimum one statement.


There is a Demo program for you:


#include <stdio.h>
int main ()
{
    printf("Hello World.");

 return 0;



Be continue.......

Wednesday, February 17, 2016

INTRODUCTION TO C


coder mania bd
C is a high level (2nd generation) structural language. With C you can solve scientific and mathematical problems. Beside this C has enormous uses like designing operating system, program developing, execute a database etc.

To start C what you will need?

At first you need a computer. A text editor.
I recommended you to use CODE BLOCK.It is a fantastic text editor.
I use it. 

you can download it from here:

For windows user :
go-->codeblocks.org-->downloads-->windows
For linux :
go-->codeblocks.org-->downloads-->linux
For Mac user :
go-->codeblocks.org-->downloads-->mac
If you face any problem to run this software in your computer then contact us through comment or join our group https://www.facebook.com/groups/codermaniabd/
Thanks for being with Coder Mania BD.

Thursday, January 28, 2016

সি প্রোগ্রামিং/কেন সি শিখবেন?

সি হল অপারেটিং সিস্টেম লেখার জন্য সবচেয়ে বেশী ব্যবহৃত প্রোগ্রামিং ভাষা । ইউনিক্স সি ভাষায় লেখা প্রথম অপারেটিং সিস্টেম । উত্তরকালের মাইক্রোসফট উইন্ডোস, ম্যাক ও এস এক্স, গ্নু/লিনাক্স সবগুলোই সি প্রগ্রামিং ভাষায় লেখা । সি শুধু অপারেটিং সিস্টেমের ভাষাই নয় , বর্তমানকালে জনপ্রিয় প্রায় সকল প্রোগ্রমিং ভাষার প্রেরণা সি প্রোগ্রমিং ভাষা ।প্রকৃতপক্ষে পার্ল, পিএইচপি, পাইথন, রুবি প্রত্যেকটা ভাষাই সি তে লেখা ।ধরুন আপনি স্পেনিশ , ইটালিয়ান , ফ্রেঞ্চ বা পর্তুগিজ ভাষা শিখতে চাচ্ছেন । তার আগে ল্যাটিন শেখা কি আপনার কাজে আসবে নাকি না ? যেহেতু ল্যাটিন ভাষা থেকেই এসকল ভাষার উৎপত্তি। সি শেখা আপনাকে সি ভাষায় তৈরি করা পুরো প্রোগ্রমিং ভাষার পরিবারকে বুঝতে সাহায্য করবে - আপনাকে দেবে স্বাধীনতা ।


কেন সি , এবং কেন এসেম্বলি ভাষা নয় ?

এসেম্বলি ভাষা আপনাকে গতি এবং সিস্টেমের উপর সর্বোচ্চ নিয়ন্ত্রণ প্রদান করলেও বহনযোগ্য নয় । সি ঠিক এই যায়গাটাতেই আলাদা । এটি যেমন সিস্টেমের উপর যথেস্ট নিয়ন্ত্রন দেয় তেমনি বহনযোগ্যও ।আলাদা আলাদা প্রোসেসর আলাদা আলাদা এসেম্বলি ভাষায় কাজ করে , তাই তাদের মধ্যে যেকোন একটি প্রোসেসর নির্ধারণ করা এবং শুধু সেটার উপযোগী এসেম্বলি ভাষা শেখা অযৌক্তিক কাজ । প্রকৃতপক্ষে সি এর প্রধান শক্তিই হচ্ছে এসেম্বলি ভাষার উপর সর্বোচ্চ নিয়ন্ত্রণ রেখেও সার্বজনিনতা এবং বিভিন্ন আর্কিটেকচারের কম্পিউটারে ব্যবহারের ক্ষমতা ।
উদাহরনস্বরুপ , HP 50g calculator (ARM processor), TI-89 calculator (68000 processor), Palm OS Cobalt smartphones (ARM processor), iMac (PowerPC), 
Arduino (Atmel AVR) এবং Intel iMac (Intel Core 2 Duo) এ সবকটিতেই আপনি সি প্রোগ্রাম কম্পাইল এবং ব্যবহার করতে পারবেন । এই সবকটি ডিভাইসের প্রত্যেকটির আলাদা আলাদা এসেম্বলি ভাষা আছে এবং কোনটাই অন্যকোনটার সাথে সামন্জস্যপূর্ন না ।
এসেম্বলি ভাষা যদিও খুবই শক্তিশালী কিন্তু বড় ধরণের কাজে ব্যবহারের জন্য প্রোগ্রাম লিখা খুবই কঠিন । সাথে সাথে এটি পড়া কিংবা যুক্তিপূর্ণ ভাষায় উপস্থাপন করাটাও অনেক কঠিন । সি একটি কম্পাইল করা ভাষা যা দ্রুত এবং কার্যকর এক্সিকিউটেবল ফাইল তৈরি করে । সাথে সাথে এটি একটি ছোট "what you see is all you get" ( যা দেখবেন তাই পাবেন ) ভাষা । একেকটি সি স্টেটমেন্ট আসলে অনেকগুলো এসেম্বলি স্টেটমেন্ট কে প্রকাশ করে - বাকি সব সরবরাহ করে লাইব্রেরী ফাংশন ।

সি প্রোগ্রামিং ভাষার এই তুমুল জনপ্রিয়তা কী আপনার কাছে বিষ্ময়কর লাগছে ?

সিড়ির উপরের ধাপটি যেমন নীচের ধাপের উপর দাড়িয়ে থাকে তেমনই উত্তর প্রজন্মের প্রোগ্রমিং ভাষা তার পূর্বের প্রজন্মের ভাষার উপরেই ভিত্তি করে গড়ে উঠে । সি তে ডিজাইন করা অপারেটিং সিস্টেমের সিস্টেম লাইব্রেরীও সি তে ডিজাইন করা হয় । এই সকল সিস্টেম লাইব্রেরী পরবর্তিতে উচ্চতর লাইব্রেরী ডিজাইন করতে ব্যবহার করা হয় ( যেমন OpenGL কিংবা GTK ) এবং এই সকল উচ্চতর লাইব্রেরীর ডিজাইনাররাও সাধারণত সেই প্রোগ্রমিং ল্যাংগুয়েজই ব্যবহার করেন যে ভাষায় সিস্টেম লাইব্রেরী লেখা হয়েছে । এপ্লিকেশন ডেভেলপাররা উচ্চতর লাইব্রেরী ব্যবহার করে গেমস , ওয়ার্ড প্রোসেসর , মিডিয়া প্লেয়ার এসব তৈরি করতে । তাদের অনেকে উচ্চতর লাইব্রেরী যে ভাষায় লেখা সেই প্রোগ্রমিং ভাষা ব্যবহার করতে পছন্দ করেন ... এবং এভাবেই সি এর জনপ্রিয়তা বাড়ছেই ...

কেন সি এবং কেন অন্য কোন উচ্চতর প্রোগামিং ভাষা নয়?

সি ল্যাংগুয়েজের প্রাথমিক লক্ষ্য হল ন্যূনতম ফুটপ্রিন্ট এবং সর্বোচ্চ পারফরম্যান্স বজায় রেখে বহনযোগ্য কোড লিখা । উল্লেখ্য যে অপারেটিং সিস্টেম বা অন্য কোন প্রোগ্রামের ক্ষেত্রে উচ্চতর ভাষা আপনাকে উল্লেখযোগ্য পারফরম্যান্স নাও দিতে পারে । সি বহুদিন যাবৎ ব্যবহৃত একটি পরিণত ভাষা , এবং মোটামুটি সকল প্লাটফরমেই একে ব্যবহার যোগ্য করা হয়েছে । সি প্রোগ্রমিং ভাষা ব্যবহারের অন্যতম একটা কারণ মেমরি ব্যবস্থাপনা , এটি একজন প্রোগ্রমারকে সরাসরি একটা মেমরি এড্রেসে লিখতে দেয় । structs, pointers এবং arrays এর মত কী কন্সট্রাক্ট গুলো মেমরিকে মেশিন অনির্ভর করে ব্যবহারের জন্যই মূলত ডিজাইন করা হয়েছে ।

Saturday, January 23, 2016

Introduction to HTML

What is HTML?

HTML is a markup language in which to describe contents a web page.
HTML is full, the Hypertext Markup Language
Markup Language is the sum of many markup tags
HTML tags are described by the HTML Documents
Each of the different content of the document describes the HTML tags


Example:
<!DOCTYPE html>
<html>
<head>
<titlePage Title </title>
</head>
<body>
<h1My First Heading </h1>
<p>  My first paragraph .</p>
</body>
</html>

Results: 
My First Heading
 My first paragraph.



Describing the Example


  • DOCTYPE declaration is the first type of document: HTML.
  • <Html> and </ html> tag within the HTML document that describes the text.
  • <Head> and </ head> tag within the HTML document type the text that contains the information.
  • <Title> and </ title> tag within the HTML document title contains the text.
  • <Body> and </ body> the contents inside the tag shows in the web browser.
  • <H1> and </ h1> tag within the text of this heading describe.
  • <P> and </ p> tags within the text of this paragraph would declare.

HTML tags


  • HTML tags are the angle brackets <> are bound by certain keywords.
  • HTML tags are usually in pairs, such as the <p>and</p> 
  • The first part is called the start-tag, and the last part is the end tag.
  • The end tag is the same as the start tag, an extra slash (/) is to be added Just before.

hints: Start tag is often called the opening tag, an end tag is called the closing tag.


Web Browser

Such as Web browsers (Chrome, IE, Firefox, Safari), and that their job is to read HTML documents to display. Sometimes the browser does not display the HTML tags but no content to display how to use the tags for.


                                                                                                                                   Be continue..........
Namecheap.com

Popular Posts