Write a C expression Assume that credits is an int variable whose value is 0 or
ID: 2317434 • Letter: W
Question
Write a C expression
Assume that credits is an int variable whose value is 0 or positive. Write an expression whose value is "freshman" or "sophomore" or "junior" or "senior" based on the value of credits. In particular: if the value of credits is less than 30 the expression 's value is "freshman"; 30-59 would be a "sophomore", 60-89 would be "junior" and 90 or more would be a "senior".
Write a loop in C language
Given that two int variables , total and amount, have been declared , write a loop that reads non-negative values into amount and adds them into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0.
Write a C statement
Assume that the variables gpa, deansList and studentName, have been declared and initialized . Write a statement that both adds 1 to deansList and prints studentName to standard out if gpa exceeds 3.5.
Explanation / Answer
ANS 1)
#include<stdio.h>
#include<string.h>
int main()
{
int credit = 0;
string expression;
scanf("%d",&credit);
if(credit<30)
expression="freshman";
else if(credit>=30 && credit<=59)
expression="sophomore";
else if(credit>=60 && credit<=89)
expression="junior";
else
expression="senior";
return 0;
}
ANS 2)
#include<stdio.h>
int main()
{
int total = 0;
int amount;
scanf("%d",&amount);
while(amount)
{
total = total+amount;
scanf("%d",&amount);
}
return 0;
}
ANS 3)
int a=1;
gpa>3.5 ? (a=1): (a=0);
if(a)
{
deansList++;
printf("%s",studentName);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.