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
#include<stdio.h>
Void main()
{
int a,b,c;
printf("Enter the marks of student 1 , student 2 and student 3: \n");
scanf("%d %d %d",&a,&b,&c);
if ((a>b)&&(a>c))
printf("student 1 has highest marks\n");
else if (b>c)
printf("student 2 has highest marks\n");
else
printf("student 3 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");
}
Output:
Enter the marks of student 1,student 2 and student 3:
100 98 97
Student 1 has highest marks
#include<stdio.h>
int main()
{
int a, b, c;
printf("enter the marks of student 1, student 2, and student 3:\n");
scanf("%d,%d,%d",&a,&b,&c);
if((a>b)&&(a>c))
printf("student 1 has highest marks\n");
else if (b>c)
printf("student 2 has highest marks\n");
else
printf("student 3 has highest marks\n");
if ((a==b)&&(b==c)&&(c==a))
printf("three students have equal marks\n");
else if ((a==b)||(b==c)||(a==c))
printf("two students have equal marks\n");
else
printf("no students have equal marks\n");
return 0;
}
output:
enter the marks of student 1 student 2 and student 3:
30,60,79
student 3 has highest marks
#include<stdio.h>
int main()
{
int a, b, c;
printf("enter the marks of student 1, student 2, and student 3:\n");
scanf("%d,%d,%d",&a,&b,&c);
if((a>b)&&(a>c))
printf("student 1 has highest marks\n");
else if (b>c)
printf("student 2 has highest marks\n");
else
printf("student 3 has highest marks\n");
if ((a==b)&&(b==c)&&(c==a))
printf("three students have equal marks\n");
else if ((a==b)||(b==c)||(a==c))
printf("two students have equal marks\n");
else
printf("no students have equal marks\n");
return 0;
}
output:
enter the marks of student 1 student 2 and student 3:
30,60,79
student 3 has highest marks
#include<stdio.h>
Void main()
{
int a,b,c;
printf("Enter the marks of student 1 , student 2 and student 3: \n");
scanf("%d %d %d",&a,&b,&c);
if ((a>b)&&(a>c))
printf("student 1 has highest marks\n");
else if (b>c)
printf("student 2 has highest marks\n");
else
printf("student 3 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");
}
Output:
Enter the marks of student 1,student 2 and student 3:
100 98 97
Student 1 has highest marks
#include<stdio.h>
int main()
{
int a, b, c;
printf("enter the marks of student 1, student 2, and student 3:\n");
scanf("%d,%d,%d",&a,&b,&c);
if((a>b)&&(a>c))
printf("student 1 has highest marks\n");
else if (b>c)
printf("student 2 has highest marks\n");
else
printf("student 3 has highest marks\n");
if ((a==b)&&(b==c)&&(c==a))
printf("three students have equal marks\n");
else if ((a==b)||(b==c)||(a==c))
printf("two students have equal marks\n");
else
printf("no students have equal marks\n");
return 0;
}
output:
enter the marks of student 1 student 2 and student 3:
30,60,79
student 3 has highest marks
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("enter the marks of the students:");
scanf("%d%d%d",&a,&b,&c);
if(a>b&a>c)
printf("a got highest marks of %d",a);
else if(b>c&b>a)
printf("b got highest marks of %d",b);
else
printf("c got highest marks of %d",c);
if(a==b&a==c)
printf("a,b,c got same marks");
else if(a==b)
printf("a and b got same marks");
else if(a==c)
printf("a and c got same marks");
else
printf("b and c got same marks");
getch();
}
output
enter the marks of the students:100 98 97
a got highest marks of 100
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("enter the marks of the students:");
scanf("%d%d%d",&a,&b,&c);
if(a>b&a>c)
printf("a got highest marks of %d",a);
else if(b>c&b>a)
printf("b got highest marks of %d",b);
else
printf("c got highest marks of %d",c);
if(a==b&a==c)
printf("a,b,c got same marks");
else if(a==b)
printf("a and b got same marks");
else if(a==c)
printf("a and c got same marks");
else
printf("b and c got same marks");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("enter the marks of the students:");
scanf("%d%d%d",&a,&b,&c);
if(a>b&a>c)
printf("a got highest marks of %d",a);
else if(b>c&b>a)
printf("b got highest marks of %d",b);
else
printf("c got highest marks of %d",c);
if(a==b&a==c)
printf("a,b,c got same marks");
else if(a==b)
printf("a and b got same marks");
else if(a==c)
printf("a and c got same marks");
else
printf("b and c got same marks");
getch();
}
#include<stdio.h>
#include<conio.h>
Void main()
{
int a,b,c;
printf("Enter the marks of three students: \n");
scanf("%d %d %d",&a,&b,&c);
if ((a>b)&&(a>c))
printf("a got highest marks of %d",a);
else if (b>c)
printf("b got highest marks of %d",b);
else
printf("c got highest marks of %d",c);
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");
getch();
}
Output:
enter the marks of three students:
95 98 99
c got highest marks of 99
Login to add comment