Showing posts with label source code. Show all posts
Showing posts with label source code. Show all posts

C Program to Simulate Round Robin CPU Sceduling Algorithm

The round robin CPU scheduling algorithm is simulated using C program. The time slice or time quantum is read from the user.

Program:

#include<stdio.h>
struct process{

C Program to Simulate grep Command in Linux

This post contains C program to simulate grep command in Linux or Unix operating systems

Simulation of  grep command in Linux

#include<stdio.h>
#include<string.h>
main()
{

C Program to Simulate the ls Command in Linux Operating system

This is a c program to do Simulation of ls Command in linux. The ls command lists all the contents of the directory including filse and sub-directories. The following program in C language will simulate the ls command.

#include<stdio.h>
#include<dirent.h>
main()
{

C Program to Remove (Delete) a Directory using LINUX System Calls

This is a C program to delete  or remove a directory using the system calls in Linux or Unix operating systems. The program make use of the remove() system call in Linux.

#include<stdio.h>
#include<fcntl.h>
main()
{

C Program to open, read and write files and perform file copy operation usingSystem Calls in UNIX

Write a program to open, read and write files and perform file copy operation. This program show how to open, read, write and copy files using Linux or Unix system calls like open(), read() and write().

#include<stdio.h>
#include<fcntl.h>
main()
{

C Program to Open, Read and Write a file using System Calls

This is a C program to open , read and write files using system calls in Linux (UNIX) operating systems. The system calls open(), read() and write() are used in the C program to open, read and write files in Unix/Linux operating systems.

#include<stdio.h>
#include<fcntl.h>
main()
{

Using System calls in C Program to rename a Directory in Linux

C Program to rename a directory in Unix or Linux operating systems using system call rename().

#include<stdio.h>
main()
{

How to Create process and display Process ID (pid) of Both Parent and Child

This program shows how to create process and display Process ID (pid) of Both Parent and Child processes. The process is created using the fork system call in UNIX (Linux) operating systems.

#include<stdio.h>
#include<dirent.h>
main(int argc,char **argv)
{

How to use exit() System call

C program to show how to use exit system call. The function exit() is used to exit from a process (or to terminate a process). This works both in Linux or UNIX and Windows operating systems.

#include<stdio.h>
main()
{

C and C++ Programs to Reverse a Number

This post includes a C program and a C++ program to reverse a given number. That is, to reverse the order of digits. If 543 is entered, it will be displayed as 345.

C Program:

#include<stdio.h>
main()
{

Linear Search in C and C++ Languages

Linear search simply means 'looking for an element in the whole array from one end to the other'. The searched element is compared with the first element of array first, then with the second, then with the third, so on upto the end of the array. This is time consuming when the array is pretty enough. The time complexity is highest.The C and C++ programs for linear search is given below.

C Program:

#include<stdio.h>

void main()
{

C and C++ Programs to Check Whether a Number is Strong Number or Not

This post contains C and C++ program to check whether a given number is Strong number or not. A strong number is a number for which the sum of factorials of its digits is equal to the number itself. The first one is C program to check whether the input number is a strong number or not. An example is 145. 1!+4!+5!=1+24+120=145 Therefore 145 is a strong number.

C Program:

#include<stdio.h>
long int factorial(int n)

{

C and C++ Programs for String Sorting

Here i am writing programs in c and c++ languages to sort a given number of strings. Sorting is carried out based on the ASCII values of the letters in the strings. The string comparing function strcmp() is used in the program. These programs sort a given set of strings in ascending order.To change it into descending order just replace > with < in comparison line. The comparison line in the code is marked by comment.

C Program:
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{

C Program for Subtraction Without Using Minus Sign

The following is a program to subtract a number from another without using minus symbol. Instead of doing a normal subtract operation, the two's complement of the subtrahend is added to the minuend. (In 3-4, 3 is minuend and 4 is subtrahend.) In other words, the 1's complement and 1 is added to minuend.

#include<stdio.h>
void main()
{
int a,b,sum;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);
sum = a + ~b + 1;
printf("Difference of two integers: %d",sum);
}


C and C++ Programs to Find Sum of Digits of a Given Number

The following are C and C++ programs to find sum of digits of any given integer.

C Program

#include<stdio.h>
#include<conio.h>
void main()
{

C and C++ Program for Swapping Two Numbers Without Third Variable

This post contains C and C ++ programs for swapping two given numbers without using any temporary variable. Only the two variables are required, not a third.

C Program
#include<stdio.h>
void main()
{

2 Different C and C++ Programs to Check Whether a Given String is Palindrome or Not

Here i am writing two different programs to check whether a given string (text) us palindrome or not. There are C and C++ programs for this.

C Programs:

(i) Using string functions:




#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
char a[100],b[100];
printf("Enter the string to check if palindrome or not\n");
gets(a);
strcpy(b,a);
strrev(b);
if(strcmp(a,b)==0)
printf("\nEntered string is palindrome");
else
printf("\nEntered string is not palindrome");
getch();
} 

(ii) Comparing Character by Character


#include<string.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int len,i;
char a[100];
printf("Enter the string to check whether it is palindrome or not\n");
gets(a);
len=strlen(a);
for(i=0;i<len/2;i++)
{
if(a[i]!=a[len-i-1])
break;
}

if(i==len/2)
printf("\nEntered string is palindrome");
else
printf("\nEntered string is not palindrome");
getch();
}

C++ Programs:

(i) Using String functions:


C and C++ Program to Check Whether a Given Number is Even or Odd

C and C++ programs to check whether a given number is Odd or even

C Program

#include<stdio.h>
void main()
{
int n;
printf("Enter an integer\n");
scanf("%d",&n);
if ( n%2 == 0 )
printf("Even");
else
printf("Odd");
}

C++ Program

#include<iostream.h>
void main()
{
int n;
cout<<"Enter an integer\n";
cin>>n;
if ( n%2 == 0 )
cout<<"\nEven";
else
cout <<"\nOdd";
}


C and C++ Program to Check Whether a Given Year is Leap Year or Not

This is post contains a C program and a C++ program to check whether an input year is leap year or not. A year is a leap year if:

  1. The year is divisible by 400
  2. The year is divisible by 4 but not divisible by 100.
Any other year is not a leap year.

C program
#include <stdio.h>
void main()
{
int year;
printf("Enter a year to check if it is a leap year\n");
scanf("%d", &year);
if(year%400==0 || ((year%4=0) && (year%100!=0)))
printf("%d is a leap year.\n", year); else
printf("%d is not a leap year.\n", year);
}


C++ program
#include <iostream.h>
void main()
{
int year;
cout<<"Enter a year to check if it is a leap year or not";
cin>>year;
if(year%400==0 || ((year%4=0) && (year%100!=0)))
cout<<"\n"<<year<<"is a leap year."; else
cout<<"\n"<<year<<"is NOT a leap year."; 
}