Problem description:
Consider the room numbers of our campus - 423, 432, 441, 234, 534, 132. Here first digit represents campus number, second digit represents floor number and the third number represents room number in that floor. Write a program that will take a three digit number (like 423) and output the Campus, Floor, and Room Number according to the input.
INPUT: 423
OUTPUT: Campus 4, Floor 2, Room 3
Code:
#include <stdio.h>
int main()
{
int n, campus, floor, room;
printf("Enter a room number: ");
scanf("%d", &n);
room = n%10;
floor = ((n - room)%100)/10;
campus = n/100;
printf("Campus %d, Floor %d, Room %d", campus, floor, room);
return 0;
}
Consider the room numbers of our campus - 423, 432, 441, 234, 534, 132. Here first digit represents campus number, second digit represents floor number and the third number represents room number in that floor. Write a program that will take a three digit number (like 423) and output the Campus, Floor, and Room Number according to the input.
INPUT: 423
OUTPUT: Campus 4, Floor 2, Room 3
Code:
#include <stdio.h>
int main()
{
int n, campus, floor, room;
printf("Enter a room number: ");
scanf("%d", &n);
room = n%10;
floor = ((n - room)%100)/10;
campus = n/100;
printf("Campus %d, Floor %d, Room %d", campus, floor, room);
return 0;
}
Comments
Post a Comment