Practical Projects Questions (12)
- WAP to input two number and display its sum using function.
#include <stdio.h>#include<conio.h>int add(int , int);void main(){int num1, num2, sum;printf("Enter the first number: ");scanf("%d", &num1)printf("Enter the second number: ");scanf("%d", &num2);sum = add(num1, num2);printf("The sum of %d and %d is %d\n", num1, num2, sum);getch();}int add(int a, int b){return a + b;}
- WAP to check whether the entered number is odd or even using function
#include <stdio.h>#include <conio.h>char checkEvenOdd(int);void main(){int num;printf("Enter an integer number: ");scanf("%d", &num);char result = checkEvenOdd(num);if(result == 'E'){printf("%d is even.", num);}else{printf("%d is odd.", num);}getch();}char checkEvenOdd(int num){if(num % 2 == 0){return 'E';}else{return 'O';}}
Another Method
#include <stdio.h>#include <conio.h>const char *checkEvenOdd(int);void main(){int num;printf("Enter an integer number: ");scanf("%d", &num);const char* result = checkEvenOdd(num);printf("%d is %s.", num, result);getch();}const char* checkEvenOdd(int num){if(num % 2 == 0){return "Even";}else{return "Odd";}}
- WAP to print the greatest number among three numbers using function.
#include <stdio.h>#include <conio.h>int findMax(int, int, int);void main(){int num1, num2, num3;printf("Enter three numbers: ");scanf("%d %d %d", &num1, &num2, &num3);int max = findMax(num1, num2, num3);printf("The maximum of %d, %d and %d is %d.", num1, num2, num3, max)getch();}int findMax(int num1, int num2, int num3){int max = num1;if(num2 > max){max = num2;}if(num3 > max){max = num3;}return max;}
- WAP to calculate the cumulative sum of natural number up to n using function.
#include <stdio.h>#include <conio.h>int sum(int);void main() {int n;printf("Enter a positive integer: ");scanf("%d", &n);int result = sum(n);printf("The sum of natural numbers up to %d is %d.\n", n, result);getch();}int sum(int n) {int s = 0;for (int i = 1; i <= n; i++) {s += i;}return s;}
- WAP to calculate the factorial of ‘n’ number using function.
#include <stdio.h>#include <conio.h>int factorial(int);void main() {int n;printf("Enter a non-negative integer: ");scanf("%d", &n);if (n < 0) {printf("Error: factorial is not defined for negative numbers.\n");} else {int result = factorial(n);printf("%d! = %d\n", n, result);}getch();}int factorial(int n) {if (n == 0 || n == 1) {return 1;} else {return n * factorial(n-1);}}
- WAP to display the Fibonacci series of ‘n’ number using function.
#include <stdio.h>#include <conio.h>void fibonacci(int);void main() {int n;printf("Enter a positive integer: ");scanf("%d", &n);if (n < 1) {printf("Error: invalid input.\n");} else {fibonacci(n);}getch();}void fibonacci(int n) {int first = 0, second = 1, next;printf("Fibonacci series up to %d: %d, %d", n, first, second);for (int i = 3; i <= n; i++) {next = first + second;printf(", %d", next);first = second;second = next;}printf("\n");}
- WAP to calculate the factorial of ‘n’ number using recursive function.
- WAP to display the 10th term of Fibonacci series using function.
- WAP to display the Fibonacci series up to ‘n’ number using recursive function.
- WAP to check whether the number is prime or composite using function.
- WAP to input the name, class, roll no and section of 20 students using structure.
- WAP to input employee name, position, salary and id of ‘n’ employee using structure.
- WAP to input name, position, employee id and salary of ‘n’ employee using array of structure.
- WAP to input name and marks of ‘n’ students using structure and sort them in descending order with respect to their marks and display them.
- WAP to input name and marks of 220 students using structure and sort them in alphabetical order with respect to their name and display them.
- WAP to read two number and add them using pointer.
- WAP to input two numbers and swap the two number using call by reference method.
- WAP to create data file name student.txt and write name, roll no, section and marks of a student to this file and display the contents of the data file.
- WAP to write and read a name, employee id and salary of the ‘n’ employees from to data file using structure.
- WAP to write and read a name, employee id and salary of the employees from to data file using structure also continue ‘y’ to input the record as long as the user press.
- WAP to append the name and marks of a 10 students to a student.txt file and display all the records.
- WAP to demonstrate to remove and rename functions.
- WAP to store name and roll no of ‘n’ number of students using structure. Ask roll no from a user to delete that record and display it in proper format.
- WAP in JavaScript to calculate factorial of a number using function.
- WAP in JavaScript to calculate the area of rectangle using function.
- WAP in JavaScript using any four event handling objects.
- WAP in JavaScript using switch case statement to calculate the area of rectangle, area of circle, area of cube.
- WAP to connect database/MySQL using PHP.
Comments
Post a Comment