0% found this document useful (0 votes)
8 views7 pages

CSE Assignment -2(Abeer) (1)

The document contains solutions for assignments in a Structured Programming Language course, including code for student information management, matrix summation, character counting, and string manipulation functions. Each section provides C code examples demonstrating the functionality of structures, arrays, and string operations. Additionally, it includes input/output screenshots for each program.

Uploaded by

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

CSE Assignment -2(Abeer) (1)

The document contains solutions for assignments in a Structured Programming Language course, including code for student information management, matrix summation, character counting, and string manipulation functions. Each section provides C code examples demonstrating the functionality of structures, arrays, and string operations. Additionally, it includes input/output screenshots for each program.

Uploaded by

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

Assignment CSE

Assignment: 2
Course Code: CSE 111
Course: Structured Programming Language

Submitted to: Submitted by:


Name: Abu Quwsar Ohi Name: Ekramul Asfah Abeer
ID- 21225103134
Intake: 49
Section: 3
1.Student Information-
Solution:
#include<stdio.h>
struct payment{
float paid,due,waiver;
};
struct student{
int id,intake,section;
char name[36];
struct payment pay;
};
int main(){
struct student s;
s.id;
s.pay.paid;
printf("Input are:\n");
scanf("%d",&s.id);
scanf("%s",s.name);
scanf("%d",&s.intake);
scanf("%d",&s.section);
scanf("%f",&s.pay.paid);
printf("Output are:\n");
printf("Id number-%d\n",s.id);
printf("Name-%s\n",s.name);
printf("Intake-%d\n",s.intake);
printf("Section-%d\n",s.section);
printf("Paid-%.2f",s.pay.paid);
return 0;
}
Input/Output Screenshot:
2.Matrix Summation-

Solution:

#include<stdio.h>
int main(){
int r,c,a[2][3],b[2][3],sum[2][3],i,j;
printf("The number of rows:");
scanf("%d",&r);
printf("The number of columns:");
scanf("%d",&c);
printf("\nValues of matrix A:\n");
for(i=0;i<r;i++)
for(j=0;j<c;j++){
scanf("%d",&a[i][j]);
}
printf("\nValues of matrix B:\n");
for(i=0;i<r;i++)
for(j=0;j<c;j++){
scanf("%d",&b[i][j]);
}
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
sum[i][j] = a[i][j] + b[i][j];
}
printf("\nSummation of matrix are: \n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
printf(" %d",sum[i][j]);
if(j==c-1){
printf("\n\n");
}
}
return 0;
}
Input/Output Screenshot:

3. Counting-

Solution:

#include<stdio.h>
#include<string.h>
int main (){
char s[1000];
int i,vowels=0,consonants=0;
printf("Given String : ");
gets(s);
for(i=0;s[i];i++){
if((s[i]>=65 && s[i]<=90)||(s[i]>=97 && s[i]<=122))
{
if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||
s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U')
vowels++;
else
consonants++;
}
}
printf("Vowels = %d\n",vowels);
printf("Consonants = %d",consonants);
return 0;
}
Input/Output Screenshot:

4.String Functions:

a.strlen-
The strlen() function calculates the length of a given string.The strlen() function is defined
in string.h header file. It doesn’t count null character ‘\0’.
Syntax:
int strlen(const char *str);
Parameter:
• str: It represents the string variable whose length we have to find.
Return: This function returns the length of string passed.
Example:

#include<stdio.h>
#include<string.h>
int main (){
char str[]={"Abeer"};
printf("Length of string is = %d",strlen (str));
return 0;
}

b.strcmp-
strcmp() is a built-in library function and is declared in <string.h> header file. This function
takes two strings as arguments and compare these two strings lexicographically.
Syntax:
int strcmp(const char * str1, const char * str2);
Parameters:
• str1 – a string
• str2 – a string
Return Value From strcmp()-

Return Value Remarks


0 if strings are equal.
>0 if the first non-matching character in str1 is greater than that of str2.
<0 if the first non-matching character in str1 is lower than that of str2.

Example:

#include<stdio.h>
#include<string.h>
int main (){
char str1[]={"Abeer"};
char str2[]={"Abeer"};
int res = strcmp(str1,str2);
if (res==0)
printf("Strings are equal");
else
printf("Strings are not equal");
return 0;
}

c.strcpy-
strcpy() is a standard library function in C and is used to copy one string to another. In C it
is present in string.h header file.

Syntax:
char*strcpy(char*dest, const char*src);
Parameters:
• dest: Pointer to the destination array where the content is to be copied.
• src: string which will be copied.
Return Value: After copying the source string to the destination string, the strcpy() function
returns a pointer to the destination string.

Example:
#include<stdio.h>
#include<string.h>
int main (){
char str1[10]={"Abeer"};
char str2[10];
strcpy(str2,str1);
puts(str2);
return 0;
}
d.strcat-
The strcat() function is used for string concatenation. It concatenates the specified string at the
end of the another specified string.
Syntex:
char*strcat(char*str1, const char*str2);
Parameters:
• dest: This is a pointer to the destination array, which should contain a C string, and
should
be large enough to contain the concatenated resulting string.
• src: . This is the string to be appended. This should not overlap the destination.

Return value: The strcat() function returns dest, the pointer to the destination string.
Example:
#include<stdio.h>
#include<string.h>
int main (){
char str1[10]={"My name "};
char str2[10]={"is Abeer"};
strcat(str1,str2);
puts(str1);
puts(str2);
return 0;
}

You might also like