KhLM2ZqeS06HpWmXQWXLAQ Week 3 Practice Lab Solutions
KhLM2ZqeS06HpWmXQWXLAQ Week 3 Practice Lab Solutions
KhLM2ZqeS06HpWmXQWXLAQ Week 3 Practice Lab Solutions
#include<stdio.h>
int main(){
int a, b, c;
printf("Enter three integers a, b, and c - ");
scanf(" %d %d %d",&a,&b,&c);
if(a==b){
if(a==c){
printf("True\n");
}
else{
printf("False\n");
}
}
else{
printf("False\n");
}
/*
//alternate soln
if(a==b && a==c){
printf("True\n");
}
else{
printf("False\n");
}
*/
return 0;
}
PracticeLab1_Question1(b)
#include<stdio.h>
int main(){
int a, b, c;
printf("Enter three integers a, b, and c - ");
scanf(" %d %d %d",&a,&b,&c);
/*
//alternate soln
if(a==b)
printf("False\n");
if(a==c)
printf("False\n");
if(b==c)
printf("False\n");
else
printf("True\n");
*/
return 0;
}
PracticeLab1_Question2
#include<stdio.h>
int main(){
int marks;
printf("Please enter your marks: ");
scanf(" %d", &marks);
if(marks >=90)
printf("Your grade is Extraordinary");
}
Practice Lab 2_Question 1-(1)part
#include<stdio.h>
int main()
{
/*
Current wrong output:
1
21
321
4321
54321
int N;
printf("Please Enter a number greater than 0: ");
scanf(" %d", &N);
while( N<=0)
{
printf("Please Enter a number greater than 0: ");
scanf(" %d", &N);
}
printf("Ok, number entered is greater than 0");
printf("Please Enter a number greater than 20 AND less than 100: ");
scanf(" %d", &N);
while( N<=20 || N>=100)
{
printf("Please Enter a number greater than 20 AND less than 100:
");
scanf(" %d", &N);
}
printf("Ok, number entered is greater than 20 AND less than 100\n");
return 0;
}
Practice Lab 2_Question 3
#include<stdio.h>
int main(){
j = i;
// printf("%llu ", j); //uncomment if you want to see the series
// loop until the current number becomes 1
while(j!=1)
{
if(j%2 == 0){
j/=2;
}
else{
j = 3*j +1;
}
return 0;
}
PracticeLab 2_Question_4 (a)
#include<stdio.h>
int main(){
int month_number; // 1 to 12
switch(month_number){
case 1: printf("January"); break;
case 2: printf("February"); break;
case 3: printf("March"); break;
case 4: printf("April"); break;
case 5: printf("May"); break;
case 6: printf("June"); break;
case 7: printf("July"); break;
case 8: printf("August"); break;
case 9: printf("September"); break;
case 10: printf("October"); break;
case 11: printf("November"); break;
case 12: printf("December"); break;
}
return 0;
}
PracticeLab 2_Question_4 (b)
#include<stdio.h>
/*
sample inputs and outputs
input: 9
output: September
October
November
December
*/
int main(){
int month_number; // 1 to 12
switch(month_number){
case 1: printf("January\n");
case 2: printf("February\n");
case 3: printf("March\n");
case 4: printf("April\n");
case 5: printf("May\n");
case 6: printf("June\n");
case 7: printf("July\n");
case 8: printf("August\n");
case 9: printf("September\n");
case 10: printf("October\n");
case 11: printf("November\n");
case 12: printf("December\n");
}
return 0;
}
Practice Lab 3_Question 1 (a)
#include<stdio.h>
int main(){
int N;
printf("Enter the value of N - ");
scanf(" %d", &N);
int sum = 0;
return 0;
}
int N;
printf("Enter the value of N - ");
scanf(" %d", &N);
int sum = 0;
return 0;
}
Practice Lab 3_Question 2
The program prompt asks the user to enter a positive number (although it doesn’t throw an error
if zero or a negative number is entered). Then if the number is greater than or equal to 79, it
simply exits. If number entered is less than 79 (even a negative number), the program prints all
the multiples of 5 in the range (start,79). ‘Start’ will be printed only if it is a multiple of 5
otherwise the next immediate multiple of 5 coming after 5 will be printed, similarly at the end as
last number 75 is printed which is the last multiple of 5 before 79.
return 0;
}
return 0;
}
#include<stdio.h>
int main(){
printf("%llu^%llu = %llu\n",a,b,ans);
return 0;
}