#include<stdio.h> int sum(int *p,int n) { int s=0,i; for(i=0;i<n;i++) { s=s+*p; p++; } return s; } void main() { int arr[10]={7,3,11,4,8,2,6,0,1,5}; int z; z=sum(arr,5); printf("Sum is %d",z); }
Sum is 33
#include<stdio.h> float mean(int *p,int n) { int i; float m,s=0; for(i=0;i<n;i++) { s=s+ *p; p++; } m=s/n; return m; } void main() { int arr[10]={7,3,11,4,8,2,6,0,1,5}; float z; z=mean(arr,5); printf("Mean is %f",z); }
Mean is 6.600000
#include<stdio.h> int count(int *p,int n) { int i,c=0; for(i=0;i<n;i++) { if(*p%2 == 0 ) c=c+1; p++; } return c; } void main() { int arr[10]={7,3,11,4,8,2,6,0,1,5}; int z; z=count(arr,5); printf("Total Even nos are %d",z); }
Total Even nos are 2
#include<stdio.h> int max(int *p,int n) { int i,g; g=*p; for(i=0;i<n-1;i++) { p++; if(*p>g) g=*p; } return g; } void main() { int arr[10]={7,13,51,44,28,52,16,0,21,5}; int z; z=max( arr,5); printf("Greatest No is %d",z); }
Greatest No is 51
while(*p!='\0') { --------- --------- p++; }
#include<stdio.h> int length(char *p) { int c=0; while(*p!='\0') { c=c+1; p++; } return c; } void main() { char arr[50]; int z; printf("Enter a String "); gets(arr); z=length(arr); printf("Length is %d ",z); }
Enter a string Amravati Length is 8
#include<stdio.h> int count(char *p) { int c=0; while(*p!='\0') { if(*p==' ') c++; p++; } return c+1; } void main() { char arr[50]; int z; printf("Enter a String "); gets(arr); z=count(arr); printf("Total Words are %d ",z); }
Enter a string Amravati is smart city Total Words are 4
#include<stdio.h> void reverse(char *p) { char *q; q=p; while(*q!='\0') q++; q=q-1; while(p<q) { char temp; temp=*p; *p=*q; *q=temp; p++; q--; } } void main() { char arr[50]; printf("Enter a String "); gets(arr); reverse(arr); printf("Result is %s ",arr); }
Enter a string Amravati Result is itavarmA
#include<stdio.h> void copy(char *q,char *p) { while(*p!='\0') { *q=*p; p++; q++; } *q='\0'; } void main() { char a[10]="seeta"; char b[10] ; copy(b,a); printf("Result is %s ",b); }
Result is seeta
#include<stdio.h> void join(char *p , char *q) { while(*p!='\0') p++; while(*q!='\0') { *p=*q; p++; q++; } *p ='\0'; } void main() { char a[10]="seeta"; char b[10]="ram"; join(a,b); printf("Result is %s ",a); }
Result is seetaram