C
Language
Array & String
Fill in the blanks
1.Array is Collection of Similar data
type
2.Types of Array 2
3.Write array syntax datatype variablename[size]={value};
4. In Single dimensional array only
presents in Row
5. In Multidimensional array presents
in Row & Coloumn
6. int a[2][2]= {{3,8},{5,4}. a[0][1]= 8
7.int a[5]={1,8,3,10,15}. a[5] =
0 ,
a[2]= 8
8. Array allows string.[T/F] False
9.We can store character in Array
.[T/F] True
10.Array is a Collections of different
data type. [T/F]. False
11.
Array stores multiple values in single variable.[T/F]. True
12.Write a syntax for multidimensional
Array datatype variablename[row
size][coloumn size]={value};
13.Write a header file for String
function string.h
14. char name[5]=”apple”.strlen(name)
= 5
15. char a[5]=”hEllo”.strupr(a)= HELLO
16.char b[3]=”HaI”.strlwr(b)= hai
17.char s1[5]=”hello”;char
s2[5]=”world”.strcat(s1,s2)=
hello world
18.char s[7]=”welcome”.strrev(s)= emoclew
19. s1=”happy”.strcpy(s2,s1)= happy
20.s1=”hello”.s1 is Palindrome.[T/F]. False
21.Array index starts from 0 index
Answer the following Question
(4
marks)
1.Write a program for single
dimensional array.
#include<stdio.h>
#include<conio.h>
main()
{
int a[5],i;
clrscr();
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<5;i++)
{
printf("\n %d",a[i]);
}
getch();
}
2.Write a program to convert a word into lower case and upper case using String Function
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char name[30];
clrscr();
printf("Enter your name:");
gets(name);
printf("The Uppercase string
is:%s\n",strupr(name));
printf("the Lowercase string
is:%s",strlwr(name));
getch();
}
3.Write a program for strlen() and
strrev() function using string
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char name[30];
int len;
clrscr();
printf("Enter your
name:");
gets(name);
len=strlen(name);
strrev(name);
printf("The length of
the string is:%d\n",len);
printf("The reversed
string is:%s",name);
getch();
}
Answer the following Question
(10
marks)
1.What is Array?Write a program for Multidimensional Array?
Array is a collection of similar data type stored in
continuous Memory location.
#include<stdio.h>
#include<conio.h>
main(){
int i,j,a[2][2];
clrscr();
printf("Enter the values \n");
for(i=0;i<2;i++){
for(j=0;j<2;j++){
scanf("%d",&a[i][j]);
}
}
printf("\n Matrix a \n");
for(i=0;i<2;i++){
for(j=0;j<2;j++){
printf("%d\t",a[i][j]);
}
printf("\n");
}
getch();
}
2. Write a Program for String Palindrome using string function strcpy(),strcmp(),strrev().
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char name[30],string[30],reverse[30];
clrscr();
printf("Enter your name:");
gets(name);
strcpy(string,name);
gets(name);
strcpy(string,name);
strcpy(reverse,strrev(name));
if(strcmp(string,reverse)==0)
{
printf("the string %s is Palindrome",string);
}
else
{
printf("the string%s is not
Palindrome",string);
}
getch();
}
3.Write a program for strcat(),strstr(),strchr() function using string
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char s1[30],s2[30];
clrscr();
printf("enter the string:");
gets(s1);
printf("Enter the sring:");
gets(s2);
strcat(s1,s2);
if(strchr("Hello",'e'))
{
printf("e is in hello\n");
}
else{
printf("e is not in hello\n");
}
if(strstr(hai
everybody","hai"))
{
printf("found hai\n");
}
else
{
printf("Not found hai\n");
}
printf("the concatenated string
is:%s\n",s1);
getch();
}
No comments:
Post a Comment