0% found this document useful (0 votes)
36 views5 pages

Assignment#04 Q#01: #Include #Include

The document contains code for two C programming questions: 1) A program that takes a first and last name as input and prints the abbreviated initials. 2) A program that takes multiple strings as input, sorts them alphabetically, allows the user to search for a string, and performs additional string operations like concatenation and counting alphabets. The additional operations demonstrate string handling functions like strcat, strcmp, etc.

Uploaded by

Abdullah Abid
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)
36 views5 pages

Assignment#04 Q#01: #Include #Include

The document contains code for two C programming questions: 1) A program that takes a first and last name as input and prints the abbreviated initials. 2) A program that takes multiple strings as input, sorts them alphabetically, allows the user to search for a string, and performs additional string operations like concatenation and counting alphabets. The additional operations demonstrate string handling functions like strcat, strcmp, etc.

Uploaded by

Abdullah Abid
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/ 5

Assignment#04

Q#01

Code

#include<stdio.h>
#include<string.h>
int main()
{
printf("/*=================================================================\n");
printf("/* CSEE1122: Computer Programming\n");
printf("/* Student Name : Abdullah Abid\n");
printf("/* Registration No.: BEE193041\n");
printf("/* Section No.: 1\n");
printf("/* Assignment No.: 4\n");
printf("/* Question No.# 01\n");
printf("/*==================================================================\n");
int x;
char name[20];
char name1[20];
int var = 0, var1 = 0, n = 0;
printf("Enter Your first name :-\n ");
gets_s(name);
printf("enter your second name:-\n");
gets_s(name1);
var = strlen(name);
for (int i = 0; i <= var; i++)
{
if (name[i] == ' ')
{
n = i + 1;
}
}
var1 = strlen(name1);
for (int k = 0; k <= var1; k++)
{
if (name[k] == ' ')
{
n = k + 1;
}
}
printf("\nYour abbreviated name is :- ");
printf("%c.%c.", name[0], name1[0]);
printf("\n\n");
scanf_s("%d", &x);
return 0;
}
Output

Q#02

Code

#include<stdio.h>
#include<string.h>
int main() {
printf("/*=================================================================\n");
printf("/* CSEE1122: Computer Programming\n");
printf("/* Student Name : Abdullah Abid\n");
printf("/* Registration No.: BEE193041\n");
printf("/* Section No.: 1\n");
printf("/* Assignment No.: 4\n");
printf("/* Question No.# 02\n");
printf("/*==================================================================\n");
int i, j, k, z, count;
char str[25][25], temp[25];
char name[20];
char s1[100], s2[100];
char s3[100], s4[100];

puts("How many strings do you want to enter?: ");


scanf_s("%d", &count);

puts("Enter Strings one by one: ");


for (i = 0; i <= count; i++)
gets_s(str[i]);
for (i = 0; i <= count; i++)
for (j = i + 1; j <= count; j++) {
if (strcmp(str[i], str[j]) > 0) {
strcpy_s(temp, str[i]);
strcpy_s(str[i], str[j]);
strcpy_s(str[j], temp);
}
}
printf("Order of Sorted Strings:");
for (i = 0; i <= count; i++)
puts(str[i]);

char s5[50];
int n, found = 0;
printf("Enter name to search: ");
gets_s(s5);
for (k = 1; k <=count; k++)
{
if (strcmp(s5, str[k]) == 0)
{
found = 1;
printf("Found in row=%d\n", k);
printf("Enter string s1: ");
fgets(s1, sizeof(s1), stdin);

for (k = 0; s1[k] != '\0'; ++k) {


s2[k] = s1[k];
}

s2[k] = '\0';
printf("String s2: %s", s2);

printf("Enter string s3: ");


fgets(s3, sizeof(s3), stdin);

for (z = 0; s3[z] != '\0'; ++z) {


s4[z] = s3[z];
}

s4[z] = '\0';
printf("String s4: %s", s4);

char a[1000], b[1000];

printf("Enter the first string\n");


gets_s(a);

printf("Enter the second string\n");


gets_s(b);

strcat_s(a, b);
printf("String obtained on concatenation: %s\n", a);

char s[1000];
int y, alphabets = 0;
printf("Enter the string : ");
gets_s(s);
for (y = 0; s[y]; y++)
{
if ((s[y] >= 65 && s[y] <= 90) || (s[y] >= 97 && s[y] <= 122))
alphabets++;

}
printf("Alphabets = %d\n", alphabets);
}

return 0;
}
Output

You might also like