DAA LAB

Program to check a number for prime in C using function

Logic: Algorithm Time Complexity: O(n) Space Complexity: O(1) Program #include <stdio.h> char check_prime(int n); int main() { printf(“******************************************************\n”); printf(“******************************************************\n”); printf(“** WAP to check a number for prime using function **\n”); printf(“** Created by Sheetal Garg **\n”); printf(“** Assistant Professor **\n”); printf(“** Phone No:9467863365 **\n”); printf(“******************************************************\n”); printf(“******************************************************\n”); int n; char result; printf(“\nenter number\n”); scanf(“%d”, &n); result …

Program to check a number for prime in C using function Read More »

Program to print factorial/product of first n natural numbers using Function

Logic: Enter the number n Product or Factorial= 1 x 2x 3 x 4 x………x n Algorithm Enter the number as n Initially assign product=1 for(i=1;i<=n;i++) product= product Time Complexity: O(n) Space Complexity: O(1) Program #include <stdio.h> int fact(int n); int main() { printf(“****************************************************************\n”); printf(“****************************************************************\n”); printf(“** WAP to print factorial of a number n using …

Program to print factorial/product of first n natural numbers using Function Read More »

Program to print sum of cubes of first n natural numbers using Function

Logic: Enter the number n sum= 13 + 23+ 33 + 43+……..+n3 Algorithm Enter the number as n Initially assign sum=0 for(i=1;i<=n;i++) sum=sum + i * i * i; Print sum Time Complexity: O(n) Space Complexity: O(1) Program #include <stdio.h> int findsum(int n); int main() { printf(“****************************************************************\n”); printf(“****************************************************************\n”); printf(“** WAP to print sum of cubes …

Program to print sum of cubes of first n natural numbers using Function Read More »

Program to print sum of squares of first n natural numbers using Function

Logic: Enter the number n sum= 12 + 22+ 32 + 4 2+……..+n2 Algorithm Enter the number as n Initially assign sum=0 for(i=1;i<=n;i++) sum=sum + i * i; Print sum Time Complexity: O(n) Space Complexity: O(1) Program #include <stdio.h> int findsum(int n); int main() { printf(“****************************************************************\n”); printf(“****************************************************************\n”); printf(“** WAP to print sum of squares of …

Program to print sum of squares of first n natural numbers using Function Read More »

Program to print sum of first n natural numbers using Function

Logic: Enter the number n sum= 1 + 2+ 3 + 4 +……..+n Algorithm Enter the number as n Initially assign sum=0 for(i=1;i<=n;i++) sum=sum+i; Print sum Time Complexity: O(n) Space Complexity: O(1) Program #include <stdio.h> int findsum(int n); int main() { printf(“****************************************************************\n”); printf(“****************************************************************\n”); printf(“** WAP to print sum of first n natural numbers using function …

Program to print sum of first n natural numbers using Function Read More »

error: You can only copy the programs code and output from this website. You are not allowed to copy anything else.