C Program
1.First Way
#include <stdio.h>
#include <stdlib.h>
int main()
{
int sel,major;
printf("press\n1.if you are full time\n2.if you are part time\n");
scanf("%d",&sel);
printf("How many major do you have:");
scanf("%d",&major);
if(sel==1)
printf("is a good major");
else if(sel==2 && major<6)
printf("Thats nice");
else
printf("That is a lot for a part-time student");
}
2.Second Way
#include <stdio.h>
#include <stdlib.h>
int main()
{
int sel,major;
printf("press\n1.if you are full time\n2.if you are part time\n");
scanf("%d",&sel);
printf("How many major do you have:");
scanf("%d",&major);
if(sel==1)
{
printf("is a good major");
}
else
{
if(major<6)
printf("Thats nice");
else
printf("That is a lot for a part-time student");
}
}
3.Third Way
#include <stdio.h>
#include <stdlib.h>
int main()
{
int sel,major;
printf("press\n1.if you are full time\n2.if you are part time\n");
scanf("%d",&sel);
printf("How many major do you have:");
scanf("%d",&major);
switch(sel)
{
case 1: printf("is a good major");
break;
case 2: if(major<6)
{
printf("Thats nice");
}
else
{
printf("That is a lot for a part-time student");
}
break;
}
}
I remember this question it was my question during c Practical exam
ReplyDelete