Tuesday, October 21, 2014

Very Very important C Programs


Convert lowercase to uppercase character
 
#include<stdio.h>

#include<conio.h>

void main()

{

char ch1,ch2;

clrscr();

printf("\n Enter character in lowercase:");

scanf("%c",&ch1);

ch2=(ch1>='a'&&ch1<='z')?('A'+ch1-'a'):ch1;

printf("\n Its Equivalent Uppercase is: %c\n",ch2);

getch();

}

OUTPUT:

Enter character in lowercase: s

Its Equivalent Uppercase is: S

Convert  uppercase to lowercase character

#include<stdio.h>

#include<conio.h>

void main()

{

char ch1,ch2;

clrscr();

printf("\n Enter character in uppercase:");

scanf("%c",&ch1);

ch2=(ch1>='A'&&ch1<='Z')?('a'+ch1-'A'):ch1;

printf("\n Its Equivalent lowercase is: %c\n",ch2);

getch();

}

OUTPUT:

Enter character in Uppercase: A

Its Equivalent lowercase is: a

Write a C program using conditional operator to find greatest of two numbers

#include<stdio.h>

#include<conio.h>

void main()

{

int x,y,z;

clrscr();

printf(" Enter value of x:");

scanf("%d",&x);

printf("\n Enter value of y:");

scanf("%d",&y);

z=(x>y)?x:y;

printf("\n %d is greater number",z);

getch();

}

 

OUTPUT:  

Enter value of x:30

Enter value of y:50

50 is greater number

Write a C program using conditional operators, determine: Whether the character entered through the keyboard is a lower case alphabet or not.

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("Enter character:");
scanf("%c",&ch);
ch>=97&&ch<=122? 
printf("Character entered is lower case"); 
printf("Character entered is not lower case");
printf("\nPress any key to exit.");
getch();
}
 
OUTPUT:  
Enter character: r
Character entered is lower case
Press any key to exit.

 

Write a C program to bitwise operator

#include<stdio.h>
#include<conio.h>
void main()
{
char c 1,c2,c3;
clrscr();
printf("enter value for c 1 and c2");
scanf("%c, %c" ,&c 1,&c2);
c3 = c 1 & c2;
printf("\n c1 & c2 = %c",c3);
c3 = c 1 | c2;
printf("\n c1| c2 = %c",c3);
c3 = c 1 ^ c2;
printf("\n i.e. c1 ^ c2 = %c",c3);
c3 = ~c1;
printf("\n compliment of c1 = %c",c3);
c3 = c1<<2;
printf("\n left shift by 2 bits c1<<2 = %c",c3);
c3 = c 1>>2;
printf("\n right shift by 2 bits c1>>2 = %c",c3);
getch();
}

Write a C program to reverse bit pattern

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
int i;
clrscr();
ch = 'd';
for(i = 128; i> 0; i = i / 2)
if(i & ch)
printf(" 1 ");
else
printf("0 ");
ch = -ch;
printf("\n ");
for(i = 128; i > 0; i = i /2)
if(i & ch)
printf(" 1 ");
else
printf("0 ");
getch();
}
 
OUTPUT:  
01100100
10011011

Write a C program to a bit shift example

 

#include<stdio.h>
#include<conio.h>
void main()
{
unsigned int i;
int j;
i = 1;
for(i = 0;j < 6;j++)
{
i= i<< I;
printf("Left shift %d: %d\n", j, i);
}
for(j = 0; j < 4; j++)
{
i= i» I;
printf("Right shift %d: %d\n",j, i);
}
getch();
}

OUTPUT:  

Left shift 0:2
Left shift 1:4
Left shift 2:8
Left shift 3: 16
Left shift 4:32
Left shift 5:64
Right shift 0:32
Right shift 1: 16
Right shift 2:8
Right shift 3:4
 
 

 


No comments:

Post a Comment