FREE : [ Study Material ] NDA/SSB Preparation : Check Now!!! | Latest: HR Interview Questions:CHECK | Like Us :

Showing posts with label C-Programs. Show all posts
Showing posts with label C-Programs. Show all posts

Wednesday, 5 June 2013

WRITE A C PROGRAM TO OPEN A FILE AND DISPLAY ITS CONTENT along with the Number of Blanks,Characters and Tab

0 comments
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
char ch;
int not=0,nob=0,noc=0;
fp=fopen("PRIME.C","r");
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
noc++;
if(ch==' ')
nob++;
if(ch=='\n')
not++;
if(ch=='\t')
not++;
}
fclose(fp);
printf("\nCharacters %d",noc);
printf("\nBlanks %d",nob);
printf("\nTABS %d",not);
printf("\n");
fclose(fp);
getch();
}


OUTPUT

Write a C program to open a File and display its content?

0 comments
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
char ch;
fp=fopen("PRIME.C","r");
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
printf("%c",ch);
}
printf("\n");
fclose(fp);
getch();
}

Output:-



Sunday, 28 April 2013

C PROGRAM TO IMPLEMENT STACK USING ARRAY | Stack USING ARRAY

0 comments
PROGRAM by Ashish

#include<stdio.h>
#include<conio.h>
#define MAX 10
int stack[MAX];
int top=-1;
void push(int num);
void pop();
void traverse();
void main()
{
int num,ch,p=0;
clrscr();
do
{
printf("Enter 1 to Print STACK\n");
printf("ENTER 2 to PUSH ITEM\n");
printf("ENTER 3 to POP ELEMENT\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("\nElements in Stack are:-\t");
traverse();
break;
}
case 2:
{
printf("\nEnter the Element to be pushed");
scanf("%d",&num);
push(num);
break;
}
case 3:
{
printf("\nGoing to Perform POP OPERATION");
pop();
break;
}
}
printf("\nENTER 1 to Continue");
scanf("%d",&p);
}while(p==1);
getch();
}
void traverse()
{
int i;
if(top==-1)
{
printf("\nStack is EMPTY");
}
else
{
for(i=top;i>=0;i--)
{
printf("\n%d",stack[i]);
}
}
}
void push(int num)
{
if(top==MAX)
{
printf("\nOVERFLOW");
}
else
{
top=top+1;
stack[top]=num;
printf("\n Element added");
}
}
void pop()
{
int item;
if(top==-1)
{
printf("\nUnder FLow");
}
else
{
item=stack[top];
top=top-1;
printf("\Element poped is%d",item);
}
}


Output:-

Wednesday, 24 April 2013

C program to implement a Queue Implementation using array | QUEUE USING ARRAY

0 comments
//Program Coded by ASHISH

#include<stdio.h>
#include<conio.h>
#define MAX 50
int queue[MAX];
int FRONT=-1;
int REAR=-1;
void traverse();
void insert(int num);
void remov();
void main()
{
int ch,num,p;
clrscr();
do
{
printf("Press 1 to Print All elements of QUEUE\n");
printf("Press 2 to Insert Element in the Queue\n");
printf("Press 3 to Delete Element from the QUEUE\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
traverse();
break;
}
case 2:
{
printf("Enter the Element to be inserted in queue\n");
scanf("%d",&num);
insert(num);
break;
}
case 3:
{
printf("Deleting Element from Queue--FIFO---\n");
remov();
break;
}
}
printf("\nDo you wanna Perform again 1 for yes\n");
scanf("%d",&p);
}while(p==1);
getch();
}
void traverse()
{
int i;
if(FRONT==-1&&REAR==-1)
{printf("\nQueue is Empty");}
else
{
printf("Queue is:-\n");
for(i=FRONT;i<=REAR;i++)
{
printf("\n%d",queue[i]);
}
}

}
void insert(int num)
{
if(FRONT==-1&&REAR==-1)
{
FRONT=0;
REAR=0;
queue[FRONT]=num;
}
else
{
REAR=REAR+1;
queue[REAR]=num;
}
printf("Element Inserted\n");
}
void remov()
{
if(FRONT==-1&&REAR==-1)
{printf("Queue is Empty\n");}
else if(FRONT==REAR)
{
FRONT=-1;
REAR=-1;
printf("Queue is Empty NOW!!!\n");
}
else
{
FRONT=FRONT+1;
}
}

Saturday, 22 December 2012

Program to Swap 2 numbers without using third Variable | C Program


Input



#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Swapping of two numbers without using temporary variable\n");
printf("Enter the two number");
scanf("%d%d",&a,&b);
printf("Numbers\n a=%d\t b=%d \n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("Numbers after\n Swapping a=%d\t b=%d",a,b);
getch();
}


Turbo C



Friday, 21 December 2012

Program to swap two Numbers using Temporary Variable | C Program


Input



#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("Swapping two using a temporary Variable\n");
scanf("%d%d",&a,&b);
printf("Number before Swapping are \ta=%d\tb=%d",a,b);
temp=a;
a=b;
b=temp;
printf("\nNumber after Swapping are \ta=%d\tb=%d",a,b);
getch();
}


Turbo C




Program to Reverse a String | C Program


Input



#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
char a[30],temp;
clrscr();
printf("Reverse a string\n");
printf("Enter the String\t");
gets(a);
n=strlen(a);
for(i=0;i<n/2;i++)
{
temp=a[i];
a[i]=a[n-i-1];
a[n-i-1]=temp;
}
for(i=0;i<n;i++)
printf("%c",a[i]);
getch();
}


Turbo C



Program to Reverse a Number | C Program


Input



#include<stdio.h>
#include<conio.h>
void main()
{
int num,res=0;
clrscr();
printf("Reverse a Number\n");
printf("Enter the Number to Reversed\n");
scanf("%d",&num);
printf("Number before reverse %d\n",num);
while(num>0)
{
res=10*res+num%10;
num=num/10;
}
printf("Number After reverse\t %d",res);
getch();
}


Turbo C



Program to check whether a Number is Prime or Not | C Program


Input 



#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,flag=0;
clrscr();
printf("Enter the Number to be checked\n");
scanf("%d",&n);
for(i=2;i<n/2;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0) printf("Number is prime");
if(flag==1) printf("Number is not prime");
getch();
}




Turbo C






Program to calculate the Power of a Number | C program


Input



#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,res=1,i;
clrscr();
printf("Enter the number\n");
scanf("%d",&a);
printf("Enter the Power\n");
scanf("%d",&b);
for(i=b;i>0;i--)
{
res=res*a;
}
printf("a^b=%d\t",res);
getch();
}



Turbo C



Program to Check Palindrome of a String | C Program


Input



#include<stdio.h>
#include<conio.h>
void main()
{
int i,flag=0;
char a[20],b[20],n;  clrscr();
printf("Enter the String to be checked\t");
gets(a);
n=strlen(a);
for(i=0;i<n;i++)
{
b[n-i-1]=a[i];
}
for(i=0;i<n;i++)
{
if(a[i]!=b[i]) {    flag=1; break; }
}
if(flag==1) printf("\n String is not palindrome");
if(flag==0) printf("\n String is palindrome");
getch();
}


Turbo C




Program to check Palindrome of a Number | C Program


Input


#include<stdio.h>
#include<conio.h>
void main()
{
int num,rev=0,temp;
clrscr();
printf("Enter the number of want to check for palindrome\n");
scanf("%d",&num);
temp=num;
while(temp>0)
{
rev=(10*rev) + (temp%10);
temp=temp/10;
}
if(num==rev)
printf("\nNumber is Palindrome");
else
printf("\n Number is not Palindrome");
getch();
}


Turbo C




Program to calculate factorial of a Number | C program


Input


#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,res=1;
clrscr();
printf("Enter the Number\n");
scanf("%d",&n);
for(i=n;i>0;i--)
{
res=res*i;
}
printf("The Factorial is\n\t%d",res);
getch();
}


Turbo C



Program to check whether a Number is Even or Odd? | C Program


Input



#include<stdio.h>
#include<conio.h>
void main()
{
int num;
clrscr();
printf("Enter the number to be Checked\t");
scanf("%d",&num);
if(num%2==0)
printf("\nNumber is EVEN");
else
printf("\nNumber is ODD");
getch();
}

Turbo C




 

Results

get our extension

Like Us on FB

    Freshers Jobs

    Donate

    DMCA Protected

    You are Visitor Number

    Interview Questions

    SSB Questions

      Authors
    Tinku Singh
    Hitesh Dhanda

    MrNaukri.com - Get Sarkari Jobs, Results, Off Campus Placement Updates © 2012. All Rights Reserved | Back To Top |

    © 2013 A Product of IBC Network