LAB 1,2
LAB 1,2
AIM
To implement c programming using statements
ALGORITHM
STEP1: Start the program
STEP2: Declare the variables
STEP3: Put the x and y value
STEP4: Check the condition, if the condition true print true statements
STEP5: Otherwise print false statements
STEP6: Stop the program
PROGRAM
#include <stdio.h>
void main( )
{
int x, y;
x = 15;
y = 18;
if (x > y )
{
printf("x is greater than y");
}
else
{
printf("y is greater than x");
}
}
2
OUTPUT
Y is greater than x
RESULT
Thus the c program using statement was executed successfully.
EX.NO:1(b) C PROGRAMMING USING EXPRESSION
AIM
To implement c programming using expressions
ALGORITHM
STEP1: Start the program
STEP2: Declare the variables
STEP3: Enter the variable value
STEP4: Perform the arithmetic operations
STEP5: Print the values
STEP6: Stop the program
PROGRAM
#include <stdio.h>
int main()
{
int a,b,result;
printf("Enter 2 numbers for Arithmetic operation \n");
scanf("%d\n%d",&a,&b);
printf("=======ARITHMETIC EXPRESSIONS=======\n");
result = a+b;
printf("Addition of %d and %d is = %d \n",a,b,result);
result = a-b;
printf("Subtraction of %d and %d is = %d \n",a,b,result);
result = a*b;
printf("Multiplication of %d and %d is = %d \n",a,b,result);
result = a/b;
printf("Division of %d and %d is = %d \n",a,b,result);
result = a%b;
printf("Modulus(Remainder) when %d divided by %d = %d \n",a,b,result);
int c=a;
4
result = a++;
printf("Post Increment of %d is = %d \n",c,result);
result = ++a;
printf("Pre Increment of %d is = %d \n",c,result);
result=a--;
printf("Post decrement of %d is = %d \n",c,result);
result=--a;
printf("Pre decrement of %d is = %d \n",c,result);
printf("===========================");
return 0;
}
OUTPUT
Enter 2 numbers for arithmetic operation
10
5
======ARITHMETIC EXPRESSIONS=======
Addition of 10 and 5 is = 15
Subtraction of 10 and 5 is = 5
Multiplication of 10 and 5 is = 50
Division of 10 and 5 is = 2
Modulus(Remainder) when 10 divided by 5 = 0
Post Increment of 10 is = 10
Pre Increment of 10 is = 12
Post decrement of 10 is = 12
Pre decrement of 10 is = 10
===========================
5
RESULT
Thus the c program using expression was executed successfully.
6
EX.NO:1(c) C PROGRAMMING USING DECISION MAKING AND ITERATIVE
STATEMENTS
AIM
To implement c programming using decision making and iterative statements
ALGORITHM
STEP1: Start the program
STEP2: Declare the variables
STEP3: Enter the variable value
STEP4: Check the condition, if it is true print palindrome
STEP5: Otherwise print not palindrome
STEP6: Stop the program
PROGRAM
#include<stdio.h>
void main()
{
int a, b, c, s = 0;
printf("Enter a number:\t");
scanf("%d", &a);
c = a;
while(a > 0)
{
b = a%10;
s = (s*10)+b;
a = a/10;
7
}
if(s == c)
{
printf("The number %d is a palindrome", c);
}
else
{
printf("The number %d is not a palindrome", c);
}
}
OUTPUT
RESULT
Thus the c program using decision making and iterative statements was executed
successfully.
8
EX.NO:2 C PROGRAMMING USING FUNCTIONS AND ARRAYS
AIM
To implement c programming using functions and arrays
ALGORITHM
STEP1: Start the program
STEP2: Declare the function with variables
STEP3: Enter the variable value
STEP4: Calculate the formula to sum the given values
STEP5: Print the result value
STEP6: Stop the program
PROGRAM
// Program to calculate the sum of array elements by passing to a function
#include <stdio.h>
float calculateSum(float num[]);
int main()
{
float result, num[] = {23.4, 55, 22.6, 3, 40.5, 18};
result = calculateSum(num);
printf("Result = %.2f", result);
return 0;
}
float calculateSum(float num[])
{
float sum = 0.0;
OUTPUT
Result = 162.50
RESULT
Thus the c program using functions and arrays was executed
successfully.