0% found this document useful (0 votes)
48 views

Program:1: / Wap The First C Programming

The document contains 25 C programming code examples submitted by a student named Rajat Maheshwari. The programs cover basic concepts like input/output, arithmetic operations, conditional statements, loops, functions etc. Each program is preceded by a brief description of the problem it solves and followed by the output for a sample run. The programs demonstrate the student's understanding of basic C programming concepts and ability to write small programs to solve simple problems.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Program:1: / Wap The First C Programming

The document contains 25 C programming code examples submitted by a student named Rajat Maheshwari. The programs cover basic concepts like input/output, arithmetic operations, conditional statements, loops, functions etc. Each program is preceded by a brief description of the problem it solves and followed by the output for a sample run. The programs demonstrate the student's understanding of basic C programming concepts and ability to write small programs to solve simple problems.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 68

Program:1

/*Wap the first c programming*/


#include<stdio.h> #include<conio.h> void main() { clrscr(); printf("Hello"); getch(); } Output:Hello

Name-Rajat Maheshwari

Roll no-12115014

Bca-IInd Sem

Program:2
/*Wap for accepting three integer from user and print the greater number*/ #include<stdio.h> #include<conio.h> void main() { clrscr(); int a,b,l; printf("\n enter the three number="); scanf("%d %d %d",&a,&b,&l); if(a>b) { l=a; } if(b>a) { l=b; } printf("\n largest is%d",l); getch(); } Output:enter the three number=5 6 4 largest is 6
Name-Rajat Maheshwari Roll no-12115014
2

Bca-IInd Sem

Program:3
/*Wap for accepting the three subject marks of student*/
#include<stdio.h> #include<conio.h> void main() { int m1,m2,m3,tot; float per; char gd; printf("\n enter three subjet marks"); scanf("\n %d %d %d",&m1,&m2,&m3); tot=m1+m2+m3; per=tot/3; if(per>=0 && per<=33) gd='d'; if(per>=33 && per<=45) gd='c'; if(per>=45 && per<=60) gd='b'; if(per>=60 && per<=100) gd='a'; printf("\n grad is %c",gd); getch();} Output:enter three subject marks78 85 65 grad is a
Name-Rajat Maheshwari Roll no-12115014
3

Bca-IInd Sem

Program:4
/*Wap for accepting two integer then print greater number*/ #include<stdio.h> #include<conio.h> void main() { clrscr(); int a,b,l,e; printf("\n enter two integer a and b="); scanf("%d %d",&a,&b); l=(a>b)?a:b; printf("\n great is=%d",l); getch(); } Output:enter two integer a and b=12 13 great is=13

Name-Rajat Maheshwari

Roll no-12115014

Bca-IInd Sem

Program:5
/*Wap for accepting two integer in to print addition*/ #include<stdio.h> #include<conio.h> void main() { int a,b,c; printf("\n enter two number"); scanf("%d%d",&a,&b); c=a+b; printf("\n sum is %d",c); getch(); } Output:enter two number12 23 Sum is 35

Name-Rajat Maheshwari

Roll no-12115014
5

Bca-IInd Sem

Program:6
/*WAP to subtract two numbers.*/ #include<stdio.h> #include<conio.h> void main() { clrscr(); int a,b,c; a=20; b=10; c=a-b; printf("\n subtract=%d",c); getch(); } Output: subtract=10

Name-Rajat Maheshwari

Roll no-12115014
6

Bca-IInd Sem

Program:7
/*WAP for accepting 2 integers from user then print their subtraction.*/ #include<stdio.h> #include<conio.h> void main() { clrscr(); int a,b,c; printf("\n input a="); scanf("%d",&a); printf("\n input b="); scanf("%d",&b); c=a-b; printf("\n subtract=%d",c); getch(); }

Output: input a=60 input b=40 subtract=20

Name-Rajat Maheshwari

Roll no-12115014
7

Bca-IInd Sem

Program:8
/*Wap for accepting of a circle then calculated the aria circumaface of circle*/ #include<stdio.h> #include<conio.h> void main() { clrscr(); int r; float ar,cr; printf("\n enter the radius of circle); scanf("%d",&r); ar=3.14*r*r; cr=2*3.14*r; printf("\n area of circle is %f",r); printf("\n circamfance of circle is %f",r); getch(); } Output:enter the radious of circle 78 area of circle is 24119115786251198500.0 circamefance of is 24119115786251198500.00

Name-Rajat Maheshwari

Roll no-12115014
8

Bca-IInd Sem

Program:9
/*Wap for accepting to integer from user then print those integer after that swapping the value */ #include<stdio.h> #include<conio.h> void main() { clrscr(); int a,b,tamp; printf("\n enter two intger"); scanf("%d%d",&a,&b); printf("\n before swapping %d %d ",a,b); tamp=a; a=b; b=tamp; printf("\n after swapping %d %d",a,b); getch(); } Output:enter two integr 12 23 before swapping 12 23 after swapping 23 12

Name-Rajat Maheshwari

Roll no-12115014
9

Bca-IInd Sem

Program:10
/*Wap for accepting two integer from user then print those integer after that swapping the value of these integer and pint these value*/ #include<stdio.h> #include<conio.h> void main() { clrscr(); int a,b; printf("\n enter two intger"); scanf("%d %d",&a,&b); printf("\n before swapping %d %d",a,b); a=a+b; b=a-b; a=a-b; printf("\n after swapping %d%d",a,b=); getch(); } Output:enter two intger 11 12 before swapping 11 12 after swapping 12 11

Name-Rajat Maheshwari

Roll no-12115014
10

Bca-IInd Sem

Program:11
/*Wap for accepting from user to print the convert temperature in Fahrenheit */
#include<stdio.h> #include<conio.h> void main() { clrscr(); int c,f,s; printf("\n enter two number c,f="); scanf("%d %d",&c,&f); c=f(-32)*s/9; printf("\n the value in Celsius=%d",c); f=9/5*c+32; printf("\n value in farenihit=%d",f); getch(); } Output:enter two number c,f=95 85 the value in celsis= 2334 value in fare hint=2366

Name-Rajat Maheshwari

Roll no-12115014
11

Bca-IInd Sem

Program:12
/*Wap for accepting two integer from user then print there value after that swap that value wit out using any temporary value*/ #include<stdio.h> #include<conio.h> void main() { int edge,ar,per; printf("\n enter edge of a square"); scanf("\n %d",&edge); ar=edge*edge; per=u*edge; printf("\n area of square=%d",ar); printf("\n perimeter of square=%d"); getch(); } Output:enter edge of a square 12 area of square 144 perimeter of square=-24616

Name-Rajat Maheshwari

Roll no-12115014
12

Bca-IInd Sem

Program:13
/*Wap for accepting the radius of sphere then calculate its value and surface area*/
#include<stdio.h> #include<conio.h> void main() { int r,vol,sa; printf("\n enter radious of sherface"); scanf("%d",&r); vol=4/3*3.14*r*r*r; sa=4*3.14*r*r; printf("\n value of Scarface=%d",vol); printf("\n surface area of share face=%d",&sa); getch(); } Output:enter radius of she face= 45 value of Scarface=23988 surface area of Scarface=-16

Name-Rajat Maheshwari

Roll no-12115014
13

Bca-IInd Sem

Program:14
/*WAP for accepting a no. from user then print the table of that no.*/ #include<stdio.h> #include<conio.h> void main() { int i,t,n; printf("\n enter the no"); scanf("%d",&n); for(i=1;i<=10;i++){ t=n*i; printf("\n %d",t);} getch(); } Output: enter the no 2 4 6
Name-Rajat Maheshwari Roll no-12115014
14

Bca-IInd Sem

8 10 12 14 16 18 20

Name-Rajat Maheshwari

Roll no-12115014
15

Bca-IInd Sem

Program:15
/*wap for accepting to get area of triangle*/ #include<stdio.h> #include<conio.h> void main() { float l,b,area; clrscr(); printf("\n enter the length and breath of triangle="); scanf("%f%f",&l,&b); area=0.5*(l*b); printf("\n area of triangle is=%f",area); getch(); } Output:enter the length and breath of triangle=4 5 area of triangle is=10.000000
.

Name-Rajat Maheshwari

Roll no-12115014
16

Bca-IInd Sem

Program:16
/*wap for accepting to determine the months from the days*/ #include<stdio.h> #include<conio.h> void main() { int a,r,month; clrscr(); printf("\n enter the number of days="); scanf("%d",&a); month=a/30; printf("\n months =%d",month); r=a%30; printf("\n days =%d",r); getch();} Output:enter the number of days=96 month=3 day=6
Name-Rajat Maheshwari Roll no-12115014
17

Bca-IInd Sem

Program:17
/*WAP for accepting an integer from user then calculate its factorial.*/ #include<stdio.h> #include<conio.h> void main() { int i,f,n; clrscr(); printf("\n enter any no"); scanf("%d",&n); for(i=1;i<=n;i++) { f=f*i; } printf("factorial is %d",fact); getch(); } Output: enter any no 3 fctorial is 6

Name-Rajat Maheshwari

Roll no-12115014
18

Bca-IInd Sem

Program:18
/*WAP to calculate the sumof first 10 natural numbers*/ #include<stdio.h> #include<conio.h> void main() { int i,s=0; for (i=o;i<=10,i++) { s=s+i; } printf("%d",s); getch(); }

Output: 5

Name-Rajat Maheshwari

Roll no-12115014
19

Bca-IInd Sem

Program:19
/*wap for accepting the reverse of the given number */ #include<stdio.h> #include<conio.h> void main() { int no,d,rev=0; clrscr(); printf("\n enter the number="); scanf("%d",&no); for( ;no>0; ){ d=no%10; rev=rev*10+d; no=no/10;} printf("\n reverse =%d",rev); getch();} Output:enter the number=678 reverse=876
.Name-Rajat Maheshwari

Roll no-12115014
20

Bca-IInd Sem

Program:20
/*wap for accepting to check weather the given number is prime or not */ #include<stdio.h> #include<conio.h> void main(){ int no,i,rem=0; clrscr(); printf("\n enter the number="); scanf("%d",&no); for(i=1;i<=no/2;i++){ if(no%i==0) rem=rem+1;} if(rem==2) printf("\n number is palindrome"); { else printf("\n number is not palindrome"); }

Name-Rajat Maheshwari

Roll no-12115014
21

Bca-IInd Sem

getch(); } Output: enter the number =121 number is palindrome

Name-Rajat Maheshwari

Roll no-12115014
22

Bca-IInd Sem

Program:21
/*Wap for accepting to weather the number is even or odd using ternary operator*/ #include<stdio.h> #include<conio.h> void main() { int no; clrscr(); printf("\n enter the number="); scanf("%d",&no); printf("\n given number is =%s",((no%2==0)?"even":"odd")); getch(); } Output:enter the number=4 given number is=even

Name-Rajat Maheshwari

Roll no-12115014
23

Bca-IInd Sem

Program:22
/*Wap for accepting to print the given number is positive or not */ #include<stdio.h> #include<conio.h> void main() { int no; clrscr(); printf("\n enter the number="); scanf("%d",&no); if(no>=0){ printf("\n given number is positive");} else { Printf(\n given number is negative); } getch(); }

Name-Rajat Maheshwari

Roll no-12115014
24

Bca-IInd Sem

Output:enter the number=34 given number is possitive

Name-Rajat Maheshwari

Roll no-12115014
25

Bca-IInd Sem

Program:23
/*wap for accepting to print the largest number among three number using ternary operator*/ #include<stdio.h> #include<conio.h> void main() { int a,b,c,d; printf("\n enter three numbers="); scanf("%d%d%d",&a,&b,&c); d=(a>b)?a:b; d=(d>c)?a:c printf("\n largest number=%d",d); getch(); Output:enter three number=5 7 9 largest number=9
Name-Rajat Maheshwari Roll no-12115014
26

Bca-IInd Sem

Program:24
/*Wap for accepting to convert rupees into paisa*/ #include<stdio.h> #include<conio.h> void main() { int rs,p; clrscr(); printf("\n enter amount in rupees="); scanf("%d",&rs); p=(rs*100); printf("\n amount in Paisa=%d",p); getch(); } Output:enter amount in rupees=23 amount in Paisa=2300

Name-Rajat Maheshwari

Roll no-12115014
27

Bca-IInd Sem

Program:25
/*wap for accepting to understand the working of if statement
#include<stdio.h> #include<conio.h> void main() { clrscr(); int n=3,a; printf("enter the value of a="); scanf("%d",&a); if(a==n) { printf("both number are equale"); } printf("%d",a); getch(); }

Output:
enter the value of a&b12 12 both number are equal Name-Rajat Maheshwari Roll no-12115014
28

Bca-IInd Sem

Program:26
/*wap for accepting to print the largest number between two number */

#include<stdio.h> #include<conio.h> void main() { int a,b; clrscr(); printf("\n enter two number="); scanf("%d%d",&a,&b); if(a>b) { printf("\n largest number is =%d",a); } else { printf("\n largest number is =%d",b); } getch();}
Name-Rajat Maheshwari Roll no-12115014
29

Bca-IInd Sem

Output:enter two number=45 67 largest number is=67

Name-Rajat Maheshwari

Roll no-12115014
30

Bca-IInd Sem

Program:27
/*wap for accepting to check the largest number among three number using if-else statement */ #include<stdio.h> #include<conio.h> void main() { int a,b,c; clrscr(); printf("\n enter three numbers="); scanf("%d%d%d",&a,&b,&c); if(a>b & a>c) { printf("\n largest number is =%d",a); } else if(b>a & b>c) { printf("\n largest number is =%d",b); }
Name-Rajat Maheshwari Roll no-12115014
31

Bca-IInd Sem

else { printf("\n largest number is =%d",c); } getch(); } Output:enter three number=34 5 6 largest number is=34

Name-Rajat Maheshwari

Roll no-12115014
32

Bca-IInd Sem

Program:28
/*wap for accepting to print the sum of digits of given number */ #include<stdio.h> #include<conio.h> void main() { int no,d,sum=0; clrscr(); printf("\n enter a number="); scanf("%d",&no); for( ;no>0; ) { d=no%10; sum=sum+d; no=no/10; } printf("\n Sum of the digit =%d",sum); getch(); }
Name-Rajat Maheshwari Roll no-12115014
33

Bca-IInd Sem

Output:enter a number=2 3 4 sum of the digit=9

Name-Rajat Maheshwari

Roll no-12115014
34

Bca-IInd Sem

Program:29
/*Wap for accepting user then print area of rectangle */ #include<stdio.h> #include<conio.h> void main() { clrscr(); char ch; float l,b,ar; printf("\n enter your choice="); scanf("%c",&ch); if(ch==ar) { printf("\n enter lenth and breath"); scanf("%f %f",&l,&b); ar=l*b; printf("\n area is %f ",ar); } else if(ch=='c') { printf("\n enter radious"); scanf("%f",&l); ar=3.14*l*l; printf("\n area is=%f",ar); } else {
Name-Rajat Maheshwari Roll no-12115014
35

Bca-IInd Sem

printf("\n wrong choice"); } getch(); } Output:enter your choice=56 wrong choice

Name-Rajat Maheshwari

Roll no-12115014

Bca-IInd Sem

36

Program:30
/*wap for accepting to understand the working of if not statement*/
#include<stdio.h> #include<conio.h> void main() { clrscr(); int a,b; printf("enter the value of a&b"); scanf("%d %d",&a,&b); if(a>b) { printf("the value of a=%d",a;both number are equal"); } else { printf("both number are not equal"); }
Name-Rajat Maheshwari Roll no-12115014
37

Bca-IInd Sem

getch(); }

Output:
enter the number a=2 b=1 both number are not equal

Name-Rajat Maheshwari

Roll no-12115014
38

Bca-IInd Sem

Program:31
/*Wap for accepting the total electricity units consume by a user*/

#include<stdio.h> #include<conio.hj> Void main() { float ut,ta; clrcscr(); prin tf(\n enter total unit consume); scanf(%f,&ut); If(ut>=0 && ut<100) ta=.60*ut; If(ut>=100 && ut<100) ta=100*.60+(ut-100)*1; if(ut>=150 && ut <250) ta=100*.60+50*1+100*2(ut-250)*2.5; printf(total bill is %f,ta);

Name-Rajat Maheshwari

Roll no-12115014
39

Bca-IInd Sem

getch();

} Output:enter total unit consume 12000 total bill is 5875110.0

Name-Rajat Maheshwari

Roll no-12115014

Bca-IInd Sem

40

Program:32
/*wap for accepting print total number of digit present in a given number */ #include<stdio.h> #include<conio.h> void main() { int no,d,c=0; clrscr(); printf("\n enter a number="); scanf("%d",&no); for( ;no>0; ) { d=no%10; c++; no=no/10; } printf("\n present digit is =%d",c);

Name-Rajat Maheshwari

Roll no-12115014
41

Bca-IInd Sem

getch(); } Output:enter a number=456 present digit is=3

Name-Rajat Maheshwari

Roll no-12115014
42

Bca-IInd Sem

Program:33
/*wap for accepcting to print the factorial of given number */ #include<stdio.h> #include<conio.h> void main() { int no,i,f=1; clrscr(); printf("\n Enter a number="); scanf("%d",&no); while(no>0){ f=f*no; no=no-1;} printf("\n Factorial of given number is =%d",f); getch(); } Output:Enter a number=4 Factorial of given is=2
Name-Rajat Maheshwari Roll no-12115014
43

Bca-IInd Sem

Program-34
/*wap for accepting to find the simple interest*/ #include<stdio.h> #include<conio.h> void main() { clrscr(); foalt p,r,t,si; printf("enter the principle"); scanf("%f",&p); printf("enter the rate"); scanf("%f",&r); printf("enter the time period(in year)"); scanf("%f",&t); si=(p*r*t)/100; printf("simple interest=%f",si); getch(); }

Name-Rajat Maheshwari

Roll no-12115014
44

Bca-IInd Sem

Output: enter a principle 1040 enter the rate 2.5


enter the time 2 simple interest=52

Name-Rajat Maheshwari

Roll no-12115014
45

Bca-IInd Sem

Program:35
/*WAP for accepting the legth,breadth and height of a cuboids then calculate its volume and surface area.*/ #include<stdio.h> #include<conio.h> void main() { int l,b,h; float vol,sa; printf("\n enter the length,breadth and height") ; scanf("%d%d%d",&l,&b,&h); vol=l*b*h; sa=2*(l*b+b*h+h*l); printf("\n volume of cuboid %f",vol); printf("\n surface area of cuboid %f",sa); getch(); } Output: enter the length,breabth and height 2 3 4 volume of cuboid 24.000 surface area of coboid 52.000

Name-Rajat Maheshwari

Roll no-12115014
46

Bca-IInd Sem

Program:36
/*WAP to print this pattern.*/ 12345 12345 12345 12345 #include<stdio.h> #include<conio.h> void main() { int i,j; for(i=1;i<=4;i++) { for(j=1;j<=5;j++) { printf("%d",j); } printf("\n");

Name-Rajat Maheshwari

Roll no-12115014
47

Bca-IInd Sem

} getch(); }

Output: 12345 12345 12345 12345

Name-Rajat Maheshwari

Roll no-12115014
48

Bca-IInd Sem

Program:37
/*WAP to print the given pattern.*/ * *** ***** ******* ********* ******* ***** *** * #include<stdio.h> #include<conio.h> void main() { int i,j; clrscr(); for(i=1;i<=5;i++) { for(j=4;j>=i;j--) { printf(" "); } for(j=1;j=(2*i-1);j++) { printf("*"); } printf("\n"); } for(i=4;i>=1;i--)
Name-Rajat Maheshwari Roll no-12115014
49

Bca-IInd Sem

{ for(j=4;j>=i;j--) { printf(" "); } for(j=1;j<=(2*i-1);j++) { printf("*"); } printf("\n"); } getch(); } Output: * *** ***** ******* ********* ******* * ** * * ***
*

Name-Rajat Maheshwari

Roll no-12115014
50

Bca-IInd Sem

Program:38
/*WAP to print the pattern given below:**/
ABCDE BCDE CDE CD E #include<stdio.h> #include<conio.h> void main() { int i,j; char ch; ch='A'; for(i=5;i>=1;i++) { for(j=i;j>=1;j--) { printf("%c",ch); ch++; } printf("\n"); } getch(); }

Name-Rajat Maheshwari

Roll no-12115014
51

Bca-IInd Sem

Output: ABCDE BCDE CDE DE E

Name-Rajat Maheshwari

Roll no-12115014
52

Bca-IInd Sem

Program:39
/*WAP to print first 20 terms of a Fibonacci series.*/ #include<stdio.h> #include<conio.h> void main() { int i,c,a=0,b=1; printf("enter the terms of Fibonacci series"); printf("%d",a); printf("%d",b); for(i=3;i<=20;i++){ c=a+b; printf("\n %d",c); a=b; b=c;} getch(); } Output: enter the terms of Fibonacci series 1 2 3 5 8 13 21 34 55 89 144
Name-Rajat Maheshwari Roll no-12115014
53

Bca-IInd Sem

233 377 610 987 1597 2584 4181

Name-Rajat Maheshwari

Roll no-12115014
54

Bca-IInd Sem

Program:40
/*WAP for accepting five subject marks of a student then calculate its total and percentage and then print them.*/ #include<stdio.h> #include<conio.h> void main() {as int m1,m2,m3,m4,m5,total; float per; clrscr(); printf("\n enter marks of 5 subjects"); scanf("%d%d%d%d%d",&m1,&m2,&m3,&m4,&m5); total=m1+m2+m3+m4+m5; per=total/5; printf("totalmarks=%d",total); printf("percentage=%f",per); getch(); } Output: enter marks of 5 subjects 23 45 67 89 45 total=269.000 percentage=53.80000

Name-Rajat Maheshwari

Roll no-12115014
55

Bca-IInd Sem

Program:41
/*WAP for accepting an integer from user if it is 1 then, calculate the area of body .If it is 2 then calculate the volume of body. If user enter 1 then calculate the area of rectangle .If he choose 'r' ,calculate the area of circle if he use 'c' otherwise display appropriate message. similarly user enter 2 then calculate the volume of cuboids if he choose 'd 'and calculate the volume of a sphere if an user choose 's' other display message.*/ #include<stdio.h> #include<conio.h> void main() { int l,b,h,ch1; float res; char ch2; clrscr(); printf("\n 1-area of body"); printf("\n 2-volume of body"); printf("\n enter ur choice"); scanf("%d",&ch1); switch(ch1) { case 1: printf("\n r:ar. of rectangle"); printf("\n c:ar of circle"); fflush(stdin); printf("\n enter ur choice"); scanf("\n %c",&ch2); switch(ch2) { case 'r': printf("\n enter lenght & breadth");
Name-Rajat Maheshwari Roll no-12115014
56

Bca-IInd Sem

scanf("\n %d",&l,&b); res=l*b; printf("\n area=%f",res); break; case 'c': printf("\n enter radius of circle"); scanf("\n %d",&l); res=3.14*l*l; printf("\n area=%f",res); break; default: printf("\n wrong choice"); } break; case 2: printf("\n d:volume of cuboid"); printf("\n s:volume of sphere"); fflush(stdin); printf("\n enetr your choice"); scanf("\n %c",&ch2); switch(ch2) { case 'd': printf("\n enter lenght breadth & height of cuboid"); scanf("\n %d%d%d",&l,&b,&h); res=l*b*h; printf("\n result=%f",res); break; case 's': printf("\n enter radius of sphere"); scanf("\n %d",&l); res=(4/3)*3.14*l*l*l;
Name-Rajat Maheshwari Roll no-12115014
57

Bca-IInd Sem

printf("\n volume=%f",res); break; default: printf("\n invalid choice"); } break; default: printf("\n wrong choice"); } getch(); } OUTPUT 1-area of body 2-volume of body enter ur choice 1 r:ar. of rectangle c:ar of circle enter ur choice c enter radius of circle 7 area=153.860001

Name-Rajat Maheshwari

Roll no-12115014
58

Bca-IInd Sem

Program:42
/*WAP for accepting the length and breadth of a rectangle from user then print the area and perimeter of the rectangle.*/ #include<stdio.h> #include<conio.h> void main() { int l,b,ar,p; clrscr(); printf("\n enter length and breadth"); scanf("%d%d",&l,&b); ar=l*b; p=2*(l+b); printf("\n area of rectangle %d",ar); printf("\n perimeter of rectangle %d",p); getch(); } Output: enter lengh and breadth 2 3 area of rectangle 6.000 perimeter of rectangle 10.000

Name-Rajat Maheshwari

Roll no-12115014
59

Bca-IInd Sem

Program:43
/*WAP for accepting 2 integers from user then print the greater no. using ternary operator.*/ #include<stdio.h> #include<conio.h> void main() { int a,b,l; clrscr(); printf("\n enter 2 integers"); scanf("%d%d",&a,&b); l=(a>b)?a:b; printf("\n greater is %d",l); getch(); } Output: enter 2 integers 2 5 greater is 5

Name-Rajat Maheshwari

Roll no-12115014
60

Bca-IInd Sem

Program:44
/*WAP for accepting an integers and print Fibonacci series*/
#include<stdio.h> #include<conio.h> void main() { int a=0,b=1,c,i; clrscr(); printf("\n fibonacci series ic:\n"); for(i=3;i<10;i++) { printf("\n %d',a); printf("\n %d",b); c=a+b; printf("\n %d",c); a=b; b=c; } getch(); } Output: 0 1 1 2 3 5 8 13 21
Name-Rajat Maheshwari Roll no-12115014
61

Bca-IInd Sem

Program:45
/*WAP for accepting any choice from user from r and c.If it is r then calculate the area of rectangle,if it is c then calculate the area of circle otherwise display appropriate message.*/
#include<stdio.h> #include<conio.h> void main() { char ch; float l,b,ar; clrscr(); printf("r->area of rectangle"); printf("\n c->area of circle"); printf("\n what is your choice\n"); scanf("%c",&ch); switch(ch) { case 'r': case 'R': printf("\n enter length and breadth"); scanf("%f%f",&l,&b); ar=l*b; printf("\n area of rectangle is %f",ar); break; case 'c': case 'C': printf("\n enter radius"); scanf("%f",&l); ar=3.14*l*l; printf("\n area of circle is %f",ar); break;
Name-Rajat Maheshwari Roll no-12115014
62

Bca-IInd Sem

default: printf("\n sorry wrong choice"); } getch(); }

Output: R->AREA OF RECTENGLE C->AREA OF CIRCLE ENTER YOUR CHOICE R ENTER LENGTH AND BREADTH 23 AREA OF RECTANGLE 6.00000

Name-Rajat Maheshwari

Roll no-12115014
63

Bca-IInd Sem

Program:46
/*WAP for accepting the given pattern and print it.*/
********* ******* ***** *** * #include<stdio.h> #include<conio.h> void main() { int i,j; clrscr(); for(i=1;i<=5;i++) { for(j=4;j>=i;j--) { printf(" "); } for(j=1;j<=(2*i-1);j++) { printf("*"); } printf("\n"); } getch(); }

Name-Rajat Maheshwari

Roll no-12115014
64

Bca-IInd Sem

Output: ********* ******* ***** *** *

Name-Rajat Maheshwari

Roll no-12115014
65

Bca-IInd Sem

Program: 47 /*WAP a prog for binary search and print it*/


#include<stdio.h> #include<conio.h> void main() { int a[100],n,i,val,f=0,l,h,mid; clrscr(); printf("\n enter the size of array"); scanf("%d",&n); printf("\n enter the array to be sorted in order"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("the array is:\n"); for(i=0;i<n;i++) { printf("\n %d",a[i]); } printf("\n enter element to be searched"); scanf("%d",&val); l=0; h=(n-1); while(l<=h) { mid=(l+h)/2; if(val==a[mid]) { f=1;
Name-Rajat Maheshwari Roll no-12115014
66

Bca-IInd Sem

break; } else if(val>a[mid]) { l=mid+1; } else if(val<a[mid]) { h=mid-1; } } if(f==0) printf("\n not found"); else printf("\n found at %d",mid+1); getch(); }

Output: enter the size of array 5 enter the array 10 20 30 40 50 enter the element to be searched 30 element found

Name-Rajat Maheshwari

Roll no-12115014
67

Bca-IInd Sem

68

You might also like