Sunday, April 14, 2013

String: Prints Initial Of Any Name

Write a C program which prints initial of any line 

#include<stdio.h>
#include<string.h>
int main()
 {
   char str[20];
   int i=0;
   printf("Enter a string: ");
   gets(str);
   printf("%c",*str);
   while(str[i]!='\0')
    {
       if(str[i]==' ')
      {
       i++;
       printf("%c",*(str+i));
      }
       i++;
   }
   return 0;
}

String: Write a c program to convert the string from lower case to upper case

Convert String from lowercase to uppercase 



#include<stdio.h>
#include<string.h>
int main()
{
  char str[50];
  int i,b=0;
  printf("Enter lowercase word: ");
  scanf("%s",str);
  b=strlen(str);
  for(i=0;i<=b;i++)
    {
        if(str[i]>=97&&str[i]<=122)
        str[i]=str[i]-32;
  }
  printf("\nThe string in Uppercase is:%s",str);
  return 0;
}

Array:Find the largest element/value form a given array using function

Find the largest element/value form a given array using function



#include<stdio.h>
#define MAX 100

int getMaxvalue();
int size;

int main()
{

    int a[MAX],max,i;
    printf("Enter the size of the array: \n");
    scanf("%d",&size);
    printf("Enter %d elements of an array: \n", size);
    for(i=0;i<size;i++)
    scanf("%d",&a[i]);
    max=getMaxvalue(a);
    printf("Largest element of an array is: %d",max);
    return 0;
}

int getMaxvalue(int a[])
{

    int i=1,max;

    max=a[0];

    while(i < size)
        {
      if(max<a[i])
           max=a[i];
      i++;
    }

    return max;
}

Pattern: Write a program to print the following output

                                   Pattern 
     Write a program to print the following output



#include<stdio.h>
main()
{
    int a=0,b,c=10,d=8,e,temp=0,res=0,i,j,n=8;


    for(b=1;b<=9;b++)
    {
        for(e=b;e<=b;e++)
        {
            temp=a*c+b;
            res=temp*d+e;
            printf("%d",temp);
            printf(" X %d + %d = %d\n",d,e,res);
            a=temp;
        }
    }
}