Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program that will read and store the details of a list of students in

ID: 3761116 • Letter: W

Question

Write a C program that will read and store the details of a list of students in the format below:

       ID                   NAME                     MARKS

Which will produce the following respective output

1.Alphabetical list of Names, ID’s and Marks.

2.List sorted on ID’s

3.List sorted on Marks

========================

Write a C program which will read a line of text and rewrite it in the alphabetical order.

=========================

Write a C program to replace a particular word by another word in a given string. Both the words are provided by the user at run time.

Explanation / Answer

Write a C program that will read and store the details of a list of students in the format below:

       ID                   NAME                     MARKS

Which will produce the following respective output

1.Alphabetical list of Names, ID’s and Marks.

2.List sorted on ID’s

3.List sorted on Marks

//Program

#define N 5
#include<stdio.h>
#include<string.h>
int main()
{
char names[N][30],marks[N][10];
char id[N][12],temp[30];
int i,j;
/* Reading Student Details */
printf("Enter Student ID NAME and MARKS ");
for(i = 0; i<N; i++)
scanf("%s %s %s",id[i],names[i],marks[i]);

/* Alphabetical Ordering of Names */
for(i=0; i<N-1; i++)
for(j=0; j<N-i-1; j++)
if(strcmp(names[j],names[j+1])>0)
{ strcpy(temp,names[j]);
strcpy(names[j], names[j+1]);
strcpy(names[j+1], temp);
/* Swapping of marks */
strcpy(temp,marks[j]);
strcpy(marks[j], marks[j+1]);
strcpy(marks[j+1], temp);

/* Swapping of ID’s */
strcpy(temp,id[j]);
strcpy(id[j], id[j+1]);
strcpy(id[j+1], temp);
}
printf("ALPHABETICAL LIST OF ID NAME & MARKS");
for(i=0;i<N;i++)
printf("%s %s %s ", id[i], names[i], marks[i]);
return 0;
}

BITS Pilani, Dubai Campus
int main()
{ char str[2][5] = {“EVEN”,”ODD”};
int j;
printf(“Enter The Number:”);
scanf(“%d”,&j);
printf(“ The number is %s”,s[j%2]);
return;
}

____________________________________________________________________________________________

Write a C program which will read a line of text and rewrite it in the alphabetical order.

//Program

#define ROW 20
#define COL 30
#include<string.h>
#include<stdio.h>
int main()
{
char text[80];
char Word[20],Strings[ROW][COL];
int i=0,j,k=0;
printf("Enter a line of text: ");
/* Reading terminated string */
scanf("%[^ ]s", text);

while(text[i]!= '')
{ j = 0;
while(1) /* Finding space terminated strings */
{ if(text[i]==' '|| text[i]=='')
break;
Word[j++] = text[i++];
}
word[j]='';
strcpy( Strings[k], Word);
k++;
if(text[i]!='')
i++;
}
for(k--; k>=0; k--)
printf("%s",Strings[k]);
return 0;
}

____________________________________________________________________________________________

C program to replace a particular word by another word in a given string. Both the words are provided by the user at run time.

// Program

#include<stdio.h>
#include<conio.h>
int stlen(char str[50])
{
int len = 0;
while(str[len]!=’)
len++;
len–;
return len;
}
void stcat(char str1[50], char str2[50])
{
int i = 0,len = 0;
while(str1[len]!=’)
len++;
while(str2[i]!=’)
{
str1[len] = str2[i];
i++;
len++;
}
str1[len] = ‘’;
}
void main()
{
char str1[50], str2[50], str3[50], temp[50];
int len1, len2, len3, i, j, match, k;
clrscr();
printf(“ ENTER A SENTENCE…: “);
gets(str1);
len1 = stlen(str1);
printf(“ ENTER A STRING WHICH YOU WANT TO DELETE…: “);
gets(str2);
len2 = stlen(str2);
printf(“ ENTER A NEW STRING WHICH YOU WANT TO INSERT …: “);
gets(str3);
len3 = stlen(str3);
for(i=0;i<=len1;i++)
{
match = 1;
for(j=0;j<=len2;j++)
if(str2[j]!=str1[i+j])
{
match = 0;
break;
}
if(match)
{
for(k=0,j=i+len2+1;j<=len1;j++,k++)
temp[k] = str1[j];
temp[k] = ‘’;
for(j=0;j<=len3;j++)
str1[i+j] = str3[j];
str1[i+j] = ‘’;
stcat(str1,temp);
len1 = len1 – len2 +len3;
i = i + j;
}
}
printf(“ OUTPUT IS…: “);
puts(str1);
getch();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote