Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
ARRAY-SORTING N NUMBERS
AIM
To write a C program to sort the array of n numbers in ascending and descending
order.
ALOGRITHM
Step 1: Start the program
Step 2: Get the total number f elements and store it in ,,n
Step 3: Assign i=1
Step 4: Repeat step 5 until i<=n
Step 5: Get the elements from the user and store it in an array ,,a
Step 6: Increment 1 by 1.Goto Step 4
Step 7: Assign i=1,j=1
Step 8: Repeat step 9 to 11 until i<n-1
Step 9: Repeat step 10 until i<n otherwise Goto step 12
Step 10: If value in array a[i] is greater than array valueva[j],then swap two values using
tempory variable otherwise
goto step11
Step 11: Increment j by 1.Goto Step 9
Step 12: Increment i by 1.Goto Step 8
Step 13: Assign i=1
Step 14: Repeat step 15 until i<n
Step 15: Display the array elements in ascending order. Increment I by 1.Goto step 14
Step 16: Assign i=n-1
Step 17: Repeat step 15 until i>=0
Step 18: Display the array elements in descending order. Increment I by 1.Goto step 17
Step 19: Display largest element, second largest element, smallest element and second
smallest element of an array a.
Step 20: Stop the program
PROGRAM
//Array Sorting
#include<stdio.h>
# include<conio.h>
void main()
{
int n,I,j,temp,a[10];
clrscr();
printf(\n Array sorting);
printf(\n Enter the number of elements);
scanf(%d,&n);
printf(\n Enter the elements)
//Loop for getting array
for(i=0;i<n;i++)
{
scanf(%d,&a[i]);
}
//Loop for sorting the array in ascending order
{
printf(The given number is not a prime number);
break;
}
i++;
}
if(i==num)
printf(The given number is a prime number);
break;
case 3:
if(num%2==0)
printf(The given number is a Even number);
else
printf(The given number is a Odd number);
break;
default:
exit(0);
}
}
getch();
}
OUTPUT
Enter the number to perform menu driven operations:6
Choose 1 of the options given below by entering the no:
1.Factorial of the given number
2.Prime number or not
3.Odd or even
4.Exit
1
The factorial of 6 is 720
Enter the number to perform menu driven operations:5
Choose 1 of the options given below by entering the no:
1.Factorial of the given number
2.Prime number or not
3.Odd or even
4.Exit
3
The given number is Odd number
Enter the number to perform menu driven operations:7
Choose 1 of the options given below by entering the no:
1.Factorial of the given number
2.Prime number or not
3.Odd or even
4.Exit
4
RESULT
Thus , the menu driven program was executed and the output was verified
Ex No:6b
ARRAY-SORTING DIGITS
AIM
To write a C program to sort the digits of a number in ascending order.
ALOGRITHM
Step 1: Start the program
Step 2: Get the total number f elements and store it in ,,n
Step 3: Assign n=0
Step 4: If num is greater than 0 then Goto Step 5
Step 5: Divide num by 10 and store the remainder in an array variable ,,a
Step 6: Divide num by 10 and store the quotient in num
Step 7:Increment n by 1 and Goto step 4
Step 8: Assign i=1,j=1
Step 9: Repeat step 9 to 11 until i<n-1
Step 10: Repeat step 10 until i<n otherwise Goto step 12
Step 11: If value in array a[i] is greater than array valueva[j],then swap two values using
tempory variable otherwise
goto step11
Step 12: Increment j by 1.Goto Step 9
Step 13: Increment i by 1.Goto Step 8
Step 14: Assign i=1
Step 15: Repeat step 15 until i<n
Step 16: Display the array elements in ascending order. Increment i by 1.Goto step 14
Step 17: Assign i=n-1
Step 18: Repeat step 15 until i>=0
Step 19: Display the array elements in descending order. Increment i by 1.Goto step 17
Step 20: Display largest element, second largest element, smallest element and second
smallest element of an array a.
Step 21: Stop the program
PROGRAM
// Digit Sorting
#include<stdio.h>
# include<conio.h>
void main()
{
int n=0,num,i,j,temp,a[10];
clrscr();
printf(\n Digit sorting);
printf(\n Enter a number);
scanf(%d,&num);
//Loop for searching and sorting the digits in an array
while(num>0)
{
a[n]=num%10;
num= num/10;
//Loop for sorting the array in ascending order
for(i=0;i<n-1;i++)
{
for(j=i ; i <n ; j++)
{
if(a[i]>a[j])
{
temp = a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf(\n The ascending order is \n);
//Loop for displaying the sorted array
for(i=0;i<n;i++)
{
printf(\n%d,a[i]);
}
printf(\n The descending order is \n);
//Loop for displaying the sorted array in reverse
for(i=n-1;i>=0;i--)
{
printf(\n%d,a[i]);
}
printf(\n The Largest Element in the array is %d:,a[n-1]);
printf(\n The smallest Element in the array is %d:,a[0]);
printf(\n The Second Largest Element in the array is %d:,a[n-2]);
printf(\n The Second smallest Element in the array is %d:,a[1]);
getch();
}
OUTPUT
Array sorting
Enter a number of elements:5
Enter the elements:3
8
3
5 3
Ex No:6c
ALL COMBINATIONS OF A 4 DIGIT NUMBER
AIM
To write a C program to print all combinations of a 4 digit number.
ALOGRITHM
Step 1: Start the program
Step 2: Get the number
Step 3: Assign i=0
Step 4: if n is greater than 0,Goto step 5 otherwise step 7
Step 5: Divide n by 10 and store the remainder in ar[i];
Step 6: Increment the value of I and divide n by 10 and store it in n.Goto Step 4
Step 7: print all combinations of a 4 digit number
Step 8: Stop the program
PROGRAM
// Possible combinations of 4 digit number
#include<stdio.h>
# include<conio.h>
void main()
{
int ar[5],n,i=0,temp,a,b,c,d
clrscr();
printf(\n Enter the number);
scanf(%d,&n);
while(n>0)
{
ar[i]=n%10;
n=n/10;
i++;
}
for(a=0 ;a<i; a ++)
{
for(b=0 ;b<i; b ++)
{
for(c=0 ;c<i; c ++)
{
for(d=0 ;d<i; d ++)
{
if(a==b||a==c||a==d||b==c||b==d||c==d)
printf(%d%d%d%d\n,ar[a], ar[b], ar[c], ar[d]);
}
}
}
}
getch();
}
for(i=0;i<n-1;i++)
{
for(j=i ; i <n ; j++)
{
if(a[i]>a[j])
{
temp = a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf(\n The ascending order is \n);
//Loop for displaying the sorted array
for(i=0;i<n;i++)
{
printf(\n%d,a[i]);
}
printf(\n The descending order is \n);
//Loop for displaying the sorted array in reverse
for(i=n-1;i>=0;i--)
{
printf(\n%d,a[i]);
}
printf(\n The Largest Element in the array is %d:,a[n-1]);
printf(\n The smallest Element in the array is %d:,a[0]);
printf(\n The Second Largest Element in the array is %d:,a[n-2]);
printf(\n The Second smallest Element in the array is %d:,a[1]);
getch();
}
OUTPUT
Digit sorting
Enter a number:946
The ascending order is
4
6
9
The descending order is
9
6
4
The Largest Element in the array is 9
The smallest Element in the array is 4:
The Second Largest Element in the array is 6:
The Second smallest Element in the array is 6:
RESULT
Thus , the C program to sort the array of n numbers in ascending and descending order was
executed and the output
was verified
Ex No:6d
MATRIX ADDITION AND SUBTRACTION
AIM
To write a C program to add and subtract the elements of two matrix.
ALOGRITHM
Step 1: Start the program
Step 2: Get the row size and column size and store it in ,,m and ,,n
Step 3: Assign i=0,j=0
Step 4: Repeat step 5 to 8 until i<m
Step 5: Repeat step 6 to7 until i<n
Step 6: Get the elements of a matrix and store it in an array ,,a
Step 7:Increment j by 1 and Goto step 5
Step 8:Increment i by 1 and Goto step 6
Step 9: Assign i=0,j=0
Step 10: Repeat step 11 to 14until i<m
Step 11: Repeat step 12 to 13 until i<n
Step 12: Get the elements of a matrix and store it in an array ,,b
Step 13:Increment j by 1 and Goto step 5
Step 14:Increment i by 1 and Goto step 6
Step 15: Assign i=0,j=0
Step 16: Repeat step 17 to 20 until i<m
Step 17: Repeat step 18 to 19 until i<n
Step 18:Perform addition and subtraction of each element in ,,a and ,,b matrices and store
the result in sum and diff matrix
Step 19:Increment j by 1 and Goto step 5
Step 20:Increment i by 1 and Goto step 6
Step 21:Dispay the resultant matrices sum and diff
Step 22:Stop the program
PROGRAM
// Matrix Addition And Subtraction
#include<stdio.h>
# include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],d[10][10]m,n,i,j,temp;
clrscr();
printf(\n Addition And Subtraction of the array);
printf(\n Enter a number of rows of the matrix);
scanf(%d,&m);
printf(\n Enter a number of columns of the matrix);
scanf(%d,&n);
//Loop for getting the value matrix A
printf(\n Enter the values of matrix A);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
OUTPUT
Enter the number1234
4321
4312
4231
4213
4132
4123
3421
3412
3241
3214
3142
3124
2431
2413
2341
2314
2143
2134
1432
1423
1342
1324
1243
RESULT
Thus , the C program to print all combinations of a 4 digit number was executed and the output
was verified.
Ex No:6e
VOWELS
AIM
To write a C program to count the number of the vowels and number of words in a
line.
ALOGRITHM
Step 1: Start the program
Step 2:Get the string and store it in variable ,,S
Step 3: Calculate the length of the string and store it in a variable ,,len
Step 4: Assign i=0,count=0,count1=1 and array ,,a with blank space
Step 5: Repeat step 6 to 8 until i<n
Step 6: If each character of a string is equal to ,,aor,,eor,,ior,,oor,,u
Step 8: Stop the program
PROGRAM
//to find the number of vowels in a line of text
#include<stdio.h>
# include<conio.h>
void main()
{
char s[20[;
int i,len,count=0,count1=1;
clrscr();
printf(\nEnter a string);
gets(s);
len=strlen(s);
for(i=0;i<len;i++)
{
if(s[i]==a|| s[i]==A|| s[i]==e|| s[i]==E|| s[i]==i|| s[i]==I|| s[i]==o|| s[i]==O||
s[i]==u|| s[i]==U)
{
count++;
}
if(strcmp(s[i],a[0])==0)
{
count1++;
}
}
printf(\n Total number of vowels in %s is %d,s,count);
printf(\n Total number of words in %s is %d,s,count1);
getch();
}
OUTPUT
Enter a string: hello world
Total number of vowels in hello world is 3
Total number of words in hello world is 2
RESULT
Thus , the C program to count the number of the vowels and number of words in a line was
executed and the output was verified.
Ex No:7a
STRING CONCATENATION
AIM
To write a C program to count the length of the string and concatenate two strings
using string handling functions.
ALOGRITHM
Step 1: Start the program
Step 2:Get two string and store it in variable ,,s1 and ,,s2
Step 3:
,,len1
Calculate the length of the string1 using strlen() function and store it in a variable
Step 4: Calculate the length of the strin2 using strlen() function and store it in a variable ,,len2
Step 5: Concatenate the two string in the first string using strcat() function
Step 6:Display lengths and two strings
Step 7: Stop the program
PROGRAM
#include<stdio.h>
# include<conio.h>
#include<string.h>
void main()
{
char s1[10], s2[10];
int len1, len2,c;
clrscr();
printf(\n String Functions to find the length concatenate\n)
printf(\nEnter the First string);
gets(s1);
printf(\nEnter the Second string);
gets(s2);
// To find the length of a string
len1=strlen(s1);
len2=strlen(s2);
printf(\n The length of First String is %d,len1);
printf(\n The length of Second String is %d,len2);
//To concatenate two string
strcat(s1,s2);
printf(\n After concatenating \n String 1 is);
puts(s1);
printf(\nString 2 is);
puts(s2);
getch();
}
OUTPUT
String Functions to find the length concatenate
Enter the First string
Enter the Second string
:pine
:apple
RESULT
Thus , the C program to count the length of the string and concatenate two strings using string
handling functions.
Ex No:7b
STRING PALINDROME
AIM
To write a C program to find whether the given string is palindrome or not using
string handling functions.
ALOGRITHM
Step 1: Start the program
Step 2:Get the string and store it in variable ,,s1
Step 3: Copy the contents of string 1 to string 2 using strcpy() function.
Step 4: Store the result of strcmp() of string 1 and string 2 in c
Step 5: if c equal to zero, Display string is palindrome , otherwise Display string is not
palindrome
Step 6: Stop the program
PROGRAM
#include<stdio.h>
# include<conio.h>
#include<string.h>
void main()
{
char s1[10], s2[10];
int c;
clrscr();
printf(\n String Palindrome Using String Functions \n)
printf(\nEnter the First string);
gets(s1);
// To find the length of a string
strcpy(s2,s1);
printf(\n After copying contents of String 1 to String 2,value of String 2 is );
puts(s2);
//To reverse the Given string
strrev(s1);
printf(\n The reverse of String1 is:);
puts(s1);
//To check whether the given string is palindrome or not
c=strcmp(s1,s2);
if(c==0)
printf(\n String is Palindrome);
else
printf(\n String is not Palindrome);
getch();
}
OUTPUT
String Palindrome Using String Functions
Enter the First string
:madam
:science
Ex No:7c
STRING CONCATENATION WITHOUT USING STRING FUNCTION
AIM
To write a C program to count the length of the string and concatenate two strings
without using string handling functions.
ALOGRITHM
Step 1: Start the program
Step 2:Get two string and store it in variable ,,s1 and ,,s2
Step 3: Set len1=0,i=0;
Step 4:If s1[i] not equal to null pointer ,Incrementing the variable len1 and Repeat the Step,
Otherwise go to next Step.
getch();
}
OUTPUT
String Functions to find the length concatenate
Enter the First string
Enter the Second string
:pine
:apple
RESULT
Thus , the C program to count the length of the string and concatenate two strings without using
string handling functions.
Ex No:7d
STRING PALINDROME WITHOUT USING STRING FUNCTION
AIM
To write a C program to find whether the given string is palindrome or not without
using string handling functions.
ALOGRITHM
Step 1: Start the program
Step 2:Get two string and store it in variable ,,s1 and ,,s2
Step 3: Set len1=0,i=0;
Step 4:If s1[i] not equal to null pointer ,Incrementing the variable len1 and Repeat the Step,
Otherwise go to next Step.
Step 9:Stop the program
PROGRAM
#include<stdio.h>
# include<conio.h>
#include<string.h>
void main()
{
:computer
:madam
: madam
String is Palindrome
RESULT
Thus , the C program to find whether the given string is palindrome or not without using string
handling functions.
Ex No:8a
FUNCTION WITH ARGUMENTS WITH RETURN TYPE
AIM
To write a C program to add two numbers by using function with arguments with return types
ALGORITHM
Step 1:Start the program
Step 2:Get two numbers from the user and store it in a variable ,,a and ,,b
Step 3:Call the function add() and store the result in ,,c.
Step 4:Display the result ,,c
Step 5:Stop the program.
FUNCTION add(a,b)
Step 1:Add the values of ,,a and ,,b and store the result in a variable ,,c
Step 2:Return the result of ,,c to main function
PROGRAM
//add two numbers using function with argument with return type
#include<conio.h>
int add(int,int)
void main()
{
int a,b,c;
clrscr();
printf(\n Add two numbers using function with argument with return type);
printf(\n Enter the value of a and b);
scanf(%d%d,&a,&b);
c=add(a,b);
printf(\n Addition of %d and %d is %d,a,b,c);
getch();
}
Addition of 6 and 8 is 14
RESULT
Thus , the C program to add two numbers by using function with arguments with return types
was executed and the output was verified.
Ex No:8b
PRODUCT OF TWO NUMBERS WITHOUT USING * OPERATOR
AIM
To write a C program to create a function to find the product of two numbers without using *
operator.
ALGORITHM
Step 1:Start the program
Step 2:Call the function mult() and store the result in ,,prod.
Step 3:Display the result ,,prod
Step 4:Stop the program.
FUNCTION mult(a,b)
Step 1: Assign c=0 , i=1
Step 2: Get two numbers from the user and store it in a variable ,,a and ,,b
Step 3: if I less than or equal to b , goto step 4,otherwise goto step 5
Step 4: Add a and c and store it in c. Increment i and goto step 3
Step 5: return c to main function
PROGRAM
//Program to perform Multiplication without using *
#include<stdio.h>
#include<conio.h>
//function without arguments and with return type
int mult();
main()
{
int prod;
clrscr();
printf(\n Multiplication of two numbers without using *\n);
prod=mult();
printf(\n The product of two numbers are:%d,prod);
getch();
}
int mult()
{
int a,b,c=0,i;
printf(\n Enter the first number);
scanf(%d,&a);
printf(\n Enter the second number);
scanf(%d,&b);
for(i=1;i<=b;i++)
{
c=c+a;
}
return c;
}
Ex No:8c
FUNCTION WITH ARGUMENT AND WITHOUT RETURN VALUE
AIM
To write a C program to illustrate function with argument and without return values
ALGORITHM
Step 1: Start the program
Step 2: Enter the two numbers.
Step 3: Call the function with two arguments passed to it.
Step 4: Add the two numbers in the calling function.
Step 5: Print the addition value in the calling function.
Step 6:Stop the program
PROGRAM
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
clrscr();
printf(\n Enter two numbers);
scanf(\n %d%d,&a,&b);
c=add(a,b);
printf(\n The addition of two numbers %d and %d is %d,a,b,c);
getch();
}
add(int x, int y)
{
int z;
z=x+y;
return(z);
}
OUTPUT
Enter two numbers:76 17
The addition of two numbers 76 and 17 is 93
RESULT
Thus , the program for a with argument with return values was executed and the output was
verified.
OUTPUT
Multiplication of two numbers without using *
Enter the first number 4
Enter the second number 5
The product of two numbers are:20
RESULT
Thus , the C program to find the product of two numbers without using * operator was executed
and the output was verified.
Ex No:9
FACTORIAL USING RECURSION
AIM
To write a C program to find the factorial of a number using recurion.
ALGORITHM
Step 1: Start the program
Step 2: Get a number to find factorial from the user and store it in ,,n
Step 3: Call the recursive function fact() and store the result in ,,f.
Step 4: Display the factorial of a number ,,f.
Step 5:Stop the program
RECURSIVE FUNCTION fact(n)
Step 1: Assign f=1
Step 2:If n is equal to 1 then return 1
Step 3: Otherwise call the recursive function fact(n-1)
Step 4: return f to main function
PROGRAM
#include<stdio.h>
#include<conio.h>
int fact(int)
main()
{
int n,f;
clrscr();
printf(\n Factorial of the number using recursion);
printf(\n Enter a number );
scanf(%d,&n);
f=fact(n);
printf(\n Factorial of %d is %d,n,f);
getch();
}
int fact(int n)
{
int f=1;
if(n==1)
return 1;
else
{
f=n*fact(n-1); return f;
}
OUTPUT
Factorial of the number using recursion
Enter a number 5
Factorial of 5 is 120
RESULT
Thus , the C program to find the factorial of a number using recurion was executed and the
output was verified.
Ex No:10a
STRUCTURE
AIM
To write a C program to assign the values to a structure variables and retrieving the values
ALGORITHM
Step 1: Start the program
Step 2: Declare a structure called stud which contains structure variables names , m1, m2, m3,
total and avg
Step 3: Declare the structure variable ,,s
Step 4:Get the name and marks of the students from the user and store it in a structure
Step 5: calculate and display athe total ,average and grade
Step 6:Stop the program
PROGRAM
#include<stdio.h>
#include<conio.h>
struct stud
{
char name[25];
int m1,m2,m3,total;
float avg;
s[50];
}
main()
{
int n,i;
clrscr();
printf(\n Enter the number of students\n);
scanf(%d,&n);
for(i=0;i<n;i++)
{
printf(\n Enter the %d student name,i+1);
scanf(%s,s[i].name);
printf(\n Enter the %d student mark1,i+1);
scanf(%d,s[i].m1);
Ex No:10b
SORTS NAMES USING ARRAYS AND STRUCTURE
AIM
To write a C program to arrange the given names in alphabetical order
ALOGRITHM
Step 1:Start the program
Step 2:Declare a structure called names
Step 3:Get the total number of names from the user and store it in variable ,,n
Step 4:Assign i=0
Step 5:Repeat step 6 to 7 until i<=n
Step 6:Get the names from the user and store it in structure array variable ,,a
Step 7:Increment i by 1.Goto step 5
Step 8:Assign i=1,j=i+1
Step 9: Repeat step 10 to 12 until i<n-1
Step 10:Repeat step 11 until i<n,otherwise goto step 13
Step 11:Compare array s[i] with s[j],.if it is greater than 0,then swap two names using temporary
variable otherwise goto step 12
dinesh
98
kani
78
aishu
Mark 2
97
82
Mark 3
Total
96
291
77
76
231
81
83
Average
246
97.000000
77.000000
82.000000
RESULT
Thus , the C program to assign the values to a structure variables and retrieving the values was
executed and the output was verified.
Ex No:10c
UNION
AIM
To write a C program to display the student mark details using union
ALGORITHM
Step 1:Start the program
Step 2:Declare a union called stud which contains union variables name, m1, m2, m3,total,avg
and g
Step 3: Declare a structure variable ,,a
Step 4:Get the name,three marks and store it in a union variable
Step 5: Calculate the sum of three marks and store it a union variables.
getch();
}
s[i]=s[j];
s[j]=temp;
}
}
}
printf(\n sorted names);
for(i=0;i<n;i++)
printf(%s\t,s[i].a);
getch();
}
OUTPUT
Enter the no of names to be entered 4
Enter the 4 names
xyz
abc
wxz
ijk
Sorted name is abc ijk wxz xyz
RESULT
Thus , the C program to arrange the given names in alphabetical order was executed and the
output was verified.
Ex No:11a
SWAP TWO NUMBERS USING CALL BY REFERENCE
AIM
To write a C program to swap two numbers using call by value
ALGORITHM
Step 1:Start the program
Step 2:Enter the two numbers
Step 3: Call the swap function
Step 4:Pass the value of the two numbers to the calling function
Step 5: Get the value in the calling function
Step 6:Swap the number using temporary variable.
Step 7:Print the swapped values in the main function
Step 8:Stop the Program
PROGRAM
#include<stdio.h>
#include<conio.h>
void swap(int,int)
main()
{
int x,y;
clrscr();
printf(\n Enter the two numbers:);
scanf(%d%d,&x,&y);
printf(\n Before Swapping \n x=%d\t y=%dx,y);
display(x,y);
printf(\n After Swapping \n x=%d\t y=%dx,y);
getch();
}
void swap(int a,int b)
{
int t;
t=a;
a=b;
b=t;
OUTPUT
Enter the details of a student
Enter name,mark1, ,mark2 ,mark3
Karthi
87
90
88
Student mark statement
Name
Total
Avg
65
88.000496
Grade
A
RESULT
Thus , the C program to display the student mark details using union was executed and the
output was verified.
Ex No:11b
SWAP TWO NUMBERS USING CALL BY REFERENCE
AIM
To write a C program to swap two numbers using call by reference
ALGORITHM
Step 1:Start the program
Step 2:Enter the two numbers
Step 3: Call the swap function
Step 4:Pass the address of the two numbers to the calling function
Step 5: Get the address in the calling function
Step 6:Swap the number using temporary variable.
Step 7:Print the swapped values in the main function
Step 8:Stop the Program
PROGRAM
#include<stdio.h>
#include<conio.h>
void swap(int *,int *)
main()
{
int x,y;
clrscr();
printf(\n Enter the two numbers:);
scanf(%d%d,&x,&y);
printf(\n Before Swapping \n x=%d\t y=%dx,y);
display(x,y);
printf(\n After Swapping \n x=%d\t y=%dx,y);
getch();
}
void swap(int *a,int *b)
{
int *t;
*t=*a;
*a=*b;
*b=*t;
printf(\n Inside swap Function the value of a=%d\t b=%d,a,b);
}
OUTPUT
Enter the two numbers 17 56
Before Swapping
x=17 y=56
Inside swap Function the value of a=17 b=56
After Swapping
x=56 y=17
RESULT
Thus , the C program to swap two numbers using call by reference was executed and the output
was verified.
EX NO:12
AIM
To write a C program in UNIX to illustrate the basic concepts of pointers
ALGORITHM
Step 1:Start the program
Step 2:Read an integer a
Step 3: Declare a pointer variable b and assign the address of a to b
Step 4: Declare a pointer- pointer variable c and assign the address of b to c
Step 5:Print the value of a,*(&a),,*b,b,c,&a,&b,*c,c,&c
Step 6:Stop the Program
PROGRAM
#include<stdio.h>
#include<conio.h>
Void main()
{
In t a ,*b,*c;
Printf(\n Enter the value of a);
Scanf(%d,&a);
b=&a;
c=&b;
printf(\n value of a is %d,a);
printf(\n value of a is %d,*(&a));
printf(\n value of a is %d,*b);
printf(\n value of a is %d,**c);
printf(\n value of b and address of a is %u,b);
printf(\n value of c and address of b is %u,b);
printf(\n address of a is %u,&a);
printf(\n address of b is %u,&b);
printf(\n address of a is %u,*c);
printf(\n address of b is %u,c);
printf(\n address of c is %u,&c);
getch();
}
OUTPUT
Enter the value of a:10
value of a is 10 value of a is 10
value of a is 10 value of a is 10
value of b and address of a is 65524
value of c and address of b is 65522
address of a is 65524 address of b is 65522
address of a is 65524
address of b is 65522
address of c is 65520
RESULT
Thus , the C program to illustrate the basic concepts of pointers was executed and the output
was verified.
EX NO:13
AIM
To write a C program to print the cosine series.
ALGORITHM
COSINE SERIES
t=2*i;
sum+(pow(-1,i)*(pow(x,t))/((float) fact(t)));
}
printf(\n Sum of series=%.2f,sum);
getch();
}
int fact(int x)
{
int i,f=1;
for(i=1;i<=x;i++)
f=f*i;
return(f);
}
OUTPUT
Sum Series
Enter the value of x & n 2
1
Sum of series = -1.00
RESULT
Thus , the C program to print the cosine series executed and the output was verified.