User:Lakshyatyagi

Area Aim: - Write a Program to count number of digits in an integer. Algorithm: - Step 1: - Start. Step 2: - Declare the variable choice, a, area, l, b, h, and r. Step 3: - Take input of choice. Step 4: - Work on input using switch. Step 5: - Case 1: - Taking input of side of square. Area=side*side. Print area. Case 2: - Taking input of side of rectangle. Area=Length*Breadth. Print area. Case 3: - Taking input of side of side of triangle. Area=height*base/2. Print area. Case 4: - Taking input of radius of circle. Area=3.141*radius*radius. Print area. Step 6: - Stop Program Code main {clrscr; int choice; float a, area, l, b, h, r; printf("\n\t\t\t Program to find an area\n"); printf("\n 1. Square"); printf("\n 2. Rectangle"); printf("\n 3. Triangle"); printf("\n 4. Circle"); printf("\n Enter your choice: "); scanf("%d", &choice); switch(choice) {case 1: printf("\n Enter the side of square: "); scanf("%f", &a); area=a*a; printf("\n Area of square is: %f", area); break; case 2: printf("\n Enter the length of rectangle: "); scanf("%f", &l); printf("\n Enter the breadth of rectangle: "); scanf("%f", &b); area=l*b; printf("\n Area of rectangle is: %f", area); break; case 3: printf("\n Enter the base length of triangle: "); scanf("%f", &b); printf("\n Enter the height of triangle: "); scanf("%f", &h); area=b*h/2; printf("\n Area of triangle is: %f", area); break; case 4: printf("\n Enter the radius of circle: "); scanf("%f", &r); area=3.141*r*r; printf("\n Area of Circle is: %f", area); break; default: printf("\n Enter only 1, 2, 3 or 4"); break; } getch; return 0; } Output Sample Input and Output Case 1: - Enter the side of square = 4 Area of Square = 16.000 Case 2: - Enter the Length of Rectangle = 3 Enter the Breadth of Rectangle = 4 Area of Rectangle = 12.000 Case 3: - Enter the Base of Triangle = 5 Enter the Height of Triangle = 4 Area of Triangle = 10.000 Case 4: - Enter the Radius of Circle = 6 Area of Circle = 113.075996 Case 5: - Enter only 1, 2, 3 or 4.
 * 1) include
 * 2) include

Result: - Find the area by using c programming. Sum of 10 positive input integer Aim: - Write a program to calculate sum of 10 input integers (skip negative numbers). Algorithm: - Step 1: - Start. Step 2: - I, a=0, b. Step 3: - Take the input of 10 integers using for loop. Step 4: - Add only positive integers using if (input≥0). Step 5: - Print the sum of all positive input integer. Step 6: - Stop. Program Code: - main {clrscr; int i; float a=0, b; printf("\n Enter any 10 integer: "); for(i=0; i<10; i++) {scanf("%f", &b); if(b>=0) a=a+b; } printf("\n After adding all positive integer: %f", a); getch; return 0; } Output: - Sample Input and Output Enter any 10 integer: - 4 -03 0 56 -09 09 32 -23 -6 12 After adding all positive integer: 113.0000
 * 1) include
 * 2) include

Result: - Add all positive integer by using c programming. Factorial Aim: - Write a program to find a factorial of a given number. Algorithm: - Step 1: - Start Step 2: - Declare the variable fact=1, i, a. Step 3: - Take the input of number to find factorial. Step 4: - Calculate factorial using while (a>0) Step 5: - fact=fact*a. Step 6: - Print the factorial of that number. Step 7: - Stop. Program code: - main {clrscr; int fact=1, i, a; printf("\n Enter any number: "); scanf("%d", &a); while(a>0) {fact=fact*a; a--; } printf("\n Factorial of number is: %d", fact); getch; return 0; } Output: - Sample Input and Output Enter any number: - 5 Factorial of number is 120
 * 1) include
 * 2) include

Result: - Calculate factorial of entered number using c programming. LCM and Hcf Aim: - Write a program to find the factorial of a given number. Algorithm: - Step 1: - Start. Step 2: - Declare the variable a, b, lcm, rem, num, den, and hcf. Step 3: - Take input of two numbers. Step 4: - if first number is greater than second number. Step 5: - numerator is first number and denominator is second number. Step 6: - else numerator is second number and denominator is first number. Step 7: - reminder = numerator%denominator. Step 8: - While reminder not equals to 0. Step 9: - numerator is equals to denominator. Step 10: - denominator is equals to reminder. Step 11: - reminder=numerator%denominator. Step 12: - hcf is denominator. Step 13: - lcm is first numberXsecond number%hcf. Step 14: - Print lcm and hcf. Step 15: - Stop Program Code: - main {clrscr; int a, b, lcm, rem, num, den, hcf; printf("\n Enter two number: "); scanf("%d %d", &a, &b); if(a>b) {num=a; den=b; } else {num=b; den=a; } rem=num%den; while(rem!=0) {num=den; den=rem; rem=num%den; } hcf=den; lcm=a*b/hcf; printf("\n LCM is: %d", lcm); printf("\n HCF is: %d", hcf); getch; return 0;} Output: - Sample Input and Output: - Enter any two number: - 15 16 Lcm is 60 And hcf is 5
 * 1) include
 * 2) include

Result: - Calculate lcm and hcf using c programming. Fibonacci series Aim: - Write a program to find the Fibonacci series for a limit. Algorithm: - Step 1: - Start. Step 2: - Declare the variable a, n, b, fib=0. Step 3: - Take input of two number. Step 4: - Take input of number of Fibonacci series. Step 5: - use for loop at the total number-2. Step 6: - Fibonacci is equals to first+second number. Step 7: - first number is equals to second number. Step 8: - second number is equals to last number. Step 9: - Print the Fibonacci series. Step 10: - Stop.

Program code: - main {clrscr; int a, n, b, fib=0; printf("\n Enter any two number: "); scanf("%d %d", &a, &b); printf("\n Enter the numbers you want in Fibonacci series: "); scanf("%d", &n); printf("\n Fibonacci series is: %d %d", a, b); for(int i=0; i<(n-2); i++) {fib=a+b; a=b; b=fib; printf(" %d", fib); } getch; return 0; } Output: - Sample Input and Output: - Enter any two number: - 2 4 Enter the number you want in Fibonacci series: - 9 Fibonacci series is: - 2 4 6 10 16 26 42 68 110
 * 1) include
 * 2) include

Result: - Print the Fibonacci series using c programming. Reverse the digit Aim: - Write a program to reverse the digits of a number. Algorithm: - Step 1: - Start. Step 2: - Declare the variable i, a. Step 3: - Take a input of any number. Step 4: - use while(i>0) Step 5: - a=i%10. Step 6: - i=i/10. Step 7: - print the number come. Step 8: - Stop. Program code: - main {clrscr; int i, a; printf("\n Enter any number: "); scanf("%d", &i); printf("\n After reversing the number is: "); while(i>0) {a=i%10; i=i/10; printf("%d", a); } getch; return 0; } Output: - Sample of Input and Output: - Enter any number: - 3214 After reversing the number is: - 4123
 * 1) include
 * 2) include

Result: - Reversing the digits of a given integer using c programming. Table of 2 Aim: - Write a program to print multiplication table of 2 from 1 to 10 using while loop. Algorithm: - Step 1: - Start. Step 2: - Declare the variable i, res. Step 3: - use for loop to the 10. Step 4: - res=2*i. Step 5: - print the table of 2. Step 6: - Stop. Program Code: - main {clrscr; int i, res; printf("\n\t\t\t Table of 2"); for(i=1; i<=10; i++) {res=2*i; printf("\n 2 x %d = %d", i, res); } getch; return 0; } Output: - Sample of Input and Output: - 2X1=2 2X2=4 2X3=6 2X4=8 2X5=10 2X6=12 2X7=14 2X8=16 2X9=18 2X10=20
 * 1) include
 * 2) include

Result: - Multiplication table of 2. Sales Detail Aim: - Program to display sales details with menu using do while loop. Algorithm: - Step 1: - Start. Step 2: - Declare the variable a, ch. Step 3: - Take an input of choice of user. Step 4: - if (choice==1) print the detail soap. Step 5: - Ask for continue. Step 6: - if (choice==2) print the detail of Shampoo. Step 7: - Ask for continue. Step 8: - if (choice==3) print the detail of face wash. Step 9: - Ask for continue. Step 10: - else enter only 1, 2 or 3. Step 11: - Stop. Program code: - main {again: clrscr; int a; char ch; printf("\n Menu\n"); printf("\n 1. Soap"); printf("\n 2. Shampoo"); printf("\n 3. Face Wash"); printf("\n Enter your choice: "); scanf("%d", &a); if(a==1) {printf("\n Soap"); printf("\n Company	: Cinthol"); printf("\n Price	: Rs. 100"); printf("\n Do you want to continue(y/n): "); scanf("%s", &ch); if(ch=='y' || ch=='Y') goto again; } else if(a==2) {printf("\n Shampoo"); printf("\n Company	: Wella Pro Enrich"); printf("\n Price	: Rs. 1050"); printf("\n Do you want to continue(y/n): "); scanf("%s", &ch); if(ch=='y'||ch=='Y') goto again; } else if(a==3) {printf("\n Face Wash"); printf("\n Company	: Himalaya Intense Lemon Face Wash"); printf("\n Price	: Rs. 114"); printf("\n Do you want to continue(y/n): "); scanf("%s", &ch); if(ch=='y'||ch=='Y') goto again; } else {printf("\n Enter only 1, 2 or 3"); } getch; return 0; } Output: -
 * 1) include
 * 2) include

Sample Input and Output: - Menu 1.	Soap 2.	Shampoo 3.	Face Wash Enter your choice: - 1 Soap Company: - Cinthol Price: - Rs. 100 Do you want to continue: - n

Result: - Display the sales details by using c programming.