






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A lab guide for c programming course at international university. It covers three exercises: determining if a year is a leap year, identifying triangle types based on sides, and calculating circle properties. The exercises involve writing c programs using input/output statements, arithmetic, relational, and logical operators, and problem-solving techniques.
Typology: Lab Reports
1 / 11
This page cannot be seen from the preview
Don't miss anything!
Full name + Student ID: ………ITITIU22019 Bùi Gia B oả ITCSIU22261 Võ Hoàng Hi pệ Class: ………………………………………………………………………………………………………………………………. Group: ……………………………………………………………………………………………………………………………. Date: ………………………………………………………………………………………………………………………………
Students are required to review the theory of the topics before the lab time.
Exercise 1 Write a C program to determines whether an input number is even or odd. Output: Input an integer: 15 15 is an odd integer #include <stdio.h> int main() { int a; int b; scanf("%d",&a) ; b= a%2; if(b==0) printf ("%d is an the even interger \n",a);
printf("%d is not a leap year.\n", a); // Print a message indicating that ‘a’is not a leap year. else if ((a % 4) == 0) // Check if ‘a’is divisible by 4 with no remainder. printf("%d is a leap year.\n", a); // Print a message indicating that ‘a’is a leap year. else printf("%d is not a leap year \n", a); // Print a message indicating that ‘a’is not a leap year. } Exercise 3 Write a C program to identify whether a triangle is Equilateral, Isosceles or Scalene based on the given sides. For Example: Output: Input three sides of triangle: 30 30 50 This is an isosceles triangle. # include <stdio.h> int main() { int a,b,c; printf ("Input three sides of triangle:"); scanf ("%d",&a); scanf ("%d",&b); scanf ("%d",&c); if (a==b==c) printf("This is an Equilateral triangle\n");// the triangle is Equilateral when a=b=c. else if (a==b) printf("This is an Isosceles triangle\n");// the triangle is Isosceles when a=b. else if (a==c) printf("This is an Isosceles triangle\n");// the triangle is Isosceles when a=c.
else if (b==c) printf("This is an Isosceles triangle\n");// the triangle is Isosceles when b=c. if ((a^2)==(b^2)+(c^2)) printf("This is an Scalene triangle\n");// the triangle is Scalen. else if ((b^2)==(a^2)+(c^2)) printf("This is an Scalene triangle\n"); else if ((c^2)==(b^2)+(a^2)) printf("This is an Scalene triangle\n"); return 0; } Exercise 4 Write a C program to input radius of a circle from user and find diameter, circumference, and area of the circle. For example: Output: Enter the radius of a circle: 3 Diameter of circle = 6.00 units Circumference of circle = 18.84 units Area of circle = 28.26 sq. units #include <stdio.h> int main() { float radius, diameter, circumference, area; //Input radius of circle from user printf("Enter radius of circle: "); scanf("%f", &radius); // Calculate diameter, circumference and area diameter = 2 * radius; circumference = 2 * 3.14 * radius; area = 3.14 * (radius * radius); //Print all results
printf ("Enter the Values of b :"); scanf ("%f",&b); printf ("Enter the Values of c :"); scanf ("%f",&c); deta=(bb)-4(ac); d=(-b)/(2a);//this is a Values of Only root e=(-b+(sqrt(deta)))/(2a); f=(-b-(sqrt(deta)))/(2a); if (deta<0) printf ("The equation has no root");//Consider the conditions of the equation. else if (deta==0) printf("%fThe equation has only root:",d); else if(deta>0) { printf ("The roots of equation are:\n"); printf ("First root:%f \n", e); printf ("Second root:%f \n", f); } return 0; } Exercise 6 Write a C program that calculate the total payment of Taxi service, in which:
#include <stdio.h> int main() { int cost,distance; printf ("Enter total distance in km:"); scanf ("%d",&distance);//input distance. // Calculate total cost. if (distance==0) cost=0;// when we do not use taxi. if (distance<=30) cost= 5+ 3(distance-1);//when the distane < 30 else cost = 5+(293)+2*(distance-30);// when the distane > printf ("\n The total cost that a passenger has to pay: %d",cost ); return 0; } Exercise 7 Write a C program to read student’s name, student’s ID and marks of three subjects (Literature, Math and English) and calculate the total, average and division. Division is defined as follows: Average ≥ 60: A 48 ≤ Average ¿60: B 36 ≤ Average ¿48: Pass Average ¿36: Fail For Example Output: Input the Name of the Student: Kien Input the No of the student: 10 Input the marks of Literature, Math and English: 50 80 70
per = total / 3.0; // Calculate percentage. if (per >= 60) // Check if percentage is greater than or equal to 60. strcpy(div, "First"); // Assign division as "First" if condition is true. else if (per < 60 && per >= 48) // Check if percentage is between 48 and 60. strcpy(div, "Second"); // Assign division as "Second" if condition is true. else if (per < 48 && per >= 36) // Check if percentage is between 36 and 48. strcpy(div, "Pass"); // Assign division as "Pass" if condition is true. else // If none of the above conditions are met. strcpy(div, "Fail"); // Assign division as "Fail". printf("\nRoll No : %d\nName of Student : %s\n", rl, nm); // Print roll number and name. printf("Marks in Physics : %d\nMarks in Chemistry : %d\nMarks in Computer Application : %d\n", phy, che, ca); // Print marks in each subject. printf("Total Marks = %d\nPercentage = %5.2f\nDivision = %s\n", total, per, div); // Print total marks, percentage, and division. } THE END
Useful Operators