0% found this document useful (0 votes)
11 views18 pages

Vishakha

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views18 pages

Vishakha

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

TEACHER

S.NO DATE PROJECT NAME SIGN.


1. Write a program to initialize and display array
elements.
2. Write a program to input 8 elements in array
and display them in reverse order.
3. Write a program to search a particular program
in array and display its position.
4. Write a program to sort the elements in array.

5. Write a program to input elements in a square


matrix and display matrix and its transpose.
6. Write a program to explain the use of pointer.

7. Write a program to find the length of string


using the strlen function.
8. Write a program to the string into another string
without using the strlen function.
9. Write to input the structure variable through
keyboard and display them.
10. Write a program to input and display data for
union.
1. Write a program to initialize and display array elements.
#include <stdio.h>
#include<conio.h>
void main()
{
int a[5]= {10, 20, 30, 40, 50};
int c;
clrscr();
for(c=0; c<=4; c++)
{
printf(“\n %d”, a[c]);
}
getch();
}

OUTPUT
10
20
30
40
50
2. Write a program to input 8 element in array and display
them reverse order.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[8], c;
clrscr();
printf(“\n Enter 8 element of array “);
for(c=0; c<=7; c++)
scanf(“%d”, &a[c]);
printf(“\n display elements”);
for(c=7; c>=0; c++)
{
printf(“\n %d”, a[c]);
}
getch();
}
OUTPUT
Enter 8 element of array
1
2
3
4
5
6
7
8
Display elements
8
7
6
5
4
3
2
1
3. Write a program to search a particular element in the
array and display its position.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10] c, se, f=0;
clrscr();
printf(“\n enter 10 elements of array”);
for(c=0; c<=9; c++)
scanf(“%d”, &a[c]);
printf(“\n enter search element”);
scanf(“%d”, &se);
for(c=0; c<=9; c++)
{
if(a[c]==se)
{
printf(“\n element found at position %d”,
c+1);
f=1;
}
}
if(f==0)
printf(“\n element not found”);
getch();
}

OUTPUT
Enter 10 element of array
5
54
34
56
76
55
87
75
21
49
Enter search element 76
Element found at position 5
Element found at position of 76
4. Write a program to sort the element of array.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5] , i, j, temp;
clrscr();
for(i=0; i<=4; i++)
{
printf(“\n Enter elements”);
scanf(“%d”, &a[c]);
}
for(i=0; i<=4; i++)
{
for(j=0; j<4-I; j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf(“\n Display element in descrending order");
for(i=0; i<=4; i++)
{
printf(“\n %d”, a[i]);
}
getch();
}

OUTPUT
Enter elements
7
Enter elements
21
Enter elements
20
Enter elements
9
Enter elements
49
Display element in descrending
order
7
9
20
21
49
5. Write a program to input element in a square matrix
and display matrix and its transpose.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3], r,c;
clrscr();
for (r=0; r<=2; r++)
{
for(c=0; c<=2; c++)
{
printf(“\n Enter element”);
scanf(“%d “, &a[r][c]);
}
}
printf(“\n Display element of 2-D array \
n”);
for(c=0; c<=2; c++)
{
for(r=0; r<=2; r++)
{
printf(“\t %d”a[r][c]);
}
printf(“\n”);
}
printf(“\n Display transpose \n”);
for(c=0; c<=2; c++)
{
for(r=0; r<=2; r++)
{
printf(“\t %d “, a[c][r]);
}
printf(“\n”);
}
getch();
}

OUTPUT

Enter element
1
Enter element
2
Enter element
3
Ener element
4
Enter element
5
Enter element
6
Enter element
7
Enter element
8
Enter element
9
Display element of 2-D array
1 2 3
4 5 6
7 8 9

Display transpose
1 4 7
2 5 8
3 6 9
6. Write a program to the explain use of pointer.
#include<stdio.h>
#include<conio.h>
void main()
{
int i=3, *j;
j=&I;
clrscr();
printf(“\n value of i is %d”, i);
printf(“\n value of j is %u”, j);
printf(“\n Address of i is %u”, &i);
printf(“\n Address of j is %u”, &j);
printf(“\n value of i is %d”, *j;
printf(“\n value of j is %d”, *(&i));
getch();
}

OUTPUT
Value of i is 3
Value of j is 65522
Address of i is 65522
Address of j is 65524
Value of i is 3
Value of i is 3
7. Write a program to find the length of string using
strlen() function.
#include<stdio.h>
#include<conio.h>
void main()l
{
charstr[20];
int l1, l2;
clrscr();
printf(“\n Enter any string”);
gets(str);
l1= strlen(str);
l2= strlen(“Hello world”);
printf(“\n length of first string is %d”, l1);
printf(“\n length of second string is %d",l2);
getch();
}
OUTPUT
Vishakha
Length of first string is 6
Length of second sting is 11
8. Write a program to copy the string into another string
without using string function.
#include<stdio.h>
#include<conio.h>
void main()
{
charsstr[20], tstr[20];
int i, j;
clrscr();
i=0;
j=0;
printf(“\n Enter the source string”);
gets(sstr);
while(sstr[i];=”\o”)
{
tstr[j]=sstr[i];
j++;
i++;
puts(tstr);
getch();
}

OUTPUT
Enter the source string
Hello
Hello
9. Write a program to input the structure variable through
keyboard and display them.
#include<stdio.h>
#include<conio.h>
struct book;
{
int pages;
float price;
char name[20]
};
void main()
{
struct book b;
clrscr();
printf(“\n Enter pages in book”);
scanf(“%d”, &b.pages);
printf(“\n Enter price of book”);
scanf(“%d”, &b.price);
printf(“\n Enter name of book”);
gets(b.name);
printf(“\n now display”);
printf(“n pages in book =%d \n price of
book=%f \n name of book =%s”, b.page,
b.price, b.name);
getch();
}

OUTPUT
Enter the pages in book
80
Enter price of book
383.99
Enter name of book
“let us c”
Now display
Pages in book =80
Price of book =383.99
Name of book =”let us c”
10. Write a program to input and display data for union.
#include<stdio.h>
#include<conio.h>
union employee
{
char name [20];
int age;
floatsal;
};
void main()
{
union employee emp;
clrscr();
printf(“\n Enter name of employee “);
gets(emp.name);
printf(“\n name of employee is %s”,
emp.name);
printf(“\n Enter age of employee”);
scanf(“%d”, &emp.age);
printf(“\n age of employee is %d”,
emp.age);
printf(“\n enter salary of employee”);
scanf(“%f”, &emp.sal);
printf(“salary of employee is %f”, emp.sal);
getch();
}

OUTPUT
Enter name of employee
Vishakha
Name of employee is Vishakha
Enter age of employee
18
Age of employee is 18
Enter salary of employee
20000
Salary of employee is 20000

You might also like