×
The future belongs to those who believe in the beauty of their dreams.
--Your friends at LectureNotes
Close

Programming in C

by Shubham ShettiShubham Shetti
Type: NoteInstitute: RCUB university Offline Downloads: 1Views: 125Uploaded: 4 months ago

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

Shubham Shetti
Shubham Shetti
C PROGRAMS -----------------------------------------------------------------------------------------------------------1./* Write a C program to find the area of a triangle, given three sides*/ #include <stdio.h> #include <conio.h> #include <math.h> void main() { int s, a, b, c, area; clrscr(); printf("Enter the values of a,b and c\n"); scanf ("%d %d %d", &a, &b, &c); /* compute s*/ s = (a + b + c) / 2; area = sqrt ( s * (s-a) * (s-b) * (s-c)); printf ("Area of a triangale = %d\n", area); } /*----------------------------Output Enter the values of a,b and c 3 4 5 Area of a triangale = 6 ------------------------------*/ 2./* Write a C program to find the area of a circl, given the adius*/ #include <stdio.h> #include <conio.h> #include <math.h> #define PI 3.142 void main() { float radius, area; clrscr(); printf("Enter the radius of a circle\n"); -----------------------------------------------------------------------------------------------------------1
C PROGRAMS -----------------------------------------------------------------------------------------------------------scanf ("%f", &radius); area = PI * pow (radius,2); printf ("Area of a circle = %5.2f\n", area); } /*----------------------------Output RUN1 Enter the radius of a circle 3.2 Area of a circle = 32.17 RUN 2 Enter the radius of a circle 6 Area of a circle = 113.11 ------------------------------*/ 3./* Write a C program to find the simple interest , given principle, * * rate of interest and times*/ #include <stdio.h> #include <conio.h> void main() { float p, r, si; int t; clrscr(); printf("Enter the values of p,r and t\n"); scanf ("%f %f %d", &p, &r, &t); si = (p * r * t)/ 100.0; printf ("Amount = Rs. %5.2f\n", p); printf ("Rate = Rs. %5.2f%\n", r); printf ("Time = %d years\n", t); printf ("Simple interest = %5.2f\n", si); } -----------------------------------------------------------------------------------------------------------2
C PROGRAMS -----------------------------------------------------------------------------------------------------------/*----------------------------Output Enter the values of p,r and t 2000 8 3 Amount = Rs. 2000.00 Rate = Rs. 8.00% Time = 3 years Simple interest = 480.00 ------------------------------*/ 4./* Write a C program to check whether a given integer is odd or even*/ #include <stdio.h> #include <conio.h> void main() { int ival, remainder; clrscr(); printf("Enter an integer :"); scanf ("%d", &ival); remainder = ival % 2; if (remainder == 0) printf ("%d, is an even integer\n", ival); else printf ("%d, is an odd integer\n", ival); } /*----------------------------Output RUN1 Enter an integer :13 13, is an odd integer RUN2 Enter an integer :24 24, is an even integer ---------------------------------*/ -----------------------------------------------------------------------------------------------------------3
C PROGRAMS -----------------------------------------------------------------------------------------------------------5./* Write a C program to check whether a given integer * * number is positive or negative*/ #include <stdio.h> #include <conio.h> void main() { int number; clrscr(); printf("Enter a number\n"); scanf ("%d", &number); if (number > 0) printf ("%d, is a positive number\n", number); else printf ("%d, is a negative number\n", number); } /*----------------------------Output Enter a number -5 -5, is a negative number RUN2 Enter a number 89 89, is a positive number ------------------------------*/ 6./* Write a C program to find the biggest of three numbers*/ #include <stdio.h> #include <conio.h> #include <math.h> void main() { int a, b, c; clrscr(); printf("Enter the values of a,b and c\n"); scanf ("%d %d %d", &a, &b, &c); -----------------------------------------------------------------------------------------------------------4

Lecture Notes