Write a C program that takes input as name of the end user. Use for loop and print the name entered in the reverse order. 5. Write a program in C that accepts the Id, Name, and Grade of 5 students using any loop. Write a switch case, which should display the description of the grade along with the Id and Name. Description of grade given below in Table 1 Grade Description E Excellent V Very Good G Good A Average F Fail
#include<stdio.h>
#include<cstring>
void reverseC(char* word)
{
int i=0;
int j= strlen(word)-1;
while(i<=j)
{
char temp=word[i];
word[i]=word[j];
word[j]=temp;
i++;
j--;
}
}
struct Student
{
int id;
char name[20];
float grade;
};
int main()
{
printf("First half of program:\n");
char name[20];
printf("Please, enter your name: ");
scanf("%s",name);
printf("Reverse name is: ");
reverseC(name);
printf("%s",name);
printf("\nSecond half of program:\n");
Student studs[5];
int i=1;
for(Student* st=&studs[0];st!=&studs[5];st++,i++)
{
printf("Please, enter an id of student %d: ",i);
scanf("%d",&st->id);
printf("Please, enter an name of student %d: ",i);
scanf("%s",st->name);
printf("Please, enter a grade of student %d: ",i);
scanf("%f",&st->grade);
}
printf("Display students:\n");
i=1;
for(Student* st=&studs[i];st!=&studs[5];++st,++i)
{
printf("Info about student %d:\n%d\n%s\n%f\n",i,st->id,st->name,st->grade);
}
}
Comments
Leave a comment