Main()
{
int n[5],I;
for(i=0;i<=4;i++)
{
printf(“Enter the number\n”);
scanf(“%d”,&n[i]);
}
sorting(n[0]);
printf(“The sorted list\n”);
for(i=0;i<=4;i++)
printf(“%d\n”,n[i]);
getch();
}
sorting (int *k)
{
int I,j,t;
for(i=0;i<4;i++)
for(j=i+1 ;j<=4 ;j++)
if(*(k+i)>* (k+j ))
{
t=*(k+I );
*(k+i)=*(k+j);
*(k+j )=t;
}
}
Posted by: Wasim Javed
Understand All about Windows 7 Tips and Tricks, Fashion,Technology, Sports, Games,Windows 8 ,Computer Science ,Essay ,Application and more useful content here, Simply to Read and Enjoy it.
Feed Headline Animator
Showing posts with label C LANGUAGE PROGRAMMING. Show all posts
Showing posts with label C LANGUAGE PROGRAMMING. Show all posts
Problem 6
main()
{
int l[10] ,I ,j, s;
for(i=0; < 10 ;i++)
{
printf(“Enter a number \n”);
scanf(“%d”,&l[i]);
s= summation (&l[0]);
printf(“sum=%d\n”,s);
}
summation (int *p)
{
int j,sum=0;
for(i=0 ;j<10 ;j++)
sum +=*(p+j);
return( sum);
}
Posted by: Wasim Javed
{
int l[10] ,I ,j, s;
for(i=0; < 10 ;i++)
{
printf(“Enter a number \n”);
scanf(“%d”,&l[i]);
s= summation (&l[0]);
printf(“sum=%d\n”,s);
}
summation (int *p)
{
int j,sum=0;
for(i=0 ;j<10 ;j++)
sum +=*(p+j);
return( sum);
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
Problem 5
main()
{
int n,m,c;
printf(“Enter two number \n”);
scanf( “%d %d “,&n, &m);
c=addition (&n, &m);
printf(sum of sequres =%d”,c);
}
addition ( int* p1 ,int *p2)
{
intr ;
r=* p1 *p2 +p2 *p2;
return ( r);
}
Posted by: Wasim Javed
{
int n,m,c;
printf(“Enter two number \n”);
scanf( “%d %d “,&n, &m);
c=addition (&n, &m);
printf(sum of sequres =%d”,c);
}
addition ( int* p1 ,int *p2)
{
intr ;
r=* p1 *p2 +p2 *p2;
return ( r);
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
Palindrome
main()
{
char ch [10];
int I, l;
printf(“Enter string \n”);
gets ( ch);
l= strlen (ch);
printf(“In reverse order \n”);
for( i=l; i>=0; i- -)
printf(“%c\n”,ch [i]);
}
Declare pointer of pointer
Example
Main()
{int x=20;
int *px;
px =&x;
print{“%d”,*px);
}
Proto typing
Int *a ,b ,c;
B=10;
A=&b;
C=*a;
Pointer to function
Example
Main()
{
int display ( );
func-ptr =display ;
printf(“address of function display is %, fun-ptr”);
}
int display ( )
{
puts (“Wasim javed \n”);
}
Swap Function
(1) Function swap(int a, int b);
{
int temp;
temp =a;
a =b;
b= temp;
}
(2) function swap (int*a, int*bb);
{
int temp;
temp =*a;
*a =*b;
*b = temp;
}
Posted by: Wasim Javed
{
char ch [10];
int I, l;
printf(“Enter string \n”);
gets ( ch);
l= strlen (ch);
printf(“In reverse order \n”);
for( i=l; i>=0; i- -)
printf(“%c\n”,ch [i]);
}
Declare pointer of pointer
Example
Main()
{int x=20;
int *px;
px =&x;
print{“%d”,*px);
}
Proto typing
Int *a ,b ,c;
B=10;
A=&b;
C=*a;
Pointer to function
Example
Main()
{
int display ( );
func-ptr =display ;
printf(“address of function display is %, fun-ptr”);
}
int display ( )
{
puts (“Wasim javed \n”);
}
Swap Function
(1) Function swap(int a, int b);
{
int temp;
temp =a;
a =b;
b= temp;
}
(2) function swap (int*a, int*bb);
{
int temp;
temp =*a;
*a =*b;
*b = temp;
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
Problem 4
Main()
{
char source [ ] = “folks”, target[30] =”Hello”;
strcat( target ,source)
printf(source =%s\n”, source );
printf(“target =%s \n”,target);
}
Posted by: Wasim Javed
{
char source [ ] = “folks”, target[30] =”Hello”;
strcat( target ,source)
printf(source =%s\n”, source );
printf(“target =%s \n”,target);
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
Problem 3
Main()
{
char source [ ] =”Hello”;
char target [20];
strcpy (target , source);
printf(%s %s “, source , target );
}
Posted by: Wasim Javed
{
char source [ ] =”Hello”;
char target [20];
strcpy (target , source);
printf(%s %s “, source , target );
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
Problem 2
Main()
{
char arr[ ] =”Wasim”
int l 1, l2;
l 1=strlen (arr);
l 2=strlen(Hello How are you\n”);
printf(“string =%s length =%d\n”,arr ,[1);
printf(“string =%s length =%d\n”, Hello How are you ,l 2);
}
Posted by: Wasim Javed
{
char arr[ ] =”Wasim”
int l 1, l2;
l 1=strlen (arr);
l 2=strlen(Hello How are you\n”);
printf(“string =%s length =%d\n”,arr ,[1);
printf(“string =%s length =%d\n”, Hello How are you ,l 2);
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
Problem 1
Main()
{
char arr[ ] =”Wasim”
int l 1, l2;
l 1=strlen (arr);
l 2=strlen(Hello How are you\n”);
printf(“string =%s length =%d\n”,arr ,[1);
printf(“string =%s length =%d\n”, Hello How are you ,l 2);
}
Posted by: Wasim Javed
{
char arr[ ] =”Wasim”
int l 1, l2;
l 1=strlen (arr);
l 2=strlen(Hello How are you\n”);
printf(“string =%s length =%d\n”,arr ,[1);
printf(“string =%s length =%d\n”, Hello How are you ,l 2);
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
To remove a specified character.
Main()
{
char s[80];
int p;
printf(“Type string and position to removed \n”);
gets ( s );
scanf(“%d”,&p);
strcpy (&s[p], &[p+1] );
puts (s);
}
Posted by: Wasim Javed
{
char s[80];
int p;
printf(“Type string and position to removed \n”);
gets ( s );
scanf(“%d”,&p);
strcpy (&s[p], &[p+1] );
puts (s);
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
WAP to read a sentence and print all lower case to upper case and upper case to lower case.
Main()
{
char s[32];
int I,l;
printf(“Enter Sentence\n”);
gets( s);
l=strlen( s);
for(i=0 ;i<= l;i++)
{
if (( s[i]>=’a’ && (s[i]<=’z’)
s[i]- =32;
s[i]+=32;
}
puts(s);
}
Posted by: Wasim Javed
{
char s[32];
int I,l;
printf(“Enter Sentence\n”);
gets( s);
l=strlen( s);
for(i=0 ;i<= l;i++)
{
if (( s[i]>=’a’ && (s[i]<=’z’)
s[i]- =32;
s[i]+=32;
}
puts(s);
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
WAP to read a sentence and count a specific letter (LOOP)
Main()
{
char s[30],ch;
int c,l,t=0;
printf(“Enter letter to counted\n”);
ch =getche();
l = strlen( s);
for(i=0 ;i<=l ;I ++)
{
if(s[i] = =c)
t++;
}
printf(“%c comes %d times “,ch ,t);
}
Posted by: Wasim Javed
{
char s[30],ch;
int c,l,t=0;
printf(“Enter letter to counted\n”);
ch =getche();
l = strlen( s);
for(i=0 ;i<=l ;I ++)
{
if(s[i] = =c)
t++;
}
printf(“%c comes %d times “,ch ,t);
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
Read a sentence and count vowel ,uppercase to lower case
main()
{
char s[20];
int v, l , u ,l g;
gets (s);
lg= strlen (s)
for (i=0; i<=lg ;i++)
{
if (s [i]>= ‘A’ && s[i]<= ‘Z’)
u++;
if( s[i]>=’a’ && s[i]<=’z’)
l++;
if (s [i] ==’a’)II s[i]==’z’) II( s[i] == ‘I’) II(s[i] ==’o’) II(s[i] = =’u’)
v++;
}
printf (“Total upper case letter = %d”, u);
printf(“Total lower case letter = %d”, u);
printf(“Total vowel case letter =%d “,u);
}
Posted by: Wasim Javed
{
char s[20];
int v, l , u ,l g;
gets (s);
lg= strlen (s)
for (i=0; i<=lg ;i++)
{
if (s [i]>= ‘A’ && s[i]<= ‘Z’)
u++;
if( s[i]>=’a’ && s[i]<=’z’)
l++;
if (s [i] ==’a’)II s[i]==’z’) II( s[i] == ‘I’) II(s[i] ==’o’) II(s[i] = =’u’)
v++;
}
printf (“Total upper case letter = %d”, u);
printf(“Total lower case letter = %d”, u);
printf(“Total vowel case letter =%d “,u);
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
Program
main()
{
char name[25];
printf” Enter your name\n”);
scanf(“Hello %s !”, name );
}
Posted by: Wasim Javed
{
char name[25];
printf” Enter your name\n”);
scanf(“Hello %s !”, name );
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
Program to display a string
main()
{
char name[ ]=”Wasim javed “;
int l;
for(i=0 ;i<=7 ;i++)
printf (“%c”, name [i]);
}
Posted by: Wasim Javed
{
char name[ ]=”Wasim javed “;
int l;
for(i=0 ;i<=7 ;i++)
printf (“%c”, name [i]);
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
Sorting in Descending order
main()
{
int l[30],I, j, t;
for(i=1 ;i<=10;i++)
{
printf(Enter a number\n”);
scanf(“%d,&l[l]);
}
for(i=1 <10;i++)
if( j=l+;j<=10;j++)
if(l[i]>l[j=1])
{
t=l[i];
l[i]=l[i];
l[j+1]=t;
}
printf(sorted list\n”);
for(i=1 ;i<=10;j++)
printf(“%d\n”,l[i]);
}
Posted by: Wasim Javed
{
int l[30],I, j, t;
for(i=1 ;i<=10;i++)
{
printf(Enter a number\n”);
scanf(“%d,&l[l]);
}
for(i=1 <10;i++)
if( j=l+;j<=10;j++)
if(l[i]>l[j=1])
{
t=l[i];
l[i]=l[i];
l[j+1]=t;
}
printf(sorted list\n”);
for(i=1 ;i<=10;j++)
printf(“%d\n”,l[i]);
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
sorting in ascending order
main()
{
int l [30]; I; j;t;
for(i=l; i<=10; i++)
{
printf(“Enter a number \n”);
scanf(“%d”,&l[l]);
}
for(i=l; i<10; i++)
for(j=l+1; j<=10 ;j++)
if( l[l]>l[j])
{
t=l[i];
l[i]=l[i];
l[i]=t;
}
printf(“sorted list \n”);
for(i=1; i<=10; i++)
printf(“%d\n”,l[i]);
}
Posted by: Wasim Javed
{
int l [30]; I; j;t;
for(i=l; i<=10; i++)
{
printf(“Enter a number \n”);
scanf(“%d”,&l[l]);
}
for(i=l; i<10; i++)
for(j=l+1; j<=10 ;j++)
if( l[l]>l[j])
{
t=l[i];
l[i]=l[i];
l[i]=t;
}
printf(“sorted list \n”);
for(i=1; i<=10; i++)
printf(“%d\n”,l[i]);
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
Binary Search
main()
{
int a[10] ,f=0,l=0 ,loc=0, n,l,md;
printf(Enter the data in sorted order\n”);
for(l=0 ; l <10 ;l++)
{
printf((Enter no\n”);
scanf(“%d”,&a[l]);
printf(Enter no to be searched \n”);
scanf(“%d”,&n);
while(f {
mid=f+l)/2;
if(a[mid]==n);
{
loc=mid+1;
break;
}
if(a[mid]>n)
l=mid-1;
if(a[mid] f=mid+1;
}
jif(loc>=0);
printf(element is not found\n”);
else
printf(“element at location=%d\n”loc);
}
Posted by: Wasim Javed
{
int a[10] ,f=0,l=0 ,loc=0, n,l,md;
printf(Enter the data in sorted order\n”);
for(l=0 ; l <10 ;l++)
{
printf((Enter no\n”);
scanf(“%d”,&a[l]);
printf(Enter no to be searched \n”);
scanf(“%d”,&n);
while(f
mid=f+l)/2;
if(a[mid]==n);
{
loc=mid+1;
break;
}
if(a[mid]>n)
l=mid-1;
if(a[mid]
}
jif(loc>=0);
printf(element is not found\n”);
else
printf(“element at location=%d\n”loc);
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
Bubble sort
main()
{
int a[50],l,j,t,n;
pritnf(“Enter total element to be sorted\n”);
scanf(“%d”,&n);
for(l=0;l {
printf(“enter a number\n”);
scanf(“%d”,&a[l]);
}
for(l=0; l for(j=0 ;j if(a[j]< a[a+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
printf(sorted list\n”);
for(l=0; l printf(“%d\n”,a[j]);
getch();
}
Posted by: Wasim Javed
{
int a[50],l,j,t,n;
pritnf(“Enter total element to be sorted\n”);
scanf(“%d”,&n);
for(l=0;l
printf(“enter a number\n”);
scanf(“%d”,&a[l]);
}
for(l=0; l
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
printf(sorted list\n”);
for(l=0; l
getch();
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
Example of linear or sequential search
main()
{
inta[10],sr,I,loc=0, f=0;
for(i=0, i<=10,i++)
{
printf(“Enter the number\n”);
scabf(“%d”,&a[i]);
}
printf(Enter the number to search\n”);
scanf(“%d”,&sr);
i=0;
while(i<10&&f==0)
{
if(sr==a[i])
{
f=1;
loc=i+1;
}
else
i++;
}
if(f==1)
printf(“Element is found at location=%d\n”,loc);
else
printf(Element is not found\n”);
getch();
}
}
Posted by: Wasim Javed
{
inta[10],sr,I,loc=0, f=0;
for(i=0, i<=10,i++)
{
printf(“Enter the number\n”);
scabf(“%d”,&a[i]);
}
printf(Enter the number to search\n”);
scanf(“%d”,&sr);
i=0;
while(i<10&&f==0)
{
if(sr==a[i])
{
f=1;
loc=i+1;
}
else
i++;
}
if(f==1)
printf(“Element is found at location=%d\n”,loc);
else
printf(Element is not found\n”);
getch();
}
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
Sum of Dignal matrix
main()
{
int r,c sum=0 ,mat[3][3];
printf(“Enter first matrix\n”);
for(r=0; r<2; r++)
for(c=0; c<2; c++)
scanf(“%d”,&mat[r][c]);
for(r=0; r<2; r++)
{
printf(“%d/t”,mat[r][c]);
sum=sum+mat[r][c];
}
printf(“\n”);
printf(“Sum of matrix =%d\n”,sum);
getch();
}
Posted by: Wasim Javed
{
int r,c sum=0 ,mat[3][3];
printf(“Enter first matrix\n”);
for(r=0; r<2; r++)
for(c=0; c<2; c++)
scanf(“%d”,&mat[r][c]);
for(r=0; r<2; r++)
{
printf(“%d/t”,mat[r][c]);
sum=sum+mat[r][c];
}
printf(“\n”);
printf(“Sum of matrix =%d\n”,sum);
getch();
}
Posted by: Wasim Javed
Labels:
C LANGUAGE PROGRAMMING
Subscribe to:
Posts (Atom)