C Programs Page 4

C Programs Page 4

C Programs Page 4
To view other topics related to Computer. Click Here.

Write a program to exchange the values of two variables using assignment and print the exchanged values on the screen( Arithmetic assignment)

main( )

{

int a,b,c;

clrscr();

a=200;

b=100;

c=a;

a=b;

b=c;

printf(“value of a =%d/n”,a);

printf(“ value of b=%d/n”,b);

}

Write a program to find out the greater value from two given values(NOT Operator)

main( )

{

int s,a;

printf(“/n Enter 1st integer value “);

scanf(“%d”,&s);

printf(“/n Enter 2nd Value”);

scanf(“%d”,&a);

! (s>a)? s:a;

printf( “1st is greater”): printf (“ 2nd is greater “);

getch();

}

Write a program in C to implement the “OR” operator (OR Operator)

main( )

{

int s;

char op;

pintf(“Enter Any Character/n”);

sanf(“%c”,&op);

pintf(“Enter Any integer value/n”);

sanf(“%d”,&s);

if((s>o)ll (op==’y’)ll (op==’n’))

printf(“ok, condition is True”);

else

printf(“All relational expression are false”);

}

Write a program to find out the largest number from three given numbers(AND Operator)

Main( )

{

int r,n,b;

clrscr();

printf(“/n Enter Three Value /n”);

Scanf(“%d %d %d”,&r, &n, &b);

If (( r>n)&& (n>b))

Printf(“1st value is greater”);

Else

If((n>r)&&(n>b))

Printf(“2nd value is greater”);

Else

Printf(“3rd value is greater”);

getch();

}

Input two values use conditional operator to find out which value is greater. Print a message on the screen to indicate the greater value

Main( )

{

int r,b,max;

clrscr();

printf(“Enter 1st value\n”);

scanf(“%d”,&r);

printf(“Enter 2nd value\n”);

scanf(“%d”,&b);

max=(r>b)? r;b;

printf(“Greater value is =%d\n”,max);

getch();

}

Write a program to perform the arithmetic operations by using all arithmetic operators. Also print the result on the screen( Arithmetic Operators)

main( )

{

int p,s,m,d,r;

p=8+2;

s=8-2;

m=8*2;

d=8/2;

r=8%3;

printf(“Addition of 8 & 2 is = %d/n”,p);

printf(“Subtraction of 8&2 is=%d/n”,s);

printf(“Multiplication of 8&2 is=%d/n”,m);

printf(“Division of 8&2 is=%d/n”,d);

printf(“Remainder of 8/2 is=%d/n”,r);

}

Post a Comment

Previous Post Next Post