Friday, 3 March 2017

Arithmatic operation using C (addition of two numbers)

//This program is to add two numbers

#include<stdio.h>

int main()
{
printf("%d \n",10+20);  //Here %d is a format specifier to display a integer value

//Variables
//In above example we cannot change the data 10+20=30 and the statements prints "30" at the output

//but the code will not be general! and always the output will be "30"
//So to write a general program to add 2 numbers we need a variable
//variable is a space in the computer memory to store a data
//for proper utilization of the memory space we have different data types to store different numbers
// ex: signed/unsigned char,int,float and the size allocated for this variables varies according to the size of your machine (16bit/32bit/64bit OS)

//lets add 2 integers


int x,z;                //here x is a integer variable.This statement is called 'vriable declaration'
x=10;                 // variable assignment
int y=34;            //variable initialization
z=x+y;

printf("The sum of two numbers is\n");
printf("sum=%d \n",x=y);

printf("the other way to display id: \n");
printf("sum is = %d \n",z);

}

No comments:

Post a Comment