Relational Operators assignment
Title
Question
Write a program that takes the marks of three students as input.
Compare the marks to see which student has scored the highest.
Check also if two or more students have scored equal marks.
C-and-Cpp Relational-Operators 08-09 min 30-40 sec
Answers:
A meaningful program can be written as follows:
#include <stdio.h>
int main(){
int m1,m2,m3;
printf("Enter the marks of student 1\n");
scanf("%d %d %d",&m1,&m2,&m3);
if(m1 > m2 & m1 > m3)
printf("student 1 got the highest marks of %d \n",m1);
else if (m2 > m1 & m2 > m3)
printf("student 2 got the highest marks of %d \n",m2);
else if (m3 > m1 & m3 > m2)
printf("student 3 got the highest marks of %d \n",m3);
if(m1 == m2 & m1== m3)
printf("same marks has been received by the students\n");
else if (m1==m2)
printf("same marks has been received by the students 1 and 2\n");
else if (m1==m3)
printf("same marks has been received by the students 1 and 3\n");
else if (m2==m3)
printf("same marks has been received by the students 2 and 3\n");
return 0;
}
<font size="4">Program in c to compare the marks of the students;</font>
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter the marks of student1 , student2 and student3\n");
scanf("%d %d %d",&a,&b,&c);
if ((a>b)&&(a>c))
printf("student1 has highest marks\n");
else if (b>c)
printf("student2 has highest marks\n");
else
printf("student3 has highest marks\n");
if ((a==b)&&(b==c)&&(a==c))
printf("Three students have equal marks\n");
else if ((a==b)||(a==c)||(b==c))
printf("Two students have equal marks\n");
else
printf("No students have equal marks\n");
return 0;
}
Output:
Enter the marks of student1 , student2 and student3
35
44
35
student2 has highest marks
Two students have equal marks
<font size="4">Program in c to compare the marks of the students;</font>
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"Enter the marks of student1 , student2 and student3"<<"\n";
cin>>a>>b>>c;
if ((a>b)&&(a>c))
cout<<"student1 has highest marks"<<"\n";
else if (b>c)
cout<<"student2 has highest marks"<<"\n";
else
cout<<"student3 has highest marks"<<"\n";
if ((a==b)&&(b==c)&&(a==c))
cout<<"Three students have equal marks"<<"\n";
else if ((a==b)||(a==c)||(b==c))
cout<<"Two students have equal marks"<<"\n";
else
cout<<"No students have equal marks"<<"\n";
return 0;
}
Output:
Enter the marks of student1 , student2 and student3
35
44
35
student2 has highest marks
Two students have equal marks
Login to add comment