Thursday, June 4, 2015

Programming Tutorial

Write a program to read a string & convert upper case alphabet to lower case & lower case to upper case.

#include<Stdio.h>
#include<conio.h>
                Main ()
{
                Int len, I;
                Char a [50];
                Printf(“enter a string);
                Gets(a);
                Len= strlen (a);
                For (i=0; i<len; i++)
                {
                If (a[i] >= ‘A’ && a[i]<=’Z’)
                a[i]= toupper (a[i]);
                else if( a[i]>= ‘A’ &&  a[i]<= ‘2’);
                a[i]= tolower(a[i]);
                }
                Print(“The changed string is %”, a);
                }



Write a program to read a string & count number of words.

#include<Stdio.h>
#include<conio.h>
                Main()
{
                Int len, I;
                Char a[50];
                Printf(“enter a string”);
                Gets(a);
                Len = strien(a);
                For (i=0; i<len; i++)
                {
                If (a[i] == 32 && a [i+1]!32)
                Count = count+1;
                }
                printf(“in the number of words = % d”, count + 1);
                }




Finding string length without library function

#include<Stdio.h>
#include<conio.h>
Main()
{
                Int len  0, I;
                Char a[50];
                Printf(“enter a string”);
                Gets(a);
                For (i=0; a[i] = ’\0’, i++)
Len =len +1;
                Printf(“in string length = % d”, len);        
                }




Write a program to copy a string from one array to next without using library function strcpy.

#include<Stdio.h>
#include<conio.h>
Main()
{
                Int len  0, i;
                Char a[50] , b [50];
                Printf(“enter a string”);
                Gets(a);
                For (i=0; a[i] = ’\0’, i++)
Len =len +1;
                For (i=0; i<len; i++)
                b[i]=a[i];
                printf(“in the copied string is %s”,b);
                }



Write to reverse a string without library function strev.
#include<Stdio.h>
#include<conio.h>
Main()
{
                Int len  0, i;
                Char a[50] , t;
                Printf(“enter a string”);
                Gets(a);
                For (i=0; a[i] = ’\0’, i++)
Len =len +1;
For (i=0; i<=len-1-i];
{
T=a[i]
A[i]=a[len-1-i]
}
Printf(“in the reversedstring is %s”, a):

}

No comments:

Post a Comment