EXPT: 1
C PROGRAMMING USING
Date: OPERATORS
LEVEL 0:
AIM:
To convert Celsius temperature into Fahrenheit by using C program.
ALGORITHM:
1. Start.
2. Declaring variables for Celsius and Fahrenheit.
3. Get the temperature in Celsius and store it.
4. Convert the Celsius temperature to Fahrenheit by using formula,
F=[9/5*c]+32;
5. Round off the value to two decimal places.
6. Store the result as Fahrenheit.
7. Display the result as Fahrenheit.
8. Stop.
PROGRAM:
#include <stdio.h>
int main()
float celsius, fahrenheit;
scanf("%f", &celsius);
fahrenheit = (9.0 / 5.0* celsius) + 32;
printf("Temperature in Fahrenheit=%0.2f\n",fahrenheit);
return 0;
INPUT:
16
OUTPUT:
Temperature in Fahrenheit=60.80
RESULT:
PROGRAM WAS SUCCESSFULLY EXECUTED AND VERIFIED.
LEVEL 1:
AIM:
To calculate Octagonal number by using C programing.
ALGORITHM:
1. Start.
2. Declare the integer variables for number and octagonal number.
3. Get the value of number and store it.
4. Calculate octagonal number by using formula,
Octagonalnumber=3n2-2n.
5. Store the result as octagonal number.
6. Display the result.
7. Stop.
PROGRAM:
#include <stdio.h>
int main()
int n, octagonalNumber;
scanf("%d", &n);
octagonalNumber = (3 * n * n - 2 * n);
printf("The octagonal number is: %d\n",octagonalNumber);
return 0;
}
INPUT:
6
OUTPUT:
The octagonal number is: 96
RESULT:
PROGRAM WAS SUCCESSFULLY EXECUTED AND VERIFIED.
LEVEL 2:
AIM:
To calculate number of match sticks required for X number of floors.
ALGORITHM:
1. Start.
2. Declare the variable integer X and long int for the total number of math
sticks.
3. Get the value of X and store it.
4. Calculate total number of math sticks required by using formula,
Totalmathsticks=(3*x*(x+1)/2.
5. Store the output as result.
6. Display the Result.
7. Stop.
PROGRAM:
#include <stdio.h>
int main()
int x;
scanf("%d", &x);
int totalMatchsticks = (3 * x * (x + 1)) / 2;
printf("Total number of matchsticks required: %d\n", totalMatchsticks);
return 0;
INPUT:
3
OUTPUT:
Total number of matchsticks required:18
RESULT:
PROGRAM WAS SUCCESSFULLY EXECUTED AND VERIFIED.
MARK ALLOCATION
S.NO. Particulars Marks Allotted Marks Awarded
1. Program 40
2. Program Execution 30
3. Result 20
4. Viva Voce 10
Total: 100
STAFF SIGNATURE
EXPT: 2
C PROGRAMMING USING
Date: LOGICAL AND RELATIONAL
OPERATORS
LEVEL 0:
AIM:
To Check whether Two given Numbers are Equal or Not.
ALGORITHM:
1. START.
2. Declare two integer variables number1 and number2.
3. Get the values of number1 and number2 and store it.
4. Compare the two input values using if statement.
5. Display the output.
6. STOP.
PROGRAM:
#include<stdio.h>
int main()
int number1,number2;
printf("enter number 1");
scanf("%d",&number1);
printf("enter number 2");
scanf("%d",&number2);
if(number1==number2)
printf("two numbers are equal\n");
else
printf("two numbers are not eqaul\n");
return 0;
INPUT:
Enter number1: 5
Enter number2: 10
OUTPUT:
Two numbers are not equal.
RESULT:
PROGRAM WAS SUCCESSFULLY EXECUTED AND VERIFIED.
LEVEL 1:
AIM:
To check whether Inputs Sides of a Triangle can form Equilateral, Isosceles, or
Scalene Triangle.
ALGORITHM:
1. START.
2. Declare three variables to store sides of the triangle.
3. Get all three inputs and store it.
4. Check whether input passes the condition and store the result.
5. Display the result.
6. STOP.
PROGRAM:
#include<stdio.h>
int main()
int side1,side2,side3;
printf("enter side1");
scanf("%d",&side1);
printf("enter side2");
scanf("%d",&side2);
printf("enter side3");
scanf("%d",&side3);
if(side1==side2&&side2==side3&&side3==side1)
{
printf("\ntriangle is equilateral");
else if(side1==side2||side2==side3||side3==side1)
printf("\ntriangle is isoscles");
else
printf("\ntriangle is scalene");
return 0;
INPUT:
Enter side1: 1
Enter side2: 2
Enter side3: 3
OUTPUT:
Triangle is Scalene.
RESULT:
PROGRAM WAS SUCCESSFULLY EXECUTED AND VERIFIED.
LEVEL 2:
AIM:
To read input digits and displays it in words.
ALGORITHM:
1. START.
2. Declare the variables to store the digits as input values.
3. Get the input and store it.
4. Checking the condition.
5. Display the result.
6. STOP.
PROGRAM:
#include<stdio.h>
int main()
int num1;
printf("enter number");
scanf("%d",&num1);
switch(num1)
case 0:
printf("zero");
break;
case 1:
printf("one");
break;
case 2:
printf("two");
break;
case 3:
printf("three");
break;
case 4:
printf("four");
break;
case 5:
printf("five");
break;
case 6:
printf("six");
break;
case 7:
printf("seven");
break;
case 8:
printf("eight");
break;
case 9:
printf("nine");
break;
case 10:
printf("ten");
break;
default:
printf("wrong");
break;
return 0;
}
INPUT:
Enter number: 5
OUTPUT:
Five
RESULT:
PROGRAM WAS SUCCESSFULLY EXECUTED AND VERIFIED.
MARK ALLOCATION
S.NO. Particulars Marks Allotted Marks Awarded
1. Program 40
2. Program Execution 30
3. Result 20
4. Viva Voce 10
Total: 100
STAFF SIGNATURE
EXPT: 3
C PROGRAMMING USING
Date: LOOPING STATEMENTS
LEVEL 0:
AIM:
To write a C program to print the multiplication table for a given number using For
loop.
ALGORITHM:
1. START.
2. Declare the variables number1 and i.
3. Get the input and store it.
4. Calculate the product of i and number1.
5. Store the product as result.
6. Display the result.
7. STOP.
PROGRAM:
#include<stdio.h>
int main()
int i, number1;
printf("enter multiplication table number");
scanf("%d",&number1);
for(i=1;i<=10;++i)
{
printf("%dx%d=%d\n",i,number1,i*number1);
return 0;
INPUT:
Enter Multiplication Table Number: 5
OUTPUT:
1x5=5
2x5=10
3x5=15
4x5=20
5x5=25
6x5=30
7x5=35
8x5=40
9x5=45
10x5=50
RESULT:
PROGRAM WAS SUCCESSFULLY EXECUTED AND VERIFIED.
LEVEL 1:
AIM:
To Find whether Given number is Positive, Negative and also Count it using while
loop.
ALGORITHM:
1. START.
2. Declare the variables n, i, positivecount, negativecount to store values.
3. Initialize positivecount, negativecount to zero.
4. Get the value of n and store it.
5. Initialize i equal to zero.
6. Get the input numbers.
7. Calculate the numbers using while loop.
8. Printf the values of positivecount, negativecount.
9. STOP.
PROGRAM:
#include<stdio.h>
int main()
int n,i=0;
int positivecount=0,negativecount=0;
int number;
printf("enter the number of elements");
scanf("%d",&n);
while(i<n)
{
scanf("%d",&number);
if(number>0)
positivecount++;
else
negativecount++;
i++;
printf("number of positive numbers:%d\n",positivecount);
printf("number of negative numbers:%d\n",negativecount);
return 0;
INPUT:
Enter the Number of Elements: 4
-6
3
OUTPUT:
Number of positive numbers:3
Number of negative numbers:1
RESULT:
PROGRAM WAS SUCCESSFULLY EXECUTED AND VERIFIED.
LEVEL 2:
AIM:
To write a C program to print the numbers in decreasing order pattern.
ALGORITHM:
1. START.
2. Declare the number i, j variables.
3. Get the number of rows as input.
4. Calculate Pattern by using For loops i and j.
5. Display the result.
6. STOP.
PROGRAM:
#include<stdio.h>
int main()
int n,i,j,m;
printf("enter number of rows");
scanf("%d",&n);
for(i=n;i>=1;i--)
for(j=1;j<=i;j++)
{
m++;
printf("%d\t",m);
printf("\n");
return 0;
INPUT:
Enter number of rows: 4
OUTPUT:
1 2 3 4
5 6 7
8 9
10
RESULT:
PROGRAM WAS SUCCESSFULLY EXECUTED AND VERIFIED.
MARK ALLOCATION
S.NO. Particulars Marks Allotted Marks Awarded
1. Program 40
2. Program Execution 30
3. Result 20
4. Viva Voce 10
Total: 100
STAFF SIGNATURE
EXPT: 4
C PROGRAMMING USING ARRAYS
Date:
LEVEL 0:
AIM:
To write c program to print the sum of elements present in odd positions in the
array.
ALGORITHM:
1. START.
2. Declare all Three variables to Enter Elements of Array.
3. Get the size of array and store it.
4. Get the elements of array and store it.
5. Add the elements at the odd index to the sum.
6. Store the result as sum.
7. Display the result.
8. STOP.
PROGRAM:
#include<stdio.h>
int main()
int a[100];
int n,i,sum=0;
printf("enter size of array");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=1;i<n;i+=2)
sum=sum+a[i];
printf("sum of elements in odd positions:%d\n",sum);
return 0;
INPUT:
Enter size of array: 5
OUTPUT:
Sum of elements in odd positions: 6
RESULT:
PROGRAM WAS SUCCESSFULLY EXECUTED AND VERIFIED.
LEVEL 1:
AIM:
To write the C program to Remove duplicate elements from array and print the
unique alone.
ALGORITHM:
1. START.
2. Declare all Three variables to Enter Elements of Array.
3. Get the size of array and store it.
4. Get the elements of array and store it.
5. Compare the elements with subsequent elements.
6. Print the array of unique elements.
7. STOP.
PROGRAM:
#include<stdio.h>
int main()
int a[100];
int size,i,j,k;
printf("enter the size");
scanf("%d",&size);
for(i=0;i<size;i++)
scanf("%d",&a[i]);
}
for(i=0;i<size;i++)
for(j=i+1;j<size;j++)
if(a[i]==a[j])
for(k=j;k<size-1;k++)
a[k]=a[k+1];
size--;
j--;
printf("array elements:");
for(i=0;i<size;i++)
printf("%d,",a[i]);
return 0;
}
INPUT:
Enter the size: 5
OUTPUT:
Array elements:1,2,4
RESULT:
PROGRAM WAS SUCCESSFULLY EXECUTED AND VERIFIED.
LEVEL 2:
AIM:
To write a C program to Merge two arrays into third array after sorting.
ALGORITHM:
1. START.
2. Declare the variables to enter array size and elements.
3. Get the size of array and its elements.
4. Merge the two arrays into third array.
5. Sort the third array and store it as result.
6. Display the result.
7. STOP.
PROGRAM:
#include<stdio.h>
int main()
int i,j;
int temp;
int size1,size2,size3;
int a[50],b[50],c[50];
printf("enter the size of array1");
scanf("%d",&size1);
for(i=0;i<size1;i++)
{
scanf("%d",&a[i]);
printf("enter the size of array2");
scanf("%d",&size2);
for(i=0;i<size2;i++)
scanf("%d",&b[i]);
size3=size1+size2;
for(i=0;i<size1;i++)
c[i]=a[i];
for(i=0;i<size2;i++)
c[i+size1]=b[i];
printf("merged array: ");
for(i=0;i<size3;i++)
printf("%d\t",c[i]);
printf("\n final array after sorting:");
for(i=0;i<size3;i++)
for(j=i+1;j<size3;j++)
if(c[i]>c[j])
temp=c[i];
c[i]=c[j];
c[j]=temp;
for(i=0;i<size3;i++)
printf("%d\t",c[i]);
return 0;
INPUT:
Enter the size of array1: 2
Enter the size of array2: 5
1
OUTPUT:
Merged array: 1 2 1 8 5 6 4
Final array after sorting: 1 1 2 4 5 6 8
RESULT:
PROGRAM WAS SUCCESSFULLY EXECUTED AND VERIFIED.
MARK ALLOCATION
S.NO. Particulars Marks Allotted Marks Awarded
1. Program 40
2. Program Execution 30
3. Result 20
4. Viva Voce 10
Total: 100
STAFF SIGNATURE