Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- main()
- {
- int choose;
- char ans;
- printf("\n***************************************************");
- printf("\n* Student Name: Dinh Nguyen Anh Tuan *");
- printf("\n* Please select the number for appropriate tasks *");
- printf("\n* 1.Quit program *");
- printf("\n* 2.Question 2 *");
- printf("\n* 3.Question 3 *");
- printf("\n* 4.Question 4 *");
- printf("\n***************************************************");
- printf("\n\nSelect your number: ");
- scanf("%d",&choose);
- switch(choose)
- {
- case 1:
- exit(0);
- case 2:
- _flushall();
- question2();
- break;
- case 3:
- _flushall();
- question3();
- break;
- case 4:
- _flushall();
- question4();
- break;
- }
- }
- question2()
- {
- char num[100];
- int digits;
- int i;
- int dem;
- dem=0;
- printf("\n********Counting the digits of a number Program***********");
- printf("\nPlease enter a number: ");
- scanf("%s",&num);
- for(i=0;i<strlen(num);i++)
- {
- if(isdigit(num[i]) == 0) // isdigit = 0 nghia la num[i] ko phai chu so
- {
- printf("Invalid number");
- break;
- }
- dem++;
- }
- printf("\nThe number has %d digits",dem);
- }
- question3()
- {
- char str[100];
- int i;
- int dem;
- dem=0;
- printf("\nEnter a string of characters: ");
- gets(str);
- //So luong cua tu trong chuoi
- for(i=0;i<strlen(str);i++)
- {
- if(str[i] ==' ')
- {
- dem++;
- }
- }
- printf("\nThe string has %d words",dem+1);
- //Moi tu o 1 hang trong chuoi
- printf("\nThe string with each word on a different line: \n");
- for(i=0;i<strlen(str);i++)
- {
- if(str[i] ==' ')
- {
- printf("\n");
- }
- else
- {
- printf("%c",str[i]);
- }
- }
- //Dao nguoc chuoi va xuat ra
- printf("\nThe string in reversed order of characters: \n");
- for(i=strlen(str);i>=0;i--)
- {
- printf("%c",str[i]);
- }
- }
- question4()
- {
- struct detailStudent
- {
- char name[50];
- float csharp_mark;
- float java_mark;
- float english_mark;
- }Student[100];
- int n;
- int i;
- float total;
- float average;
- printf("\nEnter a number of students: ");
- scanf("%d",&n);
- //n tu 1-100
- while(n<1 || n>100)
- {
- printf("\nThe user must enter the appropriate number to continue");
- printf("\nEnter a number of students: ");_flushall();
- scanf("%d",&n);_flushall();
- }
- //Nhap thong tin hoc sinh
- printf("\nEnter the datas for each student: ");
- for(i=0;i<n;i++)
- {
- printf("\nEnter the detail of student %d",i+1);
- printf("\nName: ");_flushall();
- gets(Student[i].name);
- printf("\nC Sharp Mark: ");_flushall();
- scanf("%f",&Student[i].csharp_mark);
- printf("\nJava Mark: ");_flushall();
- scanf("%f",&Student[i].java_mark);
- printf("\nEnglish Mark: ");_flushall();
- scanf("%f",&Student[i].english_mark);
- }
- //Xuat thong tin hoc sinh
- for(i=0;i<n;i++)
- {
- printf("\n---------Detail of student %d-----------",i+1);
- printf("\nName: %s",Student[i].name);
- printf("\nC Sharp Mark: %.2f",Student[i].csharp_mark);
- printf("\nJava Mark: %.2f",Student[i].java_mark);
- printf("\nEnglish Mark: %.2f",Student[i].english_mark);
- //Tong diem
- printf("\nTotal Mark: %.2f",Student[i].csharp_mark+Student[i].java_mark+Student[i].english_mark);
- //Diem trung binh
- printf("\nAverage Mark: %.2f",(Student[i].csharp_mark+Student[i].java_mark+Student[i].english_mark)/4);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement