Sunday, April 14, 2013
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;
}
#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;
}
#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
Subscribe to:
Posts (Atom)