SEMESTER 1ST AND 2ND (1ST YEAR) – PROGRAMMING WITH "C" (P2400104)

Share:WhatsAppTelegram
Develop minimum 3 programs using Constants, Variables, arithmetic expression.

Develop minimum 3 programs using Constants, Variables, arithmetic expression.

Constants: In C programming, we used a keyword to declare any variable as constant i.e. “const”, which means that the value of variable cannot change once it is initialize.

Program 1:

#include <stdio.h>

int main()

{

            const int diploma= 10;

            printf ("The value of const variable is = %d", diploma);

            return 0;

}

 

Output: The value of const variable is = 10

 

Variables: In C programming, we used containers which is used to hold the data like number and character and access it whenever required this container is known as variable.

 

Program 2:

#include <stdio.h>

int main()

{

            int num = 50;

            float value = 15.8;

            char grade = 'A';

           

             // num, value, vowle is a name of variable

             printf ("num: %d \nvalue: %.2f \grade: %c",num,value,grade);

            return 0;

}

Output:

num: 50

value: 15.80

grade: A


 

Arithmetic Expression: In C programming, to perform mathematical operations like addition, subtraction, multiplication, division and modulus we use Arithmetic Expression (+, *, -, /, %).

Program 3:

#include <stdio.h>

int main()

{

            int num1 = 12;

            int num2 = 5;

            printf("Addition of num1 and num2 is: %d",num1+num2); //Addition operation

            printf("\nSubtraction of num1 and num2 is: %d",num1-num2);//Subtraction

            printf("\nMultiplication of num1 and num2 is: %d",num1*num2);//Multiplication

            printf("\nDivision of num1 and num2 is: %.2f",float(num1)/num2);//Division

            printf("\nModulus of num1 and num2 is: %d",num1%num2);//Modulus

            return 0;

}

Output:

Addition of num1 and num2 is 17:

Subtraction of num1 and num2 is 7

Multiplication of num1 and num2 is 60

Division of num1 and num2 is 2.40

Modulus of num1 and num2 is 2


 


*****

Previous
Next

Lab Video References

No references available right now.

Comments & Reviews

Loading comments...