Labsheet 5

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Qn 1

#include <stdio.h>

int main(){

int n;

printf("Please enter an input between 1-7 : ");

scanf("%d", &n);

switch(n){

case 1 : printf("Monday");

break;

case 2 : printf("Tueday");

break;

case 3 : printf("Wednesday");

break;

case 4 : printf("Thursday");

break;

case 5 : printf("Friday");

break;

case 6 : printf("Saturday");

break;

case 7 :

printf("Sunday");

break;

default:

return 0;

}
Qn 2

#include <stdio.h>

int main(){

int age;

printf("Please enter the age of the user: ");

scanf("%d", &age);

age>=18 ? printf("Yes, you can vote."):

printf("No, you can not vote.");

return 0;

}
Qn 3

#include <stdio.h>

int main(){

int a,b,c,d; scanf("%d %d %d %d", &a, &b, &c, &d);

//largest no in a

//second largest in b

if(b>a){

a = a+b;

b = a-b;

a = a-b;

if(c>a){

a = a+c;

c = a-c;

a = a-c;

if(d>a){

a = a+d;

d = a-d;

a = a-d;

if(c>b){b = b+c; c = b-c; b = b-c;

if(d>b){

b = b+d; d = b-d; b = b-d;

printf("The sum of %d and %d is : %d", a,b,a+b);

return 0;

}
Qn 4

#include <stdio.h>

int main(){

int n;

scanf("%d", &n);

int i=1;

while(i<=n){

printf("%d\n", i);

i++;

printf("Bye\n");

return 0;

}
Qn 6

#include <stdio.h>

int main(){

int n;

scanf("%d", &n);

for(int i=1; i<=n; i++){

//spaces

for(int j=1; j<=i-1; j++){

printf(" ");

//first row stars

if(i==1){

for(int k=1; k<=2*n-1; k++){

printf("*");

//code for middle rows

if(i>1 && i<n){

//star

printf("*");

//spaces

for(int k=0; k<=(2*n -1)-2*i-1; k++){

printf(" ");
}

//star

printf("*");

//last row single star

if(i==n){

printf("*");

printf("\n");

return 0;

You might also like