This blog consists of C and C++ programs. C and C++ programming is the basics to learn any programming language. Most of the programs are provided with their respective outputs. This blog also contains Data Structures programs using Object-Oriented Programming (C++). Some of the best books for learning C and C++ programming are also mentioned.

Showing posts with label Program. Show all posts
Showing posts with label Program. Show all posts

Friday, 1 November 2013

C program for Conditional Operator (Ternary Operators)

C program for Conditional Operators (Ternary Operators):

#include<stdio.h>
#include<conio.h>
main()
{
int a=10, b=20, small;
clrscr();
small=(a<b)?a:b;
printf("The small value = %d", small);
getch();
}

C program for Assignment Operator

C program for Assignment Operator:

#include<stdio.h>
#include<conio.h>
main()
{
int a=10;
clrscr();
printf("\n a+=10=> %d",a+=10);
printf("\n a-=10=> %d",a-=10);
printf("\n a*=10=> %d",a*=10);
printf("\n a/=10=> %d",a/=10);
printf("\n a%=10=> %d",a%=10);
getch();
}

C program for Logical Operators

C program for Logical Operators:

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,d,e,f;
clrscr();
printf("Enter the value of a:");
scanf("%d",&a);
printf("Enter the value of b:");
scanf("%d",&b);
printf("Enter the value of c:");
scanf("%d",&c);
d=(a>b)&&(a>c);
e=(a>b)||(a>c);
f=!(a>b);
printf("\nAND=%d",d);
printf("\nOR=%d",e);
printf("\nNOT=%d",f);
getch();
}

C program for Relational Operators

C program for Relational Operators:

#include<stdio.h>
#include<conio.h>
main()
{
int a=10, b=4;
clrscr();
printf("\n(%d>%d) = %d",a,b,a>b);
printf("\n(%d<%d) = %d",a,b,a<b);
printf("\n(%d>=%d) = %d",a,b,a>=b);
printf("\n(%d<=%d) = %d",a,b,a<=b);
printf("\n(%d==%d) = %d",a,b,a==b);
printf("\n(%d!=%d) = %d",a,b,a!=b);
getch();
}

C program for Unary Operators

C program for Unary Operators:

#include<stdio.h>
#include<conio.h>
main(){
int a=9;
clrscr();
printf("\na=%d",a);
printf("\na=%d",a++);
printf("\na=%d",a);
printf("\na=%d",++a);
printf("\na=%d",a);
printf("\na=%d",a--);
printf("\na=%d",a);
printf("\na=%d",--a);
printf("\na=%d",a);
getch();
}

C program for Arithmetic Operators

C Program for Arithmetic Operators:

#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
clrscr();
printf("Enter the value of a:");
scanf("%d", &a);
printf("\nEnter the value of b:");
scanf("%d", &b);
printf("\nThe Addition value is = %d", a+b);
printf("\nThe Subtraction value is = %d", a-b);
printf("\nThe Multiplication value is = %d", a*b);
printf("\nThe Division value is = %d", a/b);
printf("\nThe Modulus value is = %d", a%b);
getch();
}