Record 1
Record 1
Date :
AIM:
To implement the program using I/O statements and expression using c language
ALGORITHM:
1. Start the program
1. Input the radius of the circle
2. Find the area and circumference of the circle using the formula
Area=3.14*r*r
Circum=2*3.14*r
3. Print the area and the circum of the circle
4. Display the output of the calculations.
5. Stop.
PROGRAM:
#include<stdio.h>
#include<conio.h>
Void main()
{
float rad,area,circum;
printf("\nEnter the radius of the circle");
scanf("%f",&r);
area=3.14*rad*r;
circum=2*3.14*r;
printf(“\nArea=%f”,area);
printf("\n Circumference=%f,circum);
}
OUTPUT:
AREA=78.500000
CIRCUMFERENCE=31.4000000
RESULT:
Thus the program for I/O statement and expression was executed
successfully and the result was verified.
EX.No.1(b) Program to print Regno,Name, and calculate the average of student
DATE :
AIM
To implement the program to print regno,name and calculate the averageof a student.
ALGORITHM
PROGRAM
#include <stdio.h>
int main()
{
int Regno,Size, i, sum = 0;
char name[20];
float avg = 0;
printf(“Enter your Regno”);
scanf(“%d”,&Regno);
printf(“Enter your name”);
scanf(“%s”,&name);
printf("Please Enter the Array size = ");
scanf("%d", &Size);
int arr[Size];
printf("Enter the Marks : ");
for (i = 0; i < Size; i++)
{
scanf("%d", &arr[i]);
}
for (i = 0; i < Size; i++)
{
sum = sum + arr[i];
}
avg = sum / Size;
printf(“Your Reg no is %d”,Regno);
printf(“Your name is %s”,name);
printf("\nThe Sum of marks = %d\n", sum);
printf("\nThe Average of student = %.f\n", avg);
}
OUTPUT :
RESULT
Thus the program for print Regno ,Name and calculate Average has been implemented
successfully.
Ex.No. 2(a) PROGRAM TO DISPLAY BIGGEST OF TWO NUMBERS
AIM:
To implement the program to display biggest of two numbers.
ALGORITHM:
Step 1:Start
Step 8:end
PROGRAM:
OUTPUT:
RESULT:
Thus the program to input two numbers and display the maximum number was
implemented successfully.
EX.No.2(b) PROGRAM TO CHECK WHETHER A PERSON IS
AIM:
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int age;
char name[50];
printf("\n Enter the name of the candidate:");
gets(name);
printf("\n Enter the age:");
scanf("%d",&age);
if(age>=18)
printf("\n %s is Eligibile for vote",name);
else
printf("\n %s is not Eligibile for vote",name);
getch();
}
OUT PUT :
RESULT:
Thus the program for checking eligibility for voting is executed successfully.
EX.NO.3(a) PROGRAM TO DO ARITHMETIC OPERATIONS
DATE :
AIM:
ALGORTHIM:
PROGRAM :
# include <stdio.h>
void main()
{
int a,b,result,sq1,sq2,ch; float divide;
clrscr();
printf("enter two integers:");
scanf("%d%d",&a,&b);
printf("1.add,2.subtrat,3.multiply,4.divide,5.sqare"); printf("\
n enter the choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
result=(a+b); printf("sum=%d\
n",result);
break;
}
case 2:
{
result=(a-b); printf("difference=%d\
n",result);
break;
}
case 3:
{
result=(a*b);
printf("mutiplication=%d\n",result);
break;
}
case 4:
{
result=a/(float)b;
printf("division=%2f\n",result);
break;
}
case 5:
{
sq1=(a*a);
printf("square=%d\n",sq1);
sq2=b*b;
printf("second square number=%\n",sq2);
break;
}
Default
{
Prinf(“You are Entered wrongly”);
Break;
}
}
getch();
}
OUTPUT :
Difference : 30
RESULT :
Thus the c program for arithmetic operation using switch case has been executed
successfully.
Ex.No. 4 (a) PROGRAM TO FIND THE GIVEN NUMBER IS
AIM:
ALGORITHM:
6. If sum==temp
PROGRAM:
#include<stdio.h>
#include<cono.h>
void main()
{
intn,orgnum,r,result=0;
printf("enter a three digit number:");
scanf("%d",&n);
orgnum=n;
while(orgnum!=0)
{
r=orgnum%10;
result+=r*r*r;
orgnum=orgnum/10;
}
if(result==n)
printf("%d is an armstrongnumber",n);
else
printf("%d is not an armstrongnumber",n);
getch();
}
OUTPUT :
RESULT:
The program for checking given number is Armstrong or not has been successfully
executed.
Ex.No. 4 (b) PROGRAM TO CHECK WHETHER THE ENTERED
AIM :
To implement the Program to check whether the entered character is vowel or
not(Use switch case)
ALGORITHM :
Step 1: Start
Step 2: Declare and initialize the variables
Step 3: Get the input from the user and compare with each cases
Step 4: if match found, print vowel otherwise print consonant
Step 5: End
PROGRAM :
#include<stdio.h>
#include<conio.h>
int main()
{
char ch;
printf("Enter a character: ");
scanf("%c",&ch);
if((ch>='A' && ch<='Z') || (ch>='a' && ch<='z'))
{
switch(ch)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
printf("%c is a VOWEL.\n",ch);
break;
default:
printf("%c is a CONSONANT.\n",ch);
break;
}
}
else
{
printf("%c is not an alphabet.\n",ch);
}
return 0;
}
OUTPUT :
Enter a character : A
A is a Vowel
Enter a character : X
X is consonant
RESULT :
Thus the C Program check whether the entered character is vowel or
not (Use switch case) has been executed and the output was verified.
Ex.No.5(a) PROGRAM TO PRINT POSITIVE INTEGERS FROM 1 TO 100
DATE :
AIM :
To implement the program to print positive integers from 1 to 10.
ALGORITHM :
Step 1: Start
Step 2: Declare and the variables
Step 3: Execute the for loop
Step 4 : Print the integers from 1 to 10
PROGRAM :
#include<stdio.h>
int main()
{
int i;
printf("%d\t ",i);
return 0;
OUTPUT : 1 2 3 4 5 6 7 8 9 10
RESULT :
Thus the program to print integers from 1 to 100 is successfully implemented and verified.
EX.NO.5(b) GET THE ELEMENTS INTO AN ARRAY AND PRINT THE ELEMENTS
DATE : FIND THE LARGEST AND SMALLEST OF THE GIVEN ARRAY
AIM:
To write the program to find the largest and smallest number of given array
ALGORITHM:
5. Initialize the large and small is equal to the first element of the array
9. Check the next element smaller than the larger. If smaller then assign next
element to the small
10. Print the value of large and small after the execution of the loop
PROGRAM :
#include<stdio.h>
#include<conio.h>
Void main()
{
int a[100],I,small,large,no;
printf(“In how many numbers you want to insert….”);
scanf(“%d”,&no);
printf(“Enter the elements of the array…”);
for(i=0;i<no;i++)
scanf(“%d”,&a[i]);
printf(“\nThe
elements of the
array”);
for(i=0;i<no;i++)
printf(“\n%d”,a[i]);
small=a[0];
large=a[0];
for(i=1;i<no;i++)
{
If(a[i]>large
large=a[i];
else if(a[i]<small)
small=a[i];
}
Printf(“\nThe largest of the given array is %d”,large);
OUTPUT :
In how many numbers you want to insert….5
Enter the elements of the array….
12 34 56 87 43
The elements of the array 12 34 56 87 43
The largest of the given array is 87
The smallest of the given array is 12
RESULT:
Thus the largest and smallest number of the given array using c program has been
executed successfully.
Ex.No.6(a) FIND THE ADDITION OF TWO MATRIXES
DATE :
AIM:
ALGORITHM:
9. Add the elements of A and B in column wise and store the result in C matrix
10. After the execution of the two loops Print the value of C matrix
#include<stdio.h>
#include <conio.h>
Void main()
int a[25][25],b[25][25],c[25][25],I,j,m,n;
4 5 6
7 8 9
2 4 6
8 10 12
14 16 18
RESULT:
Thus the program to add two matrix by using C program has been executed successfully.
EX.NO.6(b) PROGRAM TO REVERSE THE ARRAY ELEMENTS
DATE:
AIM
ALGORITHM
PROGRAM :
#include<stdio.h>
int main()
{
int n, arr[n], i;
printf("Enter the size of the array: ");
scanf("%d", &n);
printf("Enter the elements: ");
for(i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
int rev[n], j = 0;
for(i = n-1; i >= 0; i--)
{
rev[j] = arr[i];
j++;
}
printf("The Reversed array: ");
for(i = 0; i < n; i++)
{
printf("%d ", rev[i]);
}
}
OUTPUT :
RESULT :
Thus the program to reverse the array elements can be implemented successfully
Ex.No.7(a) PROGRAM TO FIND WHETHER THE GIVEN STRING IS
AIM:
To write the c program to find whether the given string is palindrome or not
ALGORITHM:
while(name[len]!=’\0’)
len++;
printf(“\n%d”,len);
for(i=0,j=len-1;i<len/2;i++,j--);
{
If(name[i]!=name[j])
{
Printf(“\nThe given string is not a
palindrome”); Exit(0);
}
}
Printf(“\n The given string is a palindrome”);
}
OUTPUT :
RESULT :
Thus the program for palindrome has been implemented successfully.
Ex.no:7(b)
AIM:
ALGORITHM :
Step 5 : If two strings are equal then print the strings are equal.
PROGRAM:
#include <stdio.h>
#include<string.h>
int main()
{
char str1[20]; // declaration of char array
char str2[20]; // declaration of char array
int value; // declaration of integer variable
printf("Enter the first string : ");
scanf("%s",str1);
printf("Enter the second string : ");
scanf("%s",str2);
value=strcmp(str1,str2);
if(value==0)
printf("strings are same");
else
printf("strings are not same");
return 0;
}
SAMPLE OUTPUT :
RESULT :
Thus the C Program for compare two strings have been successfully implemented.
Ex.no.8(a) PROGRAM TO GENERATE FIBONACCI SERIES
Date:
AIM
ALGORITHM
Step 5 : Execute the for loop and add the result with previous number.
PROGRAM
#include<stdio.h>
int main()
{
int n1=0,n2=1,n3,i,number;
printf("Enter the number of elements:");
scanf("%d",&number);
printf("\n%d %d",n1,n2); //printing 0 and 1
for(i=2;i<number;++i) //loop starts from 2 because 0 and 1 are already printed
{
n3=n1+n2;
printf(" %d",n3);
n1=n2;
n2=n3;
}
return 0;
}
OUTPUT :
RESULT :
Thus the program to generate Fibonacci series has been implemented successfully.
EX.NO.8(b) PROGRAM TO GENERATE FIBONACCI SERIES USING
DATE: RECURSION
AIM
ALGORITHM
Step3 : Get the number of elements to generate Fibonacci series using recursion
Step 5 : Execute the for loop and add the result with previous number.
PROGRAM
#include<stdio.h>
void Fibonacci(int n)
{
static int n1=0,n2=1,n3;
if(n>0){
n3 = n1 + n2;
n1 = n2;
n2 = n3;
printf("%d ",n3);
Fibonacci(n-1);
}
}
int main()
{
int n;
printf("Enter the number of elements: ");
scanf("%d",&n);
printf("Fibonacci Series: ");
printf("%d %d ",0,1);
Fibonacci(n-2); //n-2 because 2 numbers are already printed
return 0;
}
OUTPUT:
RESULT :
Thus the program to generate Fibonacci series has been implemented successfully.
Ex.no:9(a)
AIM
ALGORITHM
Step 5 : Execute the swapping and function and print the exchanging values
of the variables.
PROGRAM
#include <stdio.h>
void swap(int , int); //prototype of the function
int main()
{
int a = 10; int b = 20;
printf("Before swapping the values in main a = %d, b = %d\n",a,b);
swap(a,b);
}
OUTPUT :
RESULT :
Thus the program for swapping two values by using call by value has been implemented
successfully.
EX.NO:9(b) SWAPPING TWO VALUES BY USING
AIM
ALGORITHM
Step 5 : Execute the swapping and function and print the exchanging values
of the variables.
PROGRAM :
#include <stdio.h>
void swap(int *, int *); //prototype of the function
int main()
{
int a = 10;
int b = 20;
printf("Before swapping the values in main a = %d, b = %d\n",a,b);
swap(&a,&b);
printf("After swapping values in main a = %d, b = %d\n",a,b);
}
void swap (int *a, int *b)
{
int temp;
temp = *a;
*a=*b;
*b=temp;
printf("After swapping values in function a = %d, b = %d\n",*a,*b);
}
OUTPUT :
RESULT :
Thus the program for swapping two values by using call by reference has been implemented
successfully.
Ex.No.10 (a) PROGRAM TO READ THE STUDENT DATA AND
DATE :
AIM:
Step 4 : Calculate the student who got the highest total marks
#include<stdio.h>
struct student
int sub1;
int sub2;
int sub3;
int sub4;
int sub5; };
void main()
clrscr();
for(i=0;i<=9;i++)
scanf("%d%d%d",& s[i].sub1,&s[i].sub2,&s[i].sub3,&s[i].sub4,&s[i].sub5);
total=s[i].sub1+s[i].sub2+s[i].sub3+s[i].sub4+s[i].sub5;
getch();
OUTPUT:
RESULT :
Thus the C program for create a structure and find out the average of a student marks was
implemented successfully.
Ex.no:10(b)
AIM
ALGORITHM
Step 4 : create a variable for pack and access the value of members.
PROGRAM :
int main( )
{
pack p ;
printf("\n Occupied size by union pack: %d",sizeof(pack) ) ;
p.a = 'G' ;
printf("\n Value of a:%c", p.a ) ;
p.b = 20 ;
printf("\n Value of b:%d",p.b ) ;
p.c = 2545.6250 ;
printf("\n Value of c:%f",p.c ) ;
p.a = 'G' ;
p.b = 20 ;
p.c = 2545.6250 ;
printf("\n Value of a:%c, b:%d, c:%f",p.a,p.b,p.c ) ;
return 0 ;
OUTPUT :
Value of a : G
Value of b: 20
Value of c : 2545.625
RESULT :
DATE:
AIM
ALGORITHM
Step1: Start
Step 2: Get the two Strings to be concatenated.
Step 3: Declare a new String to store the concatenated String.
Step 4: Insert the first string in the new string.
Step 5: Insert the second string in the new string.
Step 6: Print the concatenated string.
Step 7: Stop
PROGRAM
#include <stdio.h>
#include<string.h>
int main()
{
char s1[20]; // declaration of char array
char s2[20]; // declaration of char array
printf("Enter the first string : ");
scanf("%s", s1);
printf("\nEnter the second string :");
scanf("%s",s2);
strcat(s1,s2);
printf("The concatenated string is : %s",s1);
return 0;
}
OUTPUT :
RESULT :
Thus the Program for concatenation of two strings has been implemented successfully.
AIM
ALGORITHM
PROGRAM
#include <stdio.h>
#include <stdlib.h> // For exit()
int main()
{
FILE *fptr;
char filename[100], c;
fclose(fptr);
return 0;
}
OUTPUT :
RESULT :