ST.
Xavier’S College
MAITIGHAR, KATHMANDU, NEPAL
Phone: 01-5321365, 01-5344636
Email: ktm@sxc.edu.np
ASSIGNMENT NUMBER: 7
“LAB REPORT ON C PROGRAMS”
Submitted By Submitted To Signature
Name: Aarav Thakur Mr. Jaya Sundar
Roll No: 806 Shilpakar
Class: 11 Department of
Section: H Computer Science (+2)
Submission Date: 25th November, 2024
Table of Contents
C Programs ...................................................................................................................................... 3
C program to input a number and print if it is positive, negative or zero. ................................... 3
C program to print to input a number and print whether it is even or odd................................... 3
C program to input the day of a week and print if it’s a holiday or working day. ....................... 4
C program to input any number and check whether the given no. is divisible by 3 and 7 or not.4
C program to input three numbers and display the smallest one among them............................. 4
C program to input the angles of a triangle and decide it is scalene, isosceles or equilateral. ..... 5
C program to input the sides of triangle and decide if it is right angled, obtuse or acute. ........... 5
C program to input any three numbers and display the middle number. ..................................... 6
C program to calculate the area of rectangle, circle or triangle using if else ladder. ................... 6
C program to test whether a candidate is eligible a for job or not. .............................................. 7
Conclusion ....................................................................................................................................... 7
C Programs
C program to input a number and print if it is positive, negative or zero.
#include <stdio.h>
int main()
{
int num;
printf("Enter any integer number=");
scanf("%d", &num);
if(num>0)
{
printf("%d is a positive number.", num);
}
else if (num<0)
{
printf("%d is a negative number.", num);
}
else
{
printf("The number entered is zero.");
}
return 0;
}
C program to print to input a number and print whether it is even or
odd
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0)
printf("The number is Even.\n");
else
printf("The number is Odd.\n");
return 0;
}
C program to input the day of a week and print if it’s a holiday or
working day.
#include <stdio.h>
#include <string.h>
int main() {
char day[9];
printf("Enter the day of the week: ");
scanf("%s", day);
strupr(day);
if (strcmp(day, "SATURDAY") == 0 )
printf("Holiday.\n");
else
printf("Working day.\n");
return 0;
}
C program to input any number and check whether the given no. is
divisible by 3 and 7 or not.
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 3 == 0 && num % 7 == 0)
printf("The number is divisible by 3 and 7.\n");
else
printf("The number is not divisible by 3 and 7.\n");
return 0;
}
C program to input three numbers and display the smallest one among
them.
#include <stdio.h>
int main() {
int a, b, c;
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
if (a < b && a < c)
printf("Smallest number is: %d\n", a);
else if (b < c)
printf("Smallest number is: %d\n", b);
else
printf("Smallest number is: %d\n", c);
return 0;
}
C program to input the angles of a triangle and decide it is scalene,
isosceles or equilateral.
#include <stdio.h>
int main() {
int a1, a2, a3;
printf("Enter three angles of a triangle: ");
scanf("%d %d %d", &a1, &a2, &a3);
if (a1 + a2 + a3 != 180) {
printf("It is not a valid triangle.\n");
} else if (a1 == a2 && a2 == a3) {
printf("It is an equilateral Triangle.\n");
} else if (a1 == a2 || a2 == a3 || a1 == a3) {
printf("It is an isosceles Triangle.\n");
} else {
printf("It is a scalene Triangle.\n");
}
return 0;
}
C program to input the sides of triangle and decide if it is right angled,
obtuse or acute.
#include <stdio.h>
int main() {
int a, b, c;
printf("Enter integer values of 3 sides of a triangle: ");
scanf("%d %d %d", &a, &b, &c);
if (a<=0 || b<=0 || c<=0)
{
printf("It is not a valid triangle.\n");
}
else if (a + b <= c || b + c <= a || c + a <= b) {
printf("Not a valid triangle.\n");
} else if (a * a + b * b == c * c || b * b + c * c == a * a || c * c + a * a == b * b) {
printf("Right-angled Triangle.\n");
} else if (a * a + b * b < c * c || b * b + c * c < a * a || c * c + a * a < b * b) {
printf("Obtuse Triangle.\n");
} else {
printf("Acute Triangle.\n");
}
return 0;
}
C program to input any three numbers and display the middle number.
#include <stdio.h>
int main() {
int a, b, c;
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
if ((a > b && a < c) || (a > c && a < b))
printf("Middle number is: %d\n", a);
else if ((b > a && b < c) || (b > c && b < a))
printf("Middle number is: %d\n", b);
else
printf("Middle number is: %d\n", c);
return 0;
}
C program to calculate the area of rectangle, circle or triangle using if
else ladder.
#include <stdio.h>
int main() {
int choice;
printf("Select a shape to calculate area:\n");
printf("1. Rectangle\n2. Circle\n3. Triangle\n");
scanf("%d", &choice);
if (choice == 1) {
float l,b;
printf("Enter length and breadth of the rectangle:");
scanf("%f %f", &l, &b);
printf("Area of Rectangle= %.2f\n", l*b);
} else if (choice == 2) {
float r;
printf("Enter radius of the circle: ");
scanf("%f", &r);
printf("Area of Circle: %.2f\n", 3.14*r*r);
} else if (choice == 3) {
float b, h;
printf("Enter base and height of the triangle: ");
scanf("%f %f", &b, &h);
printf("Area of Triangle: %.2f\n", 0.5*b*h);
} else {
printf("Select a valid choice!\n");
}
return 0;
}
C program to test whether a candidate is eligible a for job or not.
#include <stdio.h>
#include <string.h>
int main() {
char deg[20];
int exp;
printf("Enter your degree (bachelor/intermediate):");
scanf("%s", °);
printf("Enter your years of experience: ");
scanf("%d", &exp);
strupr(deg);
if (strcmp(deg, "BACHELOR") == 0) {
printf("You are eligible for the job.\n");
} else if (strcmp(deg, "INTERMEDIATE") == 0 && exp>= 5) {
printf("You are eligible for the job.\n");
} else {
printf("You are not eligible for the job.\n");
}
return 0;
}
Conclusion
Through this lab report, I learned a lot about programming in C, including how to use string
functions from the <string.h> library and to uppercase characters using strupr() function. Writing
these programs helped me understand important concepts like handling user input, using
conditional statements effectively, and applying logical thinking to solve problems. Overall, it
was a great hands-on experience that strengthened my coding skills and made me more confident
in writing C programs.