![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Golang Program to read the marks of subjects and display the Grade
Let's enter the marks: 89 56 90 67 99
Sum of the marks is: 89+56+90+67+99 => 401
Avg. = 401/5 = 80.1
The steps are as follows:
- Define variables for 5 subjects.
- Enter marks for 5 subjects.
- Find average of the marks to find grade.
- Use if else block to print grade.
Example
package main import "fmt" func main(){ var sub1, sub2, sub3, sub4, sub5 int fmt.Println("Enter marks of the five subjects:") fmt.Scanf("%d", &sub1) fmt.Scanf("%d", &sub2) fmt.Scanf("%d", &sub3) fmt.Scanf("%d", &sub4) fmt.Scanf("%d", &sub5) avg:=(sub1+sub2+sub3+sub4+sub5)/5 if avg>=90{ print("Grade: A") }else if avg>=80 && avg<90{ print("Grade: B") }else if avg>=70 && avg<80{ print("Grade: C") }else if avg>=60 && avg<70{ print("Grade: D") } else{ print("Grade: F") } }
Output
Enter marks of the five subjects: 89 56 90 67 99 Grade: B
Advertisements