Page 1 :
Ques.1: Write a program to input any two number and calculate the sum of two numbers and print it’s result., Ans.1:, Algorithm:, Step 1) START, Step 2) Declare variable: num1,num2, Step 3) Print "Enter the num1: ", Step 4) Input value in : num1, Step 5) Print "Enter the num2: ", Step 6) Input value in : num2, Step 7) Calculate: result= num1+num2, Step 8) Print: “sum of num1 & num2 =”value of result, Step 9) Stop, FLOWCHART:, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int num1,num2,result;, clrscr();, printf("Enter the num1: ");, scanf("%d",&num1);, printf("Enter the num2: ");, scanf("%d",&num2);, result= num1 + num2;, printf("the sum of %d and %d is %d",num1,num2,result);, getch();, }, Output-, Enter the num1: 3, Enter the num2: 4, the sum of 3 and 4 is 7, Ques.2: Write a program to input any two number and calculate the difference of two numbers and print it’s result., Ans.2:, Algorithm:, Step 1) START, Step 2) Declare variable: num1,num2, Step 3) Print "Enter the num1: ", Step 4) Input value in : num1, Step 5) Print "Enter the num2: ", Step 6) Input value in : num2, Step 7) Calculate: result= num1-num2, Step 8) Print: “difference of num1 & num2 =”value of result, Step 9) Stop, FLOWCHART:, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int num1,num2,result;, clrscr();, printf("Enter the num1: ");, scanf("%d",&num1);, printf("Enter the num2: ");, scanf("%d",&num2);, result= num1 + num2;, printf("the difference of %d and %d is %d",num1,num2,result);, getch();, }, Output-, Enter the num1: 3, Enter the num2: 4, the difference of 3 and 4 is 1, Ques.3: Write a program to input any two number and calculate the product of two numbers and print it’s result., Ans.3:, Algorithm:, Step 1) START, Step 2) Declare variable: num1,num2, Step 3) Print "Enter the num1: ", Step 4) Input value in : num1, Step 5) Print "Enter the num2: ", Step 6) Input value in : num2, Step 7) Calculate: result= num1*num2, Step 8) Print: “product of num1 & num2 =”value of result, Step 9) Stop, FLOWCHART:, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int num1,num2,result;, clrscr();, printf("Enter the num1: ");, scanf("%d",&num1);, printf("Enter the num2: ");, scanf("%d",&num2);, result= num1 * num2;, printf("the product of %d and %d is %d",num1,num2,result);, getch();, }, Output-, Enter the num1: 3, Enter the num2: 4, the product of 3 and 4 is 12, Ques.4: Write a program to input any two number and calculate the division of two numbers and print it’s result., Ans.4:, Algorithm:, Step 1) START, Step 2) Declare variable: num1,num2, Step 3) Print "Enter the num1: ", Step 4) Input value in : num1, Step 5) Print "Enter the num2: ", Step 6) Input value in : num2, Step 7) Calculate: result= num1/num2, Step 8) Print: “the quotient of num1 & num2 =”value of result, Step 9) Stop, FLOWCHART:, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int num1,num2,result;, clrscr();, printf("Enter the num1: ");, scanf("%d",&num1);, printf("Enter the num2: ");, scanf("%d",&num2);, result= num1 / num2;, printf("the quotient of %d and %d is %d",num1,num2,result);, getch();, }, Output-, Enter the num1: 12, Enter the num2: 4, the product of 3 and 4 is 3, Ques.5: Write a program to input any two number and calculate the modular division of two numbers and print it’s result., Ans.5:, Algorithm:, Step 1) START, Step 2) Declare variable: num1,num2, Step 3) Print "Enter the num1: ", Step 4) Input value in : num1, Step 5) Print "Enter the num2: ", Step 6) Input value in : num2, Step 7) Calculate: result= num1%num2, Step 8) Print: “the modular division of num1 & num2 =”value of result, Step 9) Stop, FLOWCHART:, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int num1,num2,result;, clrscr();, printf("Enter the num1: ");, scanf("%d",&num1);, printf("Enter the num2: ");, scanf("%d",&num2);, result= num1 / num2;, printf("the quotient of %d and %d is %d",num1,num2,result);, getch();, }, Output-, Enter the num1: 12, Enter the num2: 4, the product of 3 and 4 is 3, Ques.6 Write a program to calculate the area of triangle using at=√s(s-a) (s-b) (s-c)., Ans.6: Algorithm:, Step 1: Start, Step 2: Declaration variable: a, b, c, s, area, Step 3: Print: “Enter value of a”, Step 4: Input Value in: a, Step 5: Print “Enter the Value of b”, Step 6: Input Value in: b, Step 7: Print “Enter Value of c”, Step 8: Input value in: c, Step 9: Calculate s= (a+b+c)/2, Step10: Calculate area =sqrt(s*(s-a)*(s-b)*(s-c)), Step11: Print “Area of triangle”= value of area, Step12: Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, #include<math.h>, void main(), {, int a,b,c;, float s,area;, printf("\n Enter the value of a:");, scanf("%d",&a);, printf("\n Enter the value of b:");, scanf("%d",&b);, printf("\n Enter the value of c:");, scanf("%d",&c);, s=(a+b+c)/2;, area=sqrt(s*(s-a)*(s-b)*(s-c));, printf("\n Area of triangle=%2f",s,area);, getch();, }, Input/output:, Enter the value of a:5, Enter the value of b:7, Enter the value of c:9, Area of triangle=10.000000, Ques.7: Basic salary of an employee is input through the keyboard. The DA is 25% of the basic salary while the HRA is 15% of the basic salary. Provident Fund is deducted at the rate of 10% of the gross salary (BS+DA+HRA). Program to calculate the Net Salary., Ans.7: Algorithm:, Step 1: Start, Step 2: Declaration variable: bs, da, hra, pf, ns, Step 3: Print: “Enter value of bs”, Step 4: Input Value in: bs, Step 5: Calculate da= bs*(0.25), Step 6: Calculate hra=bs*(0.15), Step 7: Calculate pf=bs*(0.10), Step 8: Calculate ns= (bs+hra+da)-pf, Step 9: Print “The net salary”=ns, Step10: Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, #include<math.h>, void main(), {, float bs,da,hra,pf,ns;, printf("Enter the value of bs:");, scanf("%f",&bs);, da=bs*(0.25);, hra=bs*(0.15);, pf=bs+hra+da;, ns=bs-(0.10*pf);, printf("The net salary:%f",ns);, getch();, }, Input/ Output:, Enter the value of bs: 10000, The net salary:8600.000000, Ques.8: Write a program to determine the roots of quadratic equation., Ans.8: Algorithm:, Step 1: Start, Step 2: Declaration variable: a, b, c, x, y, Step 3: Print: “Enter value of a”, Step 4: Input Value in: a, Step 5: Print “Enter the Value of b”, Step 6: Input Value in: b, Step 7: Print “Enter Value of c”, Step 8: Input value in: c, Step 9: Calculate x=(-b+sqrt(b*b-(4*a*c)))/2*a, Step10: Calculate y= (-b-sqrt (b*b-(4*a*c)))/2*a, Step11: Print “root”: x, y, Step12: Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, #include<math.h>, void main(), {, float a,b,c,x,y,d;, printf("\n Enter the value of a:");, scanf("%f",&a);, printf("\n Enter the value of b:");, scanf("%f",&b);, printf("\n Enter the value of c:");, scanf("%f",&c);, d=((b*b)-(4*a*c));, x=(-b+sqrt(d))/(2*a);, y=(-b-sqrt(d))/(2*a);, printf("/n Root=%f",x);, printf("/n Root=%f",y);, getch();, }, Input/output:, Enter the value of a:1, Enter the value of b:-5, Enter the value of c:-14, Roots =7.000000,-2.000000, Ques.9: Write a program to find the largest of three numbers using nested if else., Ans.9: Algorithm:, Step 1: Start, Step 2: Declaration variable: a, b, c, Step 3: Print: “Enter value of a”, Step 4: Input Value in: a, Step 5: Print “Enter the Value of b”, Step 6: Input Value in: b, Step 7: Print “Enter Value of c”, Step 8: Input value in: c, Step9: If a>b and a>c then print a is greater., Step10: If b>a and b>c then print b is greater., Step11: If c>a and c>b then print c is greater., Step12: Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int a,b,c;, printf("\n Enter the value of a:");, scanf("%d",&a);, printf("\n Enter the value of b:");, scanf("%d",&b);, printf("\n Enter the value of c:");, scanf("%d",&c);, if((a>b)&&(a>c)), {, printf("%d a is greater",a);, }, else if((b>a)&&(b>c)), {, printf("%d b is greater",b);, }, else if((c>a)&&(c>b)), {, printf("%d c is greater",c);, }, getch();, }, Input/output:, Enter the value of a:8, Enter the value of b:9, Enter the value of c:7, 9 b is greater, }, }, }, Ques.10: Write a program to receive marks of physics, chemistry & maths from user & check its eligibility for the course if, a) Marks of physics > 40, b) Marks of chemistry > 50, c) Marks of math's > 60, d) Total of physics & math's marks > 150, or, e) Total of three subjects marks > 200, Ans.10: Algorithm:, Step 1: Start, Step 2: Declaration variable: phy, chem, maths, pm, total, Step 3: Print: “Enter marks of phy”, Step 4: Input marks in: phy, Step 5: Print: “Enter marks of chem”, Step 6: Input marks in chem, Step 7: Print: “Enter marks of maths”, Step 8: Input marks in maths, Step 9: Calculate: pm=phy+chem+maths, Step 10: check: (phy>40, chem>50, maths>60 & pm>150 or total>200), Step 11: If Step 10 is true then print:" you are eligible for the test", Step 12: Else if Step 10 is false then print "not eligible", Step 13: Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int phy,chem,maths,pm,total;, printf("Enter marks in phy:");, scanf("%d",&phy);, printf("Enter marks in chem:");, scanf("%d",&chem);, printf("Enter marks in maths:");, scanf("%d",&maths);, pm=phy+maths;, if(phy>40&&chem>50&&maths>60&&pm>150||total>200), {, printf("\n you are eligible for the test");, }, else, printf("\n not eligible");, getch();, }, Input /Output:, Enter marks in phy:70, Enter marks in chem:80, Enter marks in maths:90, you are eligible for the test., Ques.11:, Ans.11: Algorithm:, Step 1: Start, Step 2: Declaration variable: a, x, b, n, y, Step 3: Print: “Enter value of a”, Step 4: Input Value in: a, Step 5: Print “Enter the Value of x”, Step 6: Input Value in: x, Step 7: Print “Enter Value of b”, Step 8: Input value in: b, Step9: Print “Enter Value of n”, Step10: Input value in: n, Step11: If n==1 then print: “y=a*(x%b)”, Step12: Calculate & initialize Y=a*(x%b), Step13: If n==2 then print: “y=(a*x*x)+(b*b)”, Step14: Calculate & initialize y=(a*x*x)+(b*b), Step15: If n==3 then print: “y=a-(b*x)”, Step16: Calculate & initialize y=a-(b*x), Step17: If n==4 then print: “y=a+(x/b)”, Step18: Calculate &initialize y=a+(x/b), Step19: Print “Error! wrong input in n”, Step20: Print “y=”, y, Step21: Stop, Flowchart:, j, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int a,b,x,n;, float y;, printf("\n Input a:");, scanf("%d",&a);, printf("\n Input x:");, scanf("%d",&x);, printf("\n Input b:");, scanf("%d",&b);, printf("\n Input n:");, scanf("%d",&n);, switch(n), {, case 1:, printf("y=a*x%b:");, y=(a*x)%b;, break;, case 2:, printf("y=a*x*x+b*b:");, y=(a*x*x)+b*b;, break;, case 3:, printf("y=a-bx:");, y=a-b*x;, break;, case 4:, printf("y=a+x/b=");, y=(float)a+(float)x/(float)b;, break;, default:, printf("Error! Wrong input of n");, }, printf ("%.2f", y);, getch();, }, Input /Output:, Input a:6, Input x:7, Input b:8, Input n:2, y=a*x*x+b*b=358.00, Ques.12: Write a program to construct a Fibonacci series upto n terms., Ans.12: Algorithm:, Step 1: Start, Step 2: Declaration variable: a=0, b=1, c=0, n, i;, Step 3: Print: “Enter number of terms:”, Step 4: Input value: n, Step 5: Print "fibonacci series:", Step 6: For(i=1; i<=n; i++), Step 7: Print the value of c, Step 8: Calculate and initialize: a=b, b=c, c=a+b, Step 9: End For, Step 10: Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int a=0,b=1,c=0,n,i;, clrscr ();, printf("\n Enter number of terms:");, scanf("%d",&n);, printf("fibonacci series:");, for(i=1;i<=n;i++), {, printf("%d",c);, a=b;, b=c;, c=a+b;, }, getch();, }, Input /Output:, Enter number of terms:6, fibonacci series:011235, Ques.13: Write a program to find whether the number is Armstrong number., Ans.13: Algorithm:, Step 1: Start, Step 2: Declare variable: n, n1, result=0, Step 3: Print " Enter a three digit number:", Step 4: Input value in n, Step 5: Initialize: n1=n, Step 6: While: (n1!=0) then calculate : r=n1%10,result=(r*r*r),n1/=10, Step 7: check if: (result==n), Step 8: If step 7 is true then print: “Is an Armstrong number”, Step 9: Else if step 7 is false then print: “Is not an Armstrong number”, Step 10: Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int n,n1,r,result=0;, printf("\n Enter a three digit number:");, scanf("%d",&n);, n1=n;, while(n1!=0), {, r=n1%10;, result+=(r*r*r);, n1/=10;, }, if(result==n), printf("\n%d is an armstrong number",n);, else, printf("\n%d is not an armstrong numbers",n);, getch();, }, Input /Output:, Enter a three digit number:371, 371 is an armstrong number:, Ques.14: Write a program to generate the sum of series 1!+2!+3!+……………+n!, Ans.14: Algorithm:, Step 1: Start, Step 2: Declare variable: num,i,j,fact,sum=0, Step 3:Check for: (i=1;i<=n;i++), Step 4: In step 4, for fact=1 check: (i!=num), Step 5: If step 5 is true then print: (“%d!+”,i), Step 6: Else if step 5 is false then print: (“%d!=,i), Step 7: In step 4 check for: (j=1;j<=I;j++), Step 8: calculate: fact=fact*j, sum=sum+fact, Step 9: if conditions are satisfied then print: “sum: ”, Step 10: Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int num,i,j,fact,sum=0;, printf("Enter the last number of series:");, scanf("%d",&num);, for(i=1;i<=num;i++), {, fact=1;, if(i!=num), printf("%d!+",i);, else, printf("%d!=",i);, for(j=1;j<=i;j++), fact=fact*j;, sum=sum+fact;, }, printf("%d",sum:);, getch();, }, Input/ Output:, Enter the last number of series:8, 1!+2!+3!+4!+5!+6!+7!+8!=-19303, Ques.15: Write a program to find the sum of following series 1-X1/1!+X2/2!-……………Xn/n!., Ans.15: Algorithm:, Step 1: Start, Step 2: Declare variable : n,s=1,f=1,i,sign=1,x,j, Step 3: Print: "Enter number of terms", Step 4: Input the value of n, Step 5: Print: "Enter value of x ", Step 6: Input the value of x, Step 7: Check for: (i=1;i<=n;i++), Step 8: In step 4 check for: (j=1;j<=I;j++), Step 9: Calculate and initialize: f=(f*i), Step 10: End for of variable:j, Step 11: Calculate: sign=sing*(-1),s=s-sign*pow(x,i)/f at f=1, Step 12: Check is (s>=0), Step 13: In step 12 if condition is true then print "+%f",s), Step 14: Else print ("%f",s), Step 15: End for of variable: i, Step 16: Print: “Sum of series = s”, Step 13: Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, #include<math.h>, void main(), {, float n,s=1,f=1,i,sign=1,x,j;, printf("Enter number of terms");, scanf("%f",&n);, printf("Enter value of x");, scanf("%f",&x);, for(i=1;i<=n;i++), {, for(j=1;j<=i;j++), {, f=f*i;, }, sign=sign*(-1);, s=s-sign*pow(x,i)/f;, f=1;, if (s>=0), {, printf("+%f",s);, }, else, {, printf("%f",s);, }, }, printf("=%f is the sum of series",s);, getch();, }, Input /Output:, Enter number of terms: 5, Enter value of x: 4, 5 is a sum of series, Ques.16: Write a program to print the entire prime number between 1 and 300., Ans.16: Algorithm:, Step 1: Start, Step 2: Declare variable: num, count, i, prime;, Step 3: Print: “Prime Numbers from 1 to 300 are”, Step 4: Check for (num=1; num<=300; num++), Step 5: In step 4 sif (num==1), Step 6: If step 5 is true then print: "Number 1 is neither prime nor composite", Step 7: If step 5 is false then initialize: count=sqrt(num) prime=1;, Step 8: For (i=2;i<num;i++), Step 9: Check if num%i==0 and initialize: prime=0, Step 10: End for variable i, Step 11: Check if prime, Step12: If step 11 is true then print: “num”, Step 13: If step11 is false then goto step 6., Step 14: End for of variable num, Step 15: Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, #include<math.h>, void main(), {, int num,count,i,prime;, clrscr();, printf("Prime Numbers from 1 to 300 are\n");, for(num=1;num<=300;num++), {, if(num==1), {, printf("Number 1 is neither prime nor composite\n");, continue;, }, count=sqrt(num);, prime=1;, for(i=2;i<num;i++), {, if(num%i==0), {, prime=0;, break;, }, }, if(prime), {, printf("%d\t",num);, }, }, getch();, }, Input /Output:, Prime Numbers from 1 to 300 are, Number 1 is neither prime nor composite, 2 3 5 7 11 13 17 19 23 29, 31 37 41 43 47 53 59 61 67 71, 73 79 83 89 97 101 103 107 109 113, 127 131 137 139 149 151 157 163 167 173, 179 181 191 193 197 199 211 223 227 229, 233 239 241 251 257 263 269 271 277 281, 283 293, Ques.17: Write a program to print out all the Armstrong numbers between 100 and 500., Ans.17: Algorithm:, Step 1: Start, Step 2: Declare variable:n,r,sum,count=100, Step 3: Check while: (count<=500), Step 4: If Step 3 is true then calculate: n=count,sum=0, Step 5: Check while: (n), Step 6: If Step 5 is true then calculate and initialize: r=n%10; sum=sum+(r*r*r); n=n/10;, Step 7: Check if : (count==sum), Step 8: If Step 7 is true then print: " is an armstrong number", Step 9: Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int n,r,sum,count=100;, while(count<=500), {, n=count;, sum=0;, while(n), {, r=n%10;, sum=sum+(r*r*r);, n=n/10;, }, if(count==sum), {, printf("\n %d is an armstrong number",count);, }, count++;, }, getch();, }, Input/ output:, 153 is an armstrong number, 370 is an armstrong number, 371 is an armstrong number, 407 is an armstrong number, Ques.18: Write a program to draw the following figure:, (a): 3 2 1, 2 1, 1, (b): *, **, ***, Ans.18: (a): ALGORITHM:, Step 1: Start, Step 2: Declare variable: i,j,x, Step 3: Check for: (i=3;i>=1;i--), Step 4: Initialize: x=i, Step 5: In step 3 now check for : (j=1;j<=1;j++), Step 6: Print: “x”, Step 7: Initialize: x--, Step 8: End for of variable: j, Step 9: Print: “\n”, Step 10: End for of variable: i, Step 11: Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int i,j,x;, clrscr();, for(i=3;i>=1;i--), {, x=i;, for(j=1;j<=i;j++), {, printf("%d",x);, x--;, }, printf("\n");, }, getch();, }, Input/ output:, 321, 21, 1, (b): ALGORITHM:, Step 1: Start, Step 2: Declare variable : i,j, Step 3: Check for : (i=1;i<=3;i++), Step 4: In step 3 check for: (j=1;j<=1;j++), Step 5: Print: “*”, Step 6: End for of variable j, Step 7: Print: ”\n”, Step 8: End for of variable i, Step 9: Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int i,j;, clrscr();, for(i=1;i<=3;i++), {, for(j=1;j<=i;j++), {, printf("*");, }, printf("\n");, }, getch();, }, Input/ Output:, *, **, ***, Ques.19: Write a program to receive a five digit number and display as like 24689:, 2, 4, 6, 8, 9, Ans.19: ALGORITHM:, Step 1: Start, Step 2: Declare variable : i, num, Step 3: Print: "Input a five digit number:", Step 4: Input value in: num, Step 5: For(i=4;num>0;i--), Step 6: Print: "the result": num/(int)pow(10,i), Step 7: Calculate: num=num%(int)pow(10,i), Step 8: Print: "\n", Step 9: End for, Step 10: Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, #include<math.h>, void main(), {, int num,i;, printf("Input a five digit number:");, scanf("%d",& num);, for(i=4;num>0;i--), {, printf("%d",num/(int)pow(10,i));, num=num%(int)pow(10,i);, printf("\n");, }, getch();, }, Input/ output:, Input a five digit number:24689, 2, 4, 6, 8, 9, Ques.20: Write a function that return sum of all odd digits of a given positive no. entered through keyboard., Ans.20: ALGORITHM:, Step 1: Start, Step 2: Declare variable : n,k, Step 3: Print: "Inter number:", Step 4: Input value in: n, Step 5: Initialize: k=sumodddigit(n), Step 6: Print: " sum of odd digits of a positive number\n", Step 7: Stop, Step 8: Start function sum, Step 9: Declare variable: num,rem,s=0, Step 10: Is num!=0 then, Calculate: rem=num%10, Step 11: Is rem%2!=0 then , Calculate: s=s+rem, Step 12: Calculate: num=num/10, Step 13: return s, Step 14:Stop , Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, int sumodddigit (int);//prototype of function, void main(), {, int n, k;, clrscr();, printf("Enter Number: ");, scanf("%d",&n);, //calling function, k=sumodddigit(n);, printf("%d is sum of odd digits of a positive number\n",k);, getch();, }, //function definition, int sumodddigit(int num), {, int rem, s=0;, while(num!=0), {, rem= num%10;, if (rem%2!=0), {, s=s+rem;, }, num=num/10;, }, return s;, }, Input/ output:, Enter Number: 3452, 8 is sum of odd digits of a positive number, Ques.21: Write a program to print area of rectangle using function & return its value to main function, Ans.21: ALGORITHM:, Step 1: Start, Step 2: Declare variable : length,breadth,Area, Step 3: Print: " Enter length and breadth of rectangle: ”, Step 4: Input value in: length & breadth, Step 5: Calculate and Initialize: Area = area(length, breadth), Step 6: Print: “the area of rectangle= area", Step 7: Stop, Step 8: Start function sum, Step 9: Declare variable: x,l,b, Step 10: Calculate and initialize: x=l*b, Stop11: return z, Stop12: Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, #include<math.h>, int area (int l, int b);, void main(), {, int length,breadth,Area;, clrscr();, printf("Enter length and breadth of rectangle:\n");, scanf("%d%d",& length, & breadth);, // calling of function, Area = area(length, breadth);, printf("%d is the area of rectangle", Area);, getch();, }, int area(int l, int b), {, int x;, x=l*b;, return x;, }, Input/ output:, Enter length and breadth of rectangle:, 11, 12, 132 is the area of rectangle, Ques.22: Write a program to calculate the factorial for given number using function., Ans.22: ALGORITHM:, Step 1: Start, Step 2: Declare variable : num,, Step 3: Print: " Enter a number: ”, Step 4: Input value in: num, Step 5: Calculate and Initialize: factorial=fact(num), Step 6: Print: “the factorial of given number ", Step 7: Stop, Step 8: Start function sum, Step 9: Declare variable: x,i,f=1, Step 10: for (i=1;i<=x;i++), Step 11: Calculate and initialize: f=f*i, Stop12: return f, Stop13 Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, int fact(int);, void main(), {, int num, factorial;, clrscr();, printf("\n Enter a number:");, scanf("%d",& num);, factorial=fact(num);, printf("the factorial of given number=%d",factorial);, getch();, }, Int fact(int x), {, int i,f=1;, for (i=1;i<=x;i++), {, f=f*i;, }, return f;, }, Input/ output:, Enter a number:6, the factorial of given number= 720, Ques.23: Write a program to find sum of Fibonacci series using function., Ans.23: ALGORITHM:, Step 1: start, Step 2: Declare variable,n,i,sum=0, Step 3: Print ''Enter number terms '', Step 4: Input value in :n, Step 5: For ( i=l; i<=n; i++), Step 6: calculate and Initialize sum=sum + fib (i), Step 7: End for loop, Step 8: Print "Sum of the series" =sum, Step 9: stop, Step 10: start function, Fibonacci series, Step 11: Declare variable n, Step 12: if (n==1)(n==2), Step 13: Return 1, Step 14: Return fib (n -1)+ fib (n- 2 ), Step 15: stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, int fib(int);, void main(), {, int n,i,sum=0;, printf("\n Enter number of terms:");, scanf("%d",&n);, for(i=1;i<=n;i++), {, sum = sum+fib(i);, }, printf("\n Sum of the series is = %d",sum);, getch();, }, int fib(int n), {, if(n==1||n==2), return 1;, return(fib(n-1)+fib(n-2));, }, Input/ output:, Input number of terms: 10, Sum of Fibonacci Series is= 88, Ques.24: Write factorial function & use the function to find the sum of series S=1!+2!+-----n!., Ans.24: ALGORITHM:, Step 1: start, Step 2: Declare variable,n,i,sum=0, Step 3: Print ''Enter value of n:", Step 4: Input value in :n, Step 5: For ( i=1; i<=n; i++), Step 6: Calculate and Initialize sum = sum + factorial(i), Step 7: End for loop, Step 8: Print: ("sum of series(s=1!+2!+3!....+%d!) : %d",n,sum), Step 9: stop, Step 10: start function, Fibonacci series, Step 11: Declare variable num, fact=1,i, Step 12: For ( i=1; i<=num; i++), Step 13: Calculate and Initialize: fact = fact*i, Step 14: End for loop, Step 14: Return fact, Step 15: stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, int factorial(int);, void main(), {, int n;, int sum=0;, int i;, printf("\n Enter value of n:");, scanf("%d",&n);, for(i=1;i<=n;i++), sum = sum + factorial(i);, printf("sum of series(s=1!+2!+3!....+%d!) : %d",n,sum);, getch();, }, int factorial(int num), {, int fact=1;, int i;, for(i=1;i<=num;i++), {, fact = fact*i;, }, return fact;, }, Input/ output:, Inter value of n: 5, Sum of Series (s = 1! + 2! … + 5!): 153, Ques.25: Write a program to find the factorial of given number using recursion., Ans.25: ALGORITHM:, Step1. Start, Step2. Declare variable: n, factorial, Step3. Print: "Enter value of n", Step4. Input value in:n, Step5. Calculate and initialize: factorial=fact(n), Step6. Print: "factorial of %d is =%d”,n, factorial, Step7. Stop, Step8. Start function, Step9. Declare variable: x, Step10. Is (x==0)?, Step11. return 1, Step12. Calculate and Initialize: return(x*fact(x-1)), Step13. Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, int fact(int);, void main(), {, int n,factorial;, printf("\n Enter value of n:");, scanf("%d",&n);, factorial = fact(n);, printf("\n Factorial of %d is = %d",n,factorial);, getch();, }, int fact(int x), {, if(x==0), return(1);, return(x*fact(x-1));, }, Input/ output:, Enter value of n: 7, Factorial of 7 is= 5040, Ques.26: Write a program to find the sum of digits of a 5 digit number using recursion., Ans.26: ALGORITHM:, Step 1:Start, Step 2: Declare variable: n, result, Step 3: Print "Enter the five digit number ", Step 4: Input value in :n, Step 5: calculate and Initialize: result = sum (n), Step 6: Print: "Sum of five digit number", Step 7: stop, Step 8: start function, Step 9: if x is not equal to zero, Step 10: then return (x% 10+ sum (x/10)), Step 11: Otherwise, return zero, Step 12: stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, int sum(int);, void main(), {, int n,result;, printf("\n Enter the five digit number:");, scanf("%d",&n);, result = sum(n);, printf("\n Sum of the five digit number in %d = %d",n,result);, getch();, }, int sum(int x), {, if(x!=0), {, return(x%10+sum(x/10));, }, else, {, return 0;, }, }, Input/ output:, Enter the five digit number: 12345, Sum of the five digit number in 12345: 15, Ques.27: Write a program to calculate the GCD of given numbers using recursion., Ans.27: ALGORITHM:, Step 1: start, Step 2: Declare variable n1,n2, Step 3: Print: "Enter two postive integer", Step 4: input value in n1,n2, Step 5: Print : "GCD of the %d &%d", Step 6: stop, Step 7: start function, Step 8: if n2 not equal to zero, Step 9: then return hcf ( n2,n1/n2), Step 10: Otherwise return n1, Step 11: stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, int hcf(int,int);, void main(), {, int n1,n2;, printf("\n Enter two posiitive integers:");, scanf("%d%d",&n1,&n2);, printf("GCD of the %d and %d = %d",n1,n2,hcf(n1,n2));, getch();, }, int hcf(int n1,int n2), {, if(n2!=0), return hcf(n2,n1%n2);, else, return n1;, }, Input/ output:, Enter two posiitive integers: 657,894, GCD of the 657 and 894 = 3, Ques.28: Write a program to convert decimal number in to binary number., Ans.28: ALGORITHM:, Step1. Start, Step2. Declare variable: a[10], n, i,j, Step3. Print: "Enter any no", Step4. Input value in:n, Step5. For (i=0;n>0;i++), Step6. Calculate and initialize: a[i]=n%2,n=n/2, Step7. End for loop, Step8. Print: "Binary no", Step9. For (j=1;j>=0;j---), Step10. Print : " %d", a[j], Step11. End for loop, Step12. Print: "\n", Step13. Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int a[10],n,i,j;, printf("\n Enter any number:");, scanf("%d",&n);, for(i=0;n>0;i++), {, a[i]=n%2;, n=n/2;, }, printf("\n Binary number:");, for(j=i-1;j>=0;j--), {, printf("%d",a[j]);, }, printf("\n");, getch();, }, Input/ output:, Enter any number:29, Binary number:11101, Ques. 29: Write a program to convert binary number in to decimal number., Ans.29: ALGORITHM:, Step1. Start, Step2. Declare variable: num, binary, decimal=0, base=1, rem, Step3. Print: "Enter any binary number", Step4. Input value in:num, Step5. Calculate and initialize: binary= num, Step6. Is num>0, Step7. Calculate and initialize: rem=num%10 ;d ecimal=decimal + rem ; num=num/10; base=base*2, Step8. Print:"the decimal no.", Step9. Stop, Flowchart:, Program:, #include<stdio.h>, #include<conio.h>, void main(), {, int num,binary,decimal=0,base=1,rem;, printf("Enter any binary number:\n");, scanf("%d",&num);, binary=num;, while(num>0), {, rem=num%10;, decimal=decimal+rem;, num=num/10;, base=base*2;, }, printf("The decimal number is %d\t",decimal);, getch();, }, Input/ output:, Enter any binary number: 10110, The decimal number is 22, Ques.30: Write program to sort the array of character (String) in alphabetical order like STRING in GINRST., Ans.30: ALGORITHM:, Step 1: Start, Step 2: Declare variable: s{50} ,temp,i,j, Step 3: Print: "Enter a string", Step 4: Input value in: S, Step 5: Initialize: Int len =strlen(s), Step 6: for (i= 0,i<(len -1),i ++), Step 7: for (j=i+1,j<len ,j++), Step 8 : Is s{i}>s{j}, Step 9: Calculate and Initialize: temp=s{i}; s{i} =s{j}; s{j}= temp, Step 10: End for loop, Step 11: End for loop, Step 12: Print: " New string after sorting ", Step 13: Stop, Flowchart:, Program:, #include<conio.h>, #include<string.h>, void main(), {, char s[50],temp;, int i,j;, printf("Enter a string:");, scanf("%s",&s);, int len = strlen(s);, for(i=0;i<(len-1);i++), {, for(j=(i+1);j<len;j++), {, if(s[i]>s[j]), {, temp=s[i];, s[i]=s[j];, s[j]=temp;, }, }, }, printf("New string after sorting %s",s);, getch();, }, Input/ output:, Enter String: DIGITALG1, New string after sorting: 1ADGGIILT