Skip to main content

C Programming for Beginner #3 (Instructions)


Types of Instruction


  1. Type Declaration: It is used to declare type of variables used in C Program.
  2. Arithmetic: It is used to perform Arithmetic operation on constant or variable.
  3. Control: It is used to control the sequence of execution.
With the help of these instruction we make our C Program.
  • Type Declaration:-
Example: 
int a
float b
char code
  • Explanation:

  1. int a means we are a can store an integer values in a like 1,2,3,4 etc.
  2. float b means we can store a decimal values in b like 1.5 ,2.6 etc.
  3. char is used to declare character in C Program.
  • Arithmetic:
  1. c=a+b (Addition)
  2. c=a/b (Division)
  3. c=a*b (Multiplication)
  4. c=a%b (Modulus) these gives us the remainder after division.
  • Control:

  1. This instruction comes in picture when we deal with the loops,case control sequence of program or decision making.
Example Program:
include<stdio.h>
int main()
{
int a=5,b=5;
c=a+b;
d=a-b;
e=a/b;
f=a*b;
g=a%b;
printf("Added no is %d\n",c);
printf("Subtracted no is %d\n",d);
printf("Divided no is %d\n",e);
printf("Multiplied no is %d\n",f);
printf("Modded no is %d\n",g);
return 0;
}

Here I have used %d in printf it is used to tell the program to print digit if we want result in decimal we will use %f as it is for float and %c for char.

Output of the program will be:
Added no is 10
Subtracted  no is 0
Divided no is 1
Multiplied no is 25
Modded no is 0

Note: You can compile this program try new thing and if you have any questions you can ask in comment section.

Comments

Popular posts from this blog

Android O (Android Operating system)

There are many kind of changes and improvements in this new version of Android OS. Increased Ability of the mobile:- aptX bluetooth streaming :-   High quality audio codec is supported for streaming to bluetooth Headsets and Speakers Adaptive icons give devs and OEMs easy shape masks, extra effects :-  "an OEM like Samsung or HTC will provide a unifying mask, which will allow developers to integrate almost any existing app icon into the broader user interface with minimal effort, and no extra graphics work on the icon itself." Neighborhood Aware Networking (NAN) mode for WiFi :-  "You can think about NAN as a combination of WiFi Direct and Nearby. Two hypothetical phones with NAN could find each other and connect without any additional apps or configuration, allowing them to share data at high speeds." Picture-in-picture video for all devices and new windowing features :- "The gist is that when watching video on Android O, you'll be able to shr...

C Programming #8 (Case Control Instruction)

In Programming we come across some situations where we have to choose from number of alternatives and choice should be specific to condition so the control statement that allow us to make a decision from number of choice is called as switch or we can say switch-case as they are used together. The switch statement looks like : switch (integer expression) { case constant 1: do this; case constant 2: do this; case constant 3: do this; default: do this; } In these case do this is the command statement that is to be followed when case is satisfied Example: #include<stdio.h> int main() { int i=2; switch(i) { case 1: printf("I am in case 1\n"); case 2: printf("I am in case 2\n"); case 3: printf("I am in case 3\n"); default: printf("I am in default"); } return 0; } Output of the program will be : I am in case 2 I am in case 3 I am in default But this is not the output we needed this program should give us...