Professional Documents
Culture Documents
CP 2 Front
CP 2 Front
CP 2 Front
• It allows us to enter only fixed number of elements into it. pointed which
We cannot alteristhe
more
sizethan
of the dimension specified, then we will get run time errors
the array once array is declared. Hence if we need to insertrather
morethan identifying
number them at compile time.
of records
Example:
than declared then it is not possible. We should know array size at the compile time
itself. int a[3]={1,2,3}
m
printf("%d",A[3]);
• Inserting and deleting the records from the array would be costly since we add /
EST102 Programming in C
co
Output:
delete the elements from the array, we need to manage memory space too. 3245431 (Garbage Value)
• It doeschar
notstr[]="Hello
verify the World"; https://www.keralanotes.com/
indexes while compiling the array. In1.case Write a program
there to read and display an array of size n.
is any indexes
.
len value will the length of the string which is 11. But size value will be 12 including the
m com
scanf("%d",&n);
printf("%d",A[3]);
end of character. EST102 Programming in C
for(i=0;i<n;i++)
Output:
Output 3245431 (Garbage Value)
al
PROGRAM
ke
#include<stdio.h>
s. es
} To multiply two matrices, the number of columns of the first matrix should be
strcat
void main()
#include<stdio.h> { for(i=0;i<n;i++) equal to the number of rows of the second matrix.
It concatenates two strings and returns the concatenated string.
ot
#include <stdio.h> }
int employeeID; scanf("%d",&n); void main()
char ename[25]; #include <string.h>
for(i=0;i<n;i++) } {
OUTPUT int i,j,k,m, n, p, q,sum = 0;
ra ral
EST102
theProgramming in C scanf("%d%d", &m, &n);
no
int n,i; {} } if (n != p)
printf("Enter the total number of employees:\n"); Output:printf("%d\t",A[i]);
str1[i]='\0'; Enter the number:50 printf("The multiplication isn't possible.\n");
co
scanf("%d",&n); printf("\nOutput:
}After concatenation: %s",str1);
HelloWorld else
} IIPE 2
ke
{ strcpy
Enter the size of Array: 5
#include <stdio.h> For More Study Materials : www.keralanotes.com
for (j = 0; j < n; j++)
printf("Enter the employeeID :"); Enter the number:10
void It copies the string str2 into string str1, including the end character (terminator
main()
no
scanf("%d", &A[i][j]);
scanf("%d",&e1[i].employeeID); Enter the
{ number:20
char ‘\0’). printf("Enter elements of second matrix\n");
printf("Enter the employee name:"); Enter the number:30
char str1[50], str2[25], i, j; for (i = 0; i < p; i++)
Syntax: strcpy(string1,string2) - copy the content of string2 to string1
la
scanf("%s",e1[i].ename); printf("\nEnter
Enter the number:40 first string: "); for (j = 0; j < q; j++)
#include <stdio.h>
gets(str1);
printf("Enter the salary:"); Enter the number:50
ra
scanf("%d", &B[i][j]);
#include <string.h>
printf("\nEnter second string: ");
scanf("%f",&e1[i].salary); for (i= 0; i < m; i++)
void main()
gets(str2);
ke
} IIPE 2 {
{ for(i=0; str1[i]!='\0'; i++);
om
str1[i]='\0';
printf("%d %s %f \n",e1[i].employeeID,e1[i].ename,e1[i].salary); Output:printf("\nOutput: %s",str1); C[i][j]= C[i][j] + A[i][k]*B[k][j];
} String
} For More
s1 : Hello World Study Materials : www.keralanotes.com }
ot
}
Program to copy a string to another without using string handling function
} OUTPUT }
n
strcpy
#include<stdio.h> printf("Product of the matrices:\n");
Enter the total number of employees:
la
printf(“Enter IIPE 22
Enter the employeeID :112 #include <stdio.h> string1:”); printf("%d\t", C[i][j]);
Enter the employee name:Aishwarya gets(a);
Enter the salary:30 000 #include <string.h> }
for(i=0;a[i]!=‘\0’;i++)
void main() printf("\n");
Enter the employeeID :113
{
For More Study Materials : www.keralanotes.com
Enter the employee name:Sam { }
om
113 Sam 40.000000 } printf("String s1: %s", s1); PREVIOUS YEAR UNIVERSITY QUESTIONS
} 1. Explain the different ways in which you can declare & initialize a single dimensional
es
strcmp
Output: array. [KTU, MODEL 2020]
String s1 : Hello World 2. Write a C program to read a sentence through keyboard and to display the count of
ot
Program to copy a string to another without using string handling function white spaces in the given sentence. [KTU, MODEL 2020]
3. Write a C program to check whether a given matrix is a diagonal matrix. [KTU,
n
#include<stdio.h>
Downloaded from Ktunotes.in MODEL 2020]
la
void main()
IIPE 14 4. Write a C program to perform bubble sort. [KTU, MODEL 2020], [KTU, JULY 2017],
{