Professional Documents
Culture Documents
List of Experiments (List of Experiments Given by G.G.S.I.P.U)
List of Experiments (List of Experiments Given by G.G.S.I.P.U)
U)
1. Write a program to produce ASCII equivalent of given number
#include<stdio.h>
#include<conio.h>
void main()
{
char a;
int b;
clrscr();
printf(" \n \n enter the number whose ASCII value is to be determined : ");
scanf("%d",&b);
a=b;
printf(" \n \n the ASCII value of the number entered %d is : %c",b,a);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int a,n,b=1,i,fac;
printf("\n \n \t Enter the number whose factorial is to be found :");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
a=i;
fac=a*b;
b=fac;
}
printf("\n \n the factorial of %d is : %d",n,fac);
getch();
return 0;
}
for(int i=0;i<strlen(str);i++)
{
str[i]=str[i]+12;
}
printf("\n \n The encrypted string is : ");
puts(str);
for(i=0;i<strlen(str);i++)
{
str[i]=str[i]-12;
}
printf("\n \n The decrypted string is : ");
puts(str);
getch();
}
6. Write a program to check whether a given string follows English capitalization rules
7. Write a program to find sum of the following series
1+ ½ + 1/3 +________+1/20
#include<stdio.h>
#include<conio.h>
main ()
{
float sum=1.0;
for(int i=1;i<=20;i++)
sum= sum + (1.0/i);
printf("\n the sum of the series is : %f ",sum);
getch();
return 0;
}
12. Write a program that takes two operands and one operator from the user perform the
operation and then print the answer
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
char ch;
printf("\n \n Enter the operator : ");
scanf("%c",&ch);
printf("\n \n Enter the operands a & b : ");
scanf("%d %d",&a,&b);
switch(ch)
{
case '+': c=a+b;
printf("\n \n a+b = %d",c);
break;
case '-': c=a-b;
printf("\n \n a-b = %d",c);
break;
case '*': c=a*b;
printf("\n \n a*b = %d",c);
break;
case '/': c=a/b;
printf("\n \n a/b = %d",c);
break;
case '%': c=a%b;
printf("\n \n a%b = %d",c);
break;
default : printf(" \n \n wrong choice ");
}
getch(); }
13. Write a program to print the following outputs:
1 1
2 2 2 2
3 3 3 3 3 3
4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 5
#include<stdio.h>
#include<conio.h>
main()
{
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
printf(" %d ",i);
}
printf("\n");
}
getch();
return 0;
}
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
14. Write functions to add, subtract, multiply and divide two complex numbers (x+iy) and
(a+ib) Also write the main program.
#include<stdio.h>
#include<conio.h>
#include<math.h>
/// OBJECTIVE :
WRITE A MENU DRIVEN PROGRAM FOR SEARCHING AN SORTING WITH
FOLLOWING OPTION -
/// A) SEARCHING
/// 1) LINEAR SEARCHING 2) BINARY SEARCHING
/// B) SORTING
/// 1) INSERTION SORTING 2) SELECTION SORTING
///
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
int n,ch,i,a[10],t,k,j,temp,c,pos=-1,b,end,beg,mid;
clrscr();
printf("\n\n Enter the numbers but for binary searching enter the numbers
in ascending order");
for(i=0;i<=n-1;i++)
scanf("%d",&a[i]);
switch(ch)
{
case 1: /// CASE FOR SELECTION SORT ///
printf("\n\n******SELECTION SORT******");
for(i=0;i<=(n-2);i++)
{
for(int j=i+1;j<=n-1;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
break;
printf("\n\n********Insertion sort********");
for(i=1;i<=n-1;i++)
{
t=a[i];
for(j=0;j<i;j++)
{
if(t<a[j])
{
for(k=i;k>=j;k--)
a[k]=a[k-1];
a[j]=t;
break;
}
}
}
break;
case 2: //// CASE FOR SEARCHING THE ELEMENT FROM THE LIST ///
switch(ch)
{
case 1: /// CASE FOR LINEAR SEARCH ///
printf("\n***********LINEAR
SERCHING******************");
for(i=0;i<=n-1;i++)
{
if(b==a[i])
{
pos=i;
break;
}
}
if(pos>=0)
printf("\n\n %d is found in position %d",b,pos+1);
else
printf("\n\n number is not there");
break;
printf("\n\n**************binary searching***********");
beg=0;
end=n-1;
mid=(beg+end)/2;
while(beg<=end&&b!=a[mid])
{
if(b>a[mid])
beg=mid+1;
else
end=mid-1;
mid=(beg+end)/2;
}
if(a[mid]==b)
printf("\n\n%d is found in position: %d",b,mid+1);
else
printf("\n the number is not there");
break;
default:
printf("\n u have entered the wrong choice");
}
getche();
}
}
//////////////OUTPUT//////////////////
///********Insertion sort********
///**************binary searching***********
#include<stdio.h>
#include<conio.h>
main()
{
int n;
clrscr();
printf("\n Enter the number of disks:");
scanf("%d",&n);
transfer(n,'L','R','C');
getch();
}
///////OUTPUT///////
/// PROGRAM :
#include<stdio.h>
#include<conio.h>
#include<string.h>
if(argc!=3)
{
puts("insufficient arguments");
}
fs = fopen(argv[1],"r");
if(fs==NULL)
{
puts("cannot open the source file");
}
ft = fopen(argv[2],"w");
if(ft==NULL)
{
puts("cannot open target file");
fclose(fs);
}
while(1)
{
ch=fgetc(fs);
if(ch==EOF)
break;
else
fputc(ch,ft);
}
fclose(fs);
fclose(ft);
getch();