PPS LAB

Program to find sum of elements of an array

Program #include <stdio.h> int main() { printf(“**************************************************************”); printf(“\n**************************************************************”); printf(“\n** WAP to find sum of elements of an array **”); printf(“\n** Created by Sheetal Garg **”); printf(“\n** Assistant Professor **”); printf(“\n** Phone No:9467863365 **”); printf(“\n**************************************************************”); printf(“\n**************************************************************\n”); int n,i,a[5],sum=0; printf(“Enter no. of elements in the array\n”); scanf(“%d”,&n); printf(“enter array elements”); for(i=0;i<n;i++) scanf(“%d”,&a[i]); for(i=0; i<n; i++) sum=sum + …

Program to find sum of elements of an array Read More »

Program to enter and display elements of an array

Program #include <stdio.h> int main() { printf(“**************************************************************”); printf(“\n**************************************************************”); printf(“\n** WAP to enter and display an array **”); printf(“\n** Created by Sheetal Garg **”); printf(“\n** Assistant Professor **”); printf(“\n** Phone No:9467863365 **”); printf(“\n**************************************************************”); printf(“\n**************************************************************\n”); int n,i,a[5]; printf(“Enter no. of elements in the array\n”); scanf(“%d”,&n); printf(“enter array elements”); for(i=0;i<n;i++) scanf(“%d”,&a[i]); printf(“\nThe array elements are\n”); for(i=0; i<n; i++) …

Program to enter and display elements of an array Read More »

Program to check a number for prime in C

Logic: Algorithm Time Complexity: O(n) Space Complexity: O(1) Program to check a number for Prime (Without Function) #include <stdio.h> int main() { printf(“****************************************************************”); printf(“\n****************************************************************”); printf(“\n** WAP to check a number for prime **”); printf(“\n** Created by Sheetal Garg **”); printf(“\n** Assistant Professor **”); printf(“\n** Phone No:9467863365 **”); printf(“\n****************************************************************”); printf(“\n****************************************************************\n”); int n,i; printf(“enter number”); scanf(“%d”,&n); for(i=2;i<=n-1;i++) …

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

Program to find reverse of a number in C

Logic: Enter the number n example n=345 Reverse=543 Algorithm Enter the number as n Initially assign rev=0 while(n>0) { r=n%10; rev = rev * 10 + r; n=n/10; } Print rev Program #include<stdio.h> int main() { printf(“***************************************************************”); printf(“\n***************************************************************”); printf(“\n** WAP to find reverse of a number *”); printf(“\n** Created by Sheetal Garg **”); printf(“\n** Assistant …

Program to find reverse of a number in C Read More »

Program to find sum of cubes of first n natural numbers using for loop

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 Program #include<stdio.h> void main() { printf(“***************************************************************”); printf(“\n****************************************************************”); printf(“\n** WAP to print sum of cubes of first n natural numbers **”); printf(“\n** Created by Sheetal …

Program to find sum of cubes of first n natural numbers using for loop Read More »

Program to find sum of squares of first n natural numbers using for loop

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 Program #include<stdio.h> void main() { printf(“**************************************************************”); printf(“\n**************************************************************”); printf(“\n** WAP to print sum of squares of first n natural numbers **”); printf(“\n** Created by Sheetal Garg …

Program to find sum of squares of first n natural numbers using for loop Read More »

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