//wap to display the fibonacci series up to nth term. #include int main() { int n, i, a = 0, b = 1, c; printf("enter num upto which u want the series to continue: "); scanf("%d", &n); printf("fibonacci Series up to %d terms is: \n", n); printf("%d %d ", a, b); for (i = 3; i <= n; i++) { c = a + b; printf("%d ", c); a = b; b = c; } return 0; } //QN5. #include #include int main(){ int cost, sum,unit,charge; printf("enter unit of electricity"); scanf("%d",&unit); if(unit>=0&&unit<=20){ charge=unit*4; cost=charge+50; } else if(unit>=21&&unit<=30){ charge=unit*7; cost=charge+75; } else if(unit>=31&&unit<=50){ charge=unit*8.5; cost=charge+100; } else if(unit>=51&&unit<=150){ charge=unit*10; cost=charge+125; } else if(unit>=151){ charge=unit*11; cost=charge+150; } else{ printf("Invalid Unit"); } printf("Your total cost is %d",cost); } //QN6. wap to find all roots of quadratic equation #include #include int main() { int a, b, c, root; printf("Enter the value of a,b,c after comparing with the quadratic equation (ax^2 + bx + c): "); scanf("%d%d%d", &a, &b, &c); int disc = pow(b, 2) - 4 * a * c; if (disc > 0) { root = (-b + sqrt(disc)) / (2 * a); printf("The roots are %d and %d\n", root, root); } else if (disc < 0) { root = -b / (2 * a); printf("The roots are %di and %di\n", root, root); } else { root = -b / (2 * a); printf("The root is %d\n", root); } return 0; } //QN7. #include #include int main() { int purchaseamt,cost,discount; printf("enter purchase amount"); scanf("%d",&purchaseamt); if(purchaseamt>=10000){ cost=purchaseamt-(0.2*purchaseamt); } if(purchaseamt>=5000&&purchaseamt<10000){ cost=purchaseamt-(0.1*purchaseamt); } if(purchaseamt<5000){ cost=purchaseamt-(0.03*purchaseamt); } printf("Your cost after discount is %d",cost); return 0; } //QN10. WAP to display all those palindrome numbers from 1 to 100 and count the displayed numbers. #include int main() { int num, rem, reverse_num, temp, start, end, count = 0; printf("Enter the lower limit: "); scanf("%d", &start); printf("Enter the upper limit: "); scanf("%d", &end); printf("Palindrome numbers between %d and %d are: ", start, end); for (num = start; num <= end; num++) { temp = num; reverse_num = 0; while (temp) { rem = temp % 10; temp = temp / 10; reverse_num = reverse_num * 10 + rem; } if (num == reverse_num) { printf("%d ", num); count++; } } printf("\nTotal palindrome numbers found: %d", count); return 0; } //QN11.wap to check leap year. #include int main() { int year; printf("Enter a year: "); scanf("%d", &year); if (year % 400 == 0) { printf("%d is a leap year.", year); } else if (year % 100 == 0) { printf("%d is not a leap year.", year); } else if (year % 4 == 0) { printf("%d is a leap year.", year); } else { printf("%d is not a leap year.", year); } return 0; } //QN12.write a menu driven program having following menu: //a. multiplication table //b.positive or negative number //c.exit //Note: Repeat the program till user wants. #include int main() { int num, i, choice; do { printf("\nMenu:\n"); printf("1. Multiplication table\n"); printf("2. Check positive or negative number\n"); printf("3. Exit\n"); printf("Enter your choice: "); scanf("%d", &choice); switch (choice) { case 1: { printf("Enter a number to find its multiplication table: "); scanf("%d", &num); for (i = 1; i <= 10; i++) { printf("%d x %d = %d\n", num, i, num * i); } break; } case 2: { printf("Enter a number to check if it's positive or negative: "); scanf("%d", &num); if (num < 0) { printf("It's negative.\n"); } else if (num > 0) { printf("It's positive.\n"); } else { printf("It's zero.\n"); } break; } case 3: { printf("Exiting the program.\n"); break; } default: { printf("Invalid choice! Please enter a valid option.\n"); } } } while (choice != 3); return 0; }