Complete the following problems. Assignment must be printed and stapled. Put nam
ID: 2079369 • Letter: C
Question
Complete the following problems. Assignment must be printed and stapled. Put name and course number at the top. For code, remember to include an information header at the top and inecomments Assignment wilbe graded on comments/explanations in addition to working code. 1) Show the output that would be produced for the following code fragments.Assumeii.and kare declared as integer type variables. ICode and screenshots are not required for this problem. a) i 5; j la printf "i" d j" d", i, j) printf i, j, k): i 11/4; 1114 11.0/4 printf ("i sd j k ad", i, j, k): printf printf printf printf ("i sd n", i)J 2) Write a program that asks the user to enter a positivetwo digt integer and then displaysthenumber with the digitsin reverse order. Submit your code and a screenshot of the code execution. Enter a 2-digit integer: 24 r in reverse 42 write a program that asks the user to enter three integers (separated by spaces, then determines and prints the largest number and smallest number. Submit your code and a screenshot of the code execution. Enter three integers Largest 42 Smallest 4) Write a program that asks the user to enter two dates and then indicates which date is earlier on the calendar Submit your code and a screenshot of the code execution. 8717716 Enter the first date Imam/dd/yy Enter the second date (mm/dd/yy) 3VI9/16 3/19/16 is earlier than 4/17/16 EE 107- Spring 2017Explanation / Answer
1.a. i=35 j=6
1.b i=3 j=2 k=1
1.c i=2 j=3 k=2
1.d
i=1
i=2
i=2
i=3
2. Code to reverse two digit number
#include<stdio.h>
int main()
{
int n=0;
int q=0;
int r=0;
int reverse;
printf("Enter the 2-digit number");
scanf("%d",&n);
q=n/10; //Find quotient
r=n%10; //Find remainder
reverse=r*10+t; //Calculate reverse
printf("The reversed number is=%d",reverse);
}
Example:
Enter the 2-digit number45
The reversed number is=54
Enter the 2-digit number33
The reversed number is=33
3.
#include<stdio.h>
int main()
{
int n1=0;
int n2=0;
int n3=0;
int l=0;
int s=0;
printf("Enter the 3 numbers separated by spaces");
scanf("%d %d %d",&n1, &n2, &n3);
//Calculate if n1 is largest
if ((n1>n2) && (n1>n3))
{
l=n1;
}
//Calculate if n1 is smallest
else if((n1<n2) && (n1<n3))
{
s=n1;
}
//Calculate if n2 is largest
if ((n2>n1) && (n2>n3))
{
l=n2;
}
//Calculate if n2 is smallest
else if((n2<n1) && (n2<n3))
{
s=n2;
}
//Calculate if n3 is largest
if ((n3>n1) && (n3>n2))
{
l=n3;
}
//Calculate if n3 is smallest
else if((n3<n1) && (n3<n2))
{
s=n3;
}
printf("Largest:%d ",l);
printf("Smallest:%d ",s);
}
Example:
Enter the 3 numbers separated by spaces15 7 42
Largest:42
Smallest:7
Enter the 3 numbers separated by spaces99 9 0
Largest:99
Smallest:0
4.
#include<stdio.h>
int main()
{
int m1, m2, d1, d2, y1, y2;
printf("Enter the first date (mm/dd/yyyy):");
scanf("%d/%d/%d",&m1, &d1, &y1);
printf("Enter the second date (mm/dd/yyyy):");
scanf("%d/%d/%d",&m2, &d2, &y2);
if (y1<y2)
{
printf("%d/%d/%d is earlier than %d/%d/%d ", m1, d1, y1, m2, d2, y2 );
}
else if (y1==y2)
{
if(m1<m2)
{
printf("%d/%d/%d is earlier than %d/%d/%d ", m1, d1, y1, m2, d2, y2 );
}
else if(m1==m2)
{
if (d1<d2)
{
printf("%d/%d/%d is earlier than %d/%d/%d ", m1, d1, y1, m2, d2, y2 );
}
else if(d1>d2)
{
printf("%d/%d/%d is earlier than %d/%d/%d ", m2, d2, y2, m1, d1, y1 );
}
else
{
printf("The dates are the same");
}
}
else
{
printf("%d/%d/%d is earlier than %d/%d/%d ", m2, d2, y2, m1, d1, y1 );
}
}
else
{
printf("%d/%d/%d is earlier than %d/%d/%d ", m2, d2, y2, m1, d1, y1 );
}
}
Example:
Enter the first date (mm/dd/yyyy):2/3/1190
Enter the second date (mm/dd/yyyy):5/4/2016
2/3/1190 is earlier than 5/4/2016
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.