Professional Documents
Culture Documents
#include<stdio.h>
#include<string.h>
for(i=0;i<n;i++)
count=1;
if(s[i])
for(j=i+1;j<n;j++)
if(s[i]==s[j])
count++;
s[j]='\0';
int main()
char s[1000];
gets(s);
frequencyofuniquecharacter(s);
return 0;
}
2. Program to swap two numbers.
#include <stdio.h>
int t;
t = *a;
*a = *b;
*b = t;
int main()
int x,y;
printf("Enter x: ");
scanf("%d",&x);
printf("Enter y: ");
scanf("%d",&y);
swap(&x,&y);
return 0;
}
3. Program to find area and circumference of a circle.
#include <stdio.h>
*area=3.1415*(*r)*(*r);
*peri=2*3.1415*(*r);
int main(){
float radius,area,peri;
scanf("%f",&radius);
Area_Perimeter(&radius,&area,&peri);
return 0;
}
4. Write functions for the following string operations.
#include <stdio.h>
#include <stdlib.h>
int lengh(char*str)
int count = 0;
count++;
str++;
return count;
while(*m != '\0')
m++;
while(*n != '\0')
*m=*n;
m++;
n++;
*m = '\0';
while(*n)
*m = *n;
n++;
m++;
*m = '\0';
char reverse[100];
reverse[i]=*(str+length-1-i);
*(str+i) = reverse[i];
while(*m == *n)
if ( *m == '\0' || *n == '\0' )
break;
m++;
n++;
else
int main(){
char m[50],n[50];
int a;
scanf("%d",&a);
if(a==1)
printf("==LENGTH FUNCTION==\n");
scanf("%s",m);
if(a==2)
printf("==Reverse function==\n");
scanf("%s",m);
reverse(m);
if(a==3)
printf("==Concatenation function==\n");
scanf("%s",m);
scanf("%s",n);
concat(m,n);
puts(m);
if(a==4)
printf("==Copy function==\n");
scanf("%s",m);
scanf("%s",n);
copy(m,n);
printf("\nafter copying:");
puts(n);
if(a==5)
printf("==Compare function==\n");
scanf("%s",m);
scanf("%s",n);
compare(m,n);
else if (a>=6)
printf("==Wrong command==");
return 0;
}
5. Write a program to display the greatest of N numbers –use malloc() function.
#include<stdio.h>
#include<stdlib.h>
int main(){
int n;
int *p;
scanf("%d",&n);
p = (int*)malloc(n * sizeof(int));
printf("==MEMORY ALLOCATED==\n");
scanf("%d",p+i);
*p = *(p + i);
return 0;
}
6. Write a program to arrange N names in alphabetical order using dynamic memory allocation.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int i,j;
char t[20];
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++){
if(strcmp(x[i],x[j])>0)
strcpy(t,x[j]);
strcpy(x[j],x[i]);
strcpy(x[i],t);
int main()
char *x[20];
int i,n=0;
scanf("%d",&n);
printf("\n");
for(i=0;i<n;i++)
x[i]=(char *)malloc(20*sizeof(char));
scanf("%s",x[i]);
}
alphaorder(n,x);
for(i=0;i<n;i++)
printf("%s\n",x[i]);
return 0;