×
The question isn’t who is going to let me; it’s who is going to stop me.
--Your friends at LectureNotes
Close

Programming in C

by Mosheck MentaMosheck Menta
Type: PracticalOffline Downloads: 2Views: 56Uploaded: 18 days ago

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

Mosheck Menta
Mosheck Menta
I-YEAR-I-SEM-B.Sc-Computer Science CODE-BS106 C--LAB-MANUAL EXERCISE-1 1. Write a program to find the largest two (three) numbers using if and conditional operator:1. a)if condition using 2 numbers:Program:#include<stdio.h> #include<conio.h> void main() { int a,b; clrscr(); printf("Enter a,b values are :\n"); scanf("%d%d",&a,&b); if(a>b) { printf("a value is largest : %d",a); } else { printf("b value is largest :%d",b); } getch(); } Output:- Govt. Degree College-Bheemgal-Telangana-University Page 1
I-YEAR-I-SEM-B.Sc-Computer Science CODE-BS106 C--LAB-MANUAL 1. b) conditional operator using 2 numbers:Program:#include<stdio.h> #include<conio.h> void main() { int a,b,z; clrscr(); printf("Enter a,b values are :\n"); scanf("%d%d",&a,&b); z=(a>b) ? a : b; printf("largest number is :%d",z); getch(); } Output:- 1. c) if condition using 3 numbers:Program:# include <stdio.h> #include<conio.h> void main() { int a, b, c,; Govt. Degree College-Bheemgal-Telangana-University Page 2
I-YEAR-I-SEM-B.Sc-Computer Science CODE-BS106 C--LAB-MANUAL clrscr(); printf("Enter three numbers : ") ; scanf("%d %d %d", &a, &b, &c) ; if(a>b) { printf("a is largest : %d",a); } else if(b>c) { printf("b is largest : %d",b); } else { printf("c is largest : %d",c); } getch(); } Output:- 1. d) conditional operator using 3 numbers:Program:# include <stdio.h> #include<conio.h> void main() Govt. Degree College-Bheemgal-Telangana-University Page 3
I-YEAR-I-SEM-B.Sc-Computer Science CODE-BS106 C--LAB-MANUAL { int a, b, c, z ; clrscr(); printf("Enter three numbers : ") ; scanf("%d %d %d", &a, &b, &c) ; z = a > b ? (a > c ? a : c) : (b > c ? b : c) ; printf("\nThe largest number is : %d", z) ; getch(); } Output:- Govt. Degree College-Bheemgal-Telangana-University Page 4

Lecture Notes