2 C Lab Part

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

Ex No 2. Develop programs using identifiers and operators

2 c) Write a C program for arithmetic calculation using assignment operators.

AIM :
To perform arithmetic calculation using assignment operators
ALGORITHM:
Step 1: Start
Step 2: Declare and initialize the variables a and c
Step 3: Perform arithmetic calculation using compound assignment operators
and calculate the value of c. (c+=a, c-=a, c*=a, c/=a)
Step 4: Print the values of c.
Step 5: Stop
FLOW CHART:
Start

Read a

C=a

C+=a

C-=a

C*=a

C/=a

Print c

Stop
Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

SOURCE CODE:

#include <stdio.h>
int main()
{
int a = 5, c;
c = a;
printf("c = %d\n", c);
c += a;
printf("c = %d\n", c);
c -= a;
printf("c = %d\n", c);
c *= a;
printf("c = %d\n", c);
c /= a;
printf("c = %d\n", c);
c %= a;
printf("c = %d\n", c);

return 0;
}
Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

SCREENSHOT:

RESULT:
Thus the C program for arithmetic operations using assignment operators is
executed and verified successfully.
Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

PRACTICE EXERCISE:
2 d)Write a C program Swapping two numbers without temp variables
Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

Particulars Max Marks Mark secured


Program and Execution 15
Viva 10
Total 25

Result
Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

2 e) Write a C program to find the value of the variable using increment and decrement
operators.

AIM :
To find the value of the variable using increment and decrement operators

ALGORITHM:
Step 1: Start
Step 2: Initialize the variables a = 10, b = 100, c = 10.5, d = 100.5.
Step 3: Perform post increment and decrement
a++, b--, c++, d--
Step 4: Print the values of a,b,c,d.
Step 5: Perform pre increment and decrement
++a, --b, ++c, --d
Step 6: Print the values of a,b,c,d.
Step 5: Stop

FLOW CHART:

Start

Assign
values
a, b, c, d

Post incr/decr
a++, b--, c++, d---

Pre incr/decr
++a, --b, ++c, --d

Print
a, b, c, d

Stop
Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

SOURCE CODE:

#include <stdio.h>
int main()
{
int a = 10, b = 100;
float c = 10.5, d = 100.5;
printf("post Incr/decr");
printf("a++ = %d \n", a++);
printf("b--= %d \n", b--);
printf("c++ = %f \n", c++);
printf("d-- = %f \n", d--);

printf("pre Incr/decr");
printf("++a = %d \n", ++a);
printf("--b = %d \n", --b);
printf("++c = %f \n", ++c);
printf("--d = %f \n", --d);
return 0;
}
Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

SCREENSHOT:

RESULT
Thus the c program to find the value of the variable using increment and
decrement operators is executed and verified successfully.
Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

PRACTICE EXERCISE:

2 f) Write a C program print the Reverse the Digit to N Number


Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

Particulars Max Marks Mark secured


Program and Execution 15
Viva 10
Total 25

Result
Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

2 g) Write a c program to check whether letter is small, capital, digit or special


symbol using logical operators

AIM:
To check whether a given letter is small, capital, digit or special symbols
using logical operators.

ALGORITHM:
Step 1: Start
Step 2: declare the variable x.
Step 3: get the value of x.
Step 4: check the alphabet is small letter or not using logical AND
if(x>=’a’ && x<=’z’) then
Print x is small letter.
Step 5: check the alphabet is digits, symbols using logical AND operator.
Step 6: Print x.
Step 7: Stop
Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

FLOW CHART:
Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

SOURCE CODE:

#include<stdio.h>
#include<conio.h>
main()
{
char x;
clrscr();
printf("Enter character: ");
scanf("%c",&x);
if(x>='a' && x<='z')
printf("Small letter");
else if(x>='A' && x<='Z')
printf("Capital letter");
else if(x>='0' && x<='9')
printf("Digit");
else
printf("Special Symbol");
getch();
}
Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

SCREENSHOT:

RESULT:
Thus the c program to check whether a given letter is small, capital, digit or special
symbol using logical operators is executed and verified successfully.
Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

PRACTICE EXERCISE:

2 h).Write a C program to find the given year is leap year or not using operators.
Programming in C Laboratory Department of Computer Science and Engineering, SMVEC

Particulars Max Marks Mark secured


Program and Execution 15
Viva 10
Total 25

Result

You might also like