C/C++


Sample Programs for Lab Record of MCA

 
1. To check whether a given number is a perfect factorial or Not
2. Write a program to convert from binary to decimal and vice versa
3. Write a program to convert binary to hexa
4. HCF and LCM
5. To Print Fibnocci series using Recursion
6. Matrix Multiplication
7. Check the given matrix is symetric or Not
8. Check whether given string or digits is palindrom or not
9. To Display the prime number within a range use a function that returns 1 if the number is prime, otherwiese 0
10. To check the given number is amstrong or not
11. Deletion of Substring
12. String operation using switch statement
13. To find the largest and smallest among a set of numbers stored in an array. Display the set of numbers along with the smallest and larges
14. To delete the duplicate numbers from a set of numbers stored in array. Display the set of numbers before and after deletion
15. To count and display the number of vowels, constants, digists, upper, lower and special charecters in a string
16. Prepare Student marklist using structure
17. Swap two values using call by Reference
18. Create a biodata using file
19. Using command line argument, write a program to copy the content of one file into another.
20.To Create a “display” command that is equivalent to the type command of the DOS-name of the file being a command line argument


 Sample Programs for Lab Record of MSc CS

 
1. To display first n prime numbers
2. To Display the sum of individual digits of a given number (4 Digits), and check the given number is palidrame or not
3. check the given string is palindrome or not
4. Convert from decimal to binary and vice versa
5. To display the first n fibnocci seires
6. To check whether a given number is palidrom or not
7. HCF and LCM of a given number
8. Factorial of a number by using recursion
9. Matrix addition
10. Matrix Multiplication
11. To find the largest odd and even number from a sort of numbers stored in an array
12. Swap two values using call by Reference and Call by value
13. String manipulation using Switch case
14. Deletion of a substring
15. Student Record creation using structure
16. Count number of vowels, constants,digits,upper, lower and special charecters in a string
17. Interchange ODD EVEN position in an aaray using pointers
18.To find the largest of given two numbers using pointer
19.Create a bio-data using file and display the contents
20.Copy content of one file into another using CLA



Related Frequently asked c programs

1. Write a c program to check given number is perfect number or not.
2. Write a c program to check given number is Armstrong number or not.
3. Write a c program to check given number is prime number or not.
4. Write a c program to check given number is strong number or not.
5. C program to check a number is odd or even.
6. Write a c program to check given number is palindrome number or not.
8. Write a c program to check given string is palindrome number or not.
7. Write a c program to solve quadratic equation.
8. Write a c program to print Fibonacci series of given range.
9. Write a c program to get factorial of given number.
10. Write a c program for Floyd’s triangle.
11. Write a c program to print Pascal triangle.
12. Write a c program to generate multiplication table.
13. Write a c program to print ASCII value of all characters.
14. C program to print hello world without using semicolon
15. Write a c program which produces its own source code as its output

C program with numbers

1. Write a c program to reverse any number.
2. Write a c program to find out sum of digit of given number.
3. Write a c program to find out power of number.
4. Write a c program to add two numbers without using addition operator.
5. Write a c program to subtract two numbers without using subtraction operator.
6. Write a c program to find largest among three numbers using binary minus operator.
7. Write a c program to find largest among three numbers using conditional operator
8. Write a c program to find out generic root of any number.
9. Write a c program to find out prime factor of given number.
10. Write a c program to find out NCR factor of given number.
11. How to convert string to int without using library functions in c
12. Program in c to print 1 to 100 without using loop
13. C program for swapping of two numbers
14. Program to find largest of n numbers in c
15. Split number into digits in c programming
16. C program to count number of digits in a number

Recursion

Example of recursion in c programming

L.C.M and H.C.F.

1. Write a c program to find out L.C.M. of two numbers.
2. Write a c program to find out H.C.F. of two numbers.
3. Write a c program to find out G.C.D. of two numbers.

Swapping

1. Write a c program to swap two numbers.
2. Write a c program to swap two numbers without using third variable.
3. Write a c program for swapping of two arrays.
4. Write a c program for swapping of two string.

Conversion ( Number System )

1. Write a c program to convert decimal number to binary number.
2. Write a c program to convert decimal number to octal number.
3. Write a c program to convert decimal number to hexadecimal number.
4. Write a c program to convert octal number to binary number.
5. Write a c program to convert octal number to decimal number.
6. Write a c program to convert octal number to hexadecimal number.
7. Write a c program to convert hexadecimal number to binary number.
8. Write a c program to convert hexadecimal number to octal number.
9. Write a c program to convert hexadecimal number to decimal number.
10. Write a c program to convert binary number to octal number.
11. Write a c program to convert binary number to decimal number.
12. Write a c program to convert binary number to hexadecimal number.
13. C program for addition of binary numbers .
14. C program for multiplication of two binary numbers.
15. C program fractional binary conversion from decimal.
16. C program for fractional decimal to binary fraction conversion.
17. C program to convert decimal number to roman.
18. C program to convert roman number to decimal number.
19. C program to convert each digits of a number in words
20. C program to convert currency or number in word.

Conversion ( Unit )

1. C program for unit conversion.

String

1. Write a c program to convert the string from upper case to lower case.
2. Write a c program to convert the string from lower case to upper case.
3. Write a c program to delete the all consonants from given string.
4. Write a c program to count the different types of characters in given string.
5. Write a c program to sort the characters of a string.
6. Write a c program for concatenation two strings without using string.h header file.
7. Write a c program to find the length of a string using pointer.
8. Write a c program which prints initial of any name.
9. Write a c program to print the string from given character.
10. Write a c program to reverse a string
11. Reverse a string using recursion in c
12. String concatenation in c without using strcat
13. How to compare two strings in c without using strcmp
14. String copy without using strcpy in c
15. Convert a string to ASCII in c

Matrix

1. Write a c program for addition of two matrices.
2. Write a c program for subtraction of two matrices
3. Write a c program for multiplication of two matrices.
4. Write a c program to find out sum of diagonal element of a matrix.
5. Write a c program to find out transport of a matrix.
6. Write a c program for scalar multiplication of matrix.
7. C program to find inverse of a matrix
8. Lower triangular matrix in c
9. Upper triangular matrix in c
10. Strassen's matrix multiplication program in c
11. C program to find determinant of a matrix

File

1. Write a c program to open a file and write some text and close its.
2. Write a c program to delete a file.
3. Write a c program to copy a file from one location to other location.
4. Write a c program to copy a data of file to other file.
5. Write a c program which display source code as a output.
6. Write a c program which writes string in the file.
7. Write a c program which reads string from file.
8. Write a c program which writes array in the file.
9. Write a c program which concatenate two file and write it third file.
10. Write a c program to find out size of any file.
11. Write a c program to know type of file.
12. Write a c program to know permission of any file.
13. Write a c program to know last date of modification of any file.
14. Write a c program to find size and drive of any file.

Complex number

1. Complex numbers program in c
2. Write a c program for addition and subtraction of two complex numbers.
3. Write a c program for multiplication of two complex numbers.
4. Write a c program for division two complex numbers.

Series

1. Write a c program to find out the sum of series 1 + 2 + …. + n.
2. Write a c program to find out the sum of series 1^2 + 2^2 + …. + n^2.
3. Write a c program to find out the sum of series 1^3 + 2^3 + …. + n^3.
4. Write a c program to find out the sum of given A.P.
5. Write a c program to find out the sum of given G.P.
6. Write a c program to find out the sum of given H.P.
7. Write a c program to find out the sum of series 1 + 2 + 4 + 8 … to infinity.

Array

1. Write a c program to find out largest element of an array.
2. Write a c program to find out second largest element of an unsorted array.
3. Write a c program to find out second smallest element of an unsorted array.
4. Write a c program which deletes the duplicate element of an array.
5. Write a c program for delete an element at desired position in an array.
6. Write a c program for insert an element at desired position in an array.
7. C program to find largest and smallest number in an array

Sorting

1. Write a c program for bubble sort.
2. Write a c program for insertion sort.
3. Write a c program for selection sort.
4. Write a c program for quick sort.
5. Write a c program for heap sort.
6. Write a c program for merge sort.
7. Write a c program for shell sort.

Recursion

1. Write a c program to find factorial of a number using recursion.
2. Write a c program to find GCD of a two numbers using recursion.
3. Write a c program to find out sum digits of a number using recursion.
4. Write a c program to find power of a number using function recursion.
5. Write a c program to reverse any number using recursion.

Size of data type

1. Write a c program to find the size of int without using sizeof operator.
2. Write a c program to find the size of double without using sizeof operator.
3. Write a c program to find the size of structure without using sizeof operator.
4. Write a c program to find the size of union without using sizeof operator.

Using pointer

1. Write a c program for concatenation two string using pointer.

Searching

1. Write a c program for linear search.
2. Write a c program for binary search.
3. Write a c program for binary search using recursion.

Area and volume

1. Write a c program to find the area of circle.
2. Write a c program to find the area of any triangle.
3. Write a c program to find the area of equilateral triangle.
4. Write a c program to find the area of right angled triangle.
5. Write a c program to find the area of rectangle.
6. Write a c program to find the area of trapezium.
7. Write a c program to find the area of rhombus.
8. Write a c program to find the area of parallelogram.
9. Write a c program to find the volume and surface area of cube.
10. Write a c program to find the volume and surface area of cuboids.
11. Write a c program to find the volume and surface area of cylinder.
12. Write a c program to find the surface area and volume of a cone.
13. Write a c program to find the volume and surface area of sphere.
14. Write a c program to find the perimeter of a circle, rectangle and triangle.

C program with very large numbers

1. Write a c program to find factorial of 100 or very large numbers
2. Write a c program to multiply the two very large number (larger the long int)
3. Write a c program for division of large number (larger than long int)
4. C code for modular division of large number.
5. C code for division of large number.
6. C code for power of large numbers.

Other C Programs

1. C program for ATM transaction.

2. Write a c program which passes one dimension array to function.
3. Write a c program which passes two dimension array to function.
4. Write a c program which takes password from user.
5. Write a scanf function in c which accept sentence from user.
6. Write a scanf function in c which accept paragraph from user.
7. Write a c program to print the all prime numbers between 1 to 300.
8. Write a c program which passes structure to function.
9. Palindrome in c without using string function
10. How to get the ASCII value of a character in c
11. C program to get last two digits of year
12. C program without main function
Swap two variables without using third variable.
Explanation:
#include<stdio.h>
int main(){
int a=5,b=10;
//process one
a=b+a;
b=a-b;
a=a-b;
printf("a= %d b= %d",a,b);

//process two
a=5;
b=10;
a=a+b-(b=a);
printf("\na= %d b= %d",a,b);
//process three
a=5;
b=10;
a=a^b;
b=a^b;
a=b^a;
printf("\na= %d b= %d",a,b);
//process four
a=5;
b=10;
a=b-~a-1;
b=a+~b+1;
a=a+~b+1;
printf("\na= %d b= %d",a,b);
//process five
a=5,
b=10;
a=b+a,b=a-b,a=a-b;
printf("\na= %d b= %d",a,b);
return 0;
}

1. Warp to check a number is Armstrong
2. C program to check whether a number is Armstrong or not
3. Simple c program for Armstrong number
4. Armstrong number in c with output

#include<stdio.h>
int main(){
int num,r,sum=0,temp;

printf("Enter a number: ");
scanf("%d",&num);

temp=num;
while(num!=0){
r=num%10;
num=num/10;
sum=sum+(r*r*r);
}
if(sum==temp)
printf("%d is an Armstrong number",temp);
else
printf("%d is not an Armstrong number",temp);

return 0;
}

Sample output:
Enter a number: 153
153 is an Armstrong number

3. C program to check perfect number

#include<stdio.h>
int main(){
int n,i=1,sum=0;

printf("Enter a number: ");
scanf("%d",&n);

while(i<n){
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
printf("%d is a perfect number",i);
else
printf("%d is not a perfect number",i);

return 0;
}

Sample output:
Enter a number: 6
6 is a perfect number


4. C program to determine prime number
Determining if a number is prime in c
C program to find given number is prime or not

#include<stdio.h>

int main(){

int num,i,count=0;
printf("Enter a number: ");
scanf("%d",&num);
for(i=2;i<=num/2;i++){
if(num%i==0){
count++;
break;
}
}
if(count==0 && num!= 1)
printf("%d is a prime number",num);
else
printf("%d is not a prime number",num);
return 0;
}

Sample output:
Enter a number: 5
5 is a prime number

5. 1. Write a c program to reverse a given number
2. C program to find reverse of a number
3. C program to reverse the digits of a number
4. Reverse of a number in c using while loop

#include<stdio.h>
int main(){
int num,r,reverse=0;

printf("Enter any number: ");
scanf("%d",&num);

while(num){
r=num%10;
reverse=reverse*10+r;
num=num/10;
}

printf("Reversed of number: %d",reverse);
return 0;
}

Sample output:
Enter any number: 12
Reversed of number: 21

6 Code 1:
1. C program to add digits of a number
2. C program for sum of digits of a number
3. C program to calculate sum of digits

#include<stdio.h>
int main(){
int num,sum=0,r;
printf("Enter a number: ");
scanf("%d",&num);
while(num){
r=num%10;
num=num/10;
sum=sum+r;
}
printf("Sum of digits of number: %d",sum);
return 0;
}

Sample output:
Enter a number: 123
Sum of digits of number: 6

7.Add two numbers in c without using operator

How to add two numbers without using the plus operator in c

#include<stdio.h>

int main(){
int a,b;
int sum;

printf("Enter any two integers: ");
scanf("%d%d",&a,&b);

//sum = a - (-b);
sum = a - ~b -1;

printf("Sum of two integers: %d",sum);

return 0;
}



Sample output:

Enter any two integers: 5 10

Sum of two integers: 15

Algorithm:

In c ~ is 1's complement operator. This is equivalent to:
~a = -b + 1
So, a - ~b -1
= a-(-b + 1) + 1
= a + b – 1 + 1
= a + b


8. Write a c program to find largest among three numbers using binary minus operator

#include<stdio.h>
int main(){
int a,b,c;
printf("\nEnter 3 numbers: ");
scanf("%d %d %d",&a,&b,&c);
if(a-b>0 && a-c>0)
printf("\nGreatest is a :%d",a);
else
if(b-c>0)
printf("\nGreatest is b :%d",b);
else
printf("\nGreatest is c :%d",c);
return 0;
}

9. Write a c program to find largest among three numbers using conditional operator
#include<stdio.h>
int main(){
int a,b,c,big;
printf("\nEnter 3 numbers:");
scanf("%d %d %d",&a,&b,&c);

big=(a>b&&a>c?a:b>c?b:c);
printf("\nThe biggest number is: %d",big);

return 0;
}

10. Write a c program or code to subtract two numbers without using subtraction operator

#include<stdio.h>

int main(){
int a,b;
int sum;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);
sum = a + ~b + 1;
printf("Difference of two integers: %d",sum);

return 0;
}

Sample Output:
Enter any two integers: 5 4
Difference of two integers: 1

11. Program in c to print 1 to 100 without using loop

#include<stdio.h>

int main(){
int num = 1;

print(num);

return 0;
}
int print(num){
if(num<=100){
printf("%d ",num);
print(num+1);
}
}

12. Write a c program to check given number is strong number or not.

1. Write a c program to check whether a number is strong or not

#include<stdio.h>
int main(){
int num,i,f,r,sum=0,temp;

printf("Enter a number: ");
scanf("%d",&num);
temp=num;
while(num){
i=1,f=1;
r=num%10;

while(i<=r){
f=f*i;
i++;
}
sum=sum+f;
num=num/10;
}
if(sum==temp)
printf("%d is a strong number",temp);
else
printf("%d is not a strong number",temp);

return 0;
}

Sample output:
Enter a number: 145
145 is a strong number


C program for odd or even number


Code 1:
1. C program to check even or odd
2. C determine odd or even
3. How to check odd number in c
4. How to determine odd or even in c
5. C even odd test

#include<stdio.h>

int main(){

int number;
printf("Enter any integer: ");
scanf("%d",&number);

if(number % 2 ==0)
printf("%d is even number.",number);
else
printf("%d is odd number.",number);
return 0;

}

Sample output:
Enter any integer: 5
5 is odd number.


Write a c program to check given string is palindrome number or not


#include<string.h>
#include<stdio.h>
int main(){
char *str,*rev;
int i,j;
printf("\nEnter a string:");
scanf("%s",str);
for(i=strlen(str)-1,j=0;i>=0;i--,j++)
rev[j]=str[i];
rev[j]='\0';
if(strcmp(rev,str))
printf("\nThe string is not a palindrome");
else
printf("\nThe string is a palindrome");
return 0;
}

TO FIND FIBONACCI SERIES USING C PROGRAM


Code 1:
1. Write a program to generate the Fibonacci series in c
2. Write a program to print Fibonacci series in c
3. Basic c programs Fibonacci series
4. How to print Fibonacci series in c
5. How to find Fibonacci series in c programming
6. Fibonacci series in c using for loop

#include<stdio.h>
int main(){
int k,r;
long int i=0l,j=1,f;

//Taking maximum numbers form user
printf("Enter the number range:");
scanf("%d",&r);

printf("FIBONACCI SERIES: ");
printf("%ld %ld",i,j); //printing firts two values.

for(k=2;k<r;k++){
f=i+j;
i=j;
j=f;
printf(" %ld",j);
}
return 0;
}

Sample output:
Enter the number range: 15
FIBONACCI SERIES: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

TO FIND FACTORIAL OF A NUMBER USING C PROGRAM


Code 1:
1. C code for factorial of a number
2. C program to find the factorial of a given number
3. Factorial program in c using while loop
4. Factorial program in c without using recursion

#include<stdio.h>
int main(){
int i=1,f=1,num;

printf("Enter a number: ");
scanf("%d",&num);

while(i<=num){
f=f*i;
i++;
}

printf("Factorial of %d is: %d",num,f);
return 0;
}

Sample output:
Enter a number: 5
Factorial of 5 is: 120


Write a c program to print Pascal triangle.



1. Pascal triangle in c without using array

2. C code to print Pascal triangle

3. Simple c program for Pascal triangle

4. C program to generate Pascal triangle

5. Pascal triangle program in c language

6. C program to print Pascal triangle using for loop


#include<stdio.h>

long fact(int);
int main(){
int line,i,j;

printf("Enter the no. of lines: ");
scanf("%d",&line);

for(i=0;i<line;i++){
for(j=0;j<line-i-1;j++)
printf(" ");

for(j=0;j<=i;j++)
printf("%ld ",fact(i)/(fact(j)*fact(i-j)));
printf("\n");
}
return 0;
}

long fact(int num){
long f=1;
int i=1;
while(i<=num){
f=f*i;
i++;
}
return f;
}

Sample output:

Enter the no. of lines: 8
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1


PRINTING ASCII VALUE USING C PROGRAM


Printing ascii value using c program

C code for ASCII table

C program to display ASCII values


#include<stdio.h>



int main(){

int i;
for(i=0;i<=255;i++)
printf("ASCII value of character %c: %d\n",i,i);

return 0;
}

Output:

ASCII value of character : 0

C program to count number of digits in a number

Code 1:
Count the number of digits in c programming language

#include<stdio.h>
int main(){
int num,count=0;

printf("Enter a number: ");
scanf("%d",&num);

while(num){
num=num/10;
count++;
}
printf("Total digits is: %d",count);
return 0;
}

Sample output:
Enter a number: 23
Total digits is: 2


Program to find largest of n numbers in c


Simple program of c find the largest number

#include<stdio.h>
int main(){
int n,num,i;
int big;
printf("Enter the values of n: ");
scanf("%d",&n);
printf("Number %d",1);
scanf("%d",&big);

for(i=2;i<=n;i++){
printf("Number %d: ",i);
scanf("%d",&num);

if(big<num)
big=num;
}
printf("Largest number is: %d",big);

return 0;
}

Sample Output:
Enter the values of n:
Number 1: 12
Number 2: 32
Number 3: 35
Largest number is: 35


C program for swapping of two numbers


Code for swapping in c

#include<stdio.h>
int main(){
int a,b,temp;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);
printf("Before swapping: a = %d, b=%d",a,b);

temp = a;
a = b;
b = temp;
printf("\nAfter swapping: a = %d, b=%d",a,b);

return 0;
}

C program for swapping of two numbers using pointers

#include<stdio.h>

int main(){

int a,b;
int *ptra,*ptrb;
int *temp;

printf("Enter any two integers: ");
scanf("%d%d",&a,&b);

printf("Before swapping: a = %d, b=%d",a,b);

ptra = &a;
ptrb = &b;

temp = ptra;
*ptra = *ptrb;
*ptrb = *temp;

printf("\nAfter swapping: a = %d, b=%d",a,b);
return 0;
}

Sample output:
Enter any two integers: 5 10
Before swapping: a = 5, b=10
After swapping: a = 10, b=10


Swapping program in c using function

#include<stdio.h>

void swap(int *,int *);
int main(){

int a,b;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);

printf("Before swapping: a = %d, b=%d",a,b);

swap(&a,&b);

printf("\nAfter swapping: a = %d, b=%d",a,b);
return 0;
}

void swap(int *a,int *b){
int *temp;
temp = a;
*a=*b;
*b=*temp;
}

Sample output:
Enter any two integers: 3 6
Before swapping: a = 3, b=6
After swapping: a = 6, b=6