1:
#include <stdio.h>
/// if else basic:
int main()
{
int a;
printf("Please enter a number greter than five:");
scanf("%d",&a);
if(a>=5)
printf("%d",a*a);
else
printf("ERROR!!!\n");
return 0;
}
output: depend on your value
2:
#include <stdio.h>
///nested if else:
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
printf("The result is:%d",a);
else
printf("The result is:%d",c);
}
else
{
if(b>c)
printf("The result is:%d",b);
else
printf("The result is:%d",c);
}
return 0;
}
output: depend on your value
3:
#include <stdio.h>
///if else ladder:
int main()
{
int mark;
scanf("%d",&mark);
if(mark>=80) printf("your grade point is:+A");
else if(mark>=70) printf("your grade point is:A");
else if(mark>=60) printf("your grade point is:-A");
else if(mark>=50) printf("your grade point is:B");
else if(mark>=40) printf("your grade point is:C");
else printf("Failed!!!");
return 0;
}
output: depend on your value
Wednesday, December 31, 2014
loop(1)
1:
#include <stdio.h>
///*** compound statement:
int main()
{
int a;
if(5>10){
scanf("%d",&a);
printf("%d",5-a);
}
else
printf("(The first condition is wrong)\n");
return 0;
}
output: The first condition is wrong
2:
#include <stdio.h>
///The program will print odd number:
int main()
{
int a,b;
for(b=1;b<=5;b++){
a=(2*b-1);
printf(" %d ",a);
if(a>=9)
break;
}
return 0;
}
output: 1 3 5 7 9
3:
#include <stdio.h>
///The program will print even number:
int main()
{
int a,b;
for(b=1;b<=5;b++){
a=(2*b-1)+1;
printf(" %d ",a);
if(a>=10)
break;
}
return 0;
}
output: 2 4 6 8 10
#include <stdio.h>
///*** compound statement:
int main()
{
int a;
if(5>10){
scanf("%d",&a);
printf("%d",5-a);
}
else
printf("(The first condition is wrong)\n");
return 0;
}
output: The first condition is wrong
2:
#include <stdio.h>
///The program will print odd number:
int main()
{
int a,b;
for(b=1;b<=5;b++){
a=(2*b-1);
printf(" %d ",a);
if(a>=9)
break;
}
return 0;
}
output: 1 3 5 7 9
3:
#include <stdio.h>
///The program will print even number:
int main()
{
int a,b;
for(b=1;b<=5;b++){
a=(2*b-1)+1;
printf(" %d ",a);
if(a>=10)
break;
}
return 0;
}
output: 2 4 6 8 10
switch case
1:
#include<stdio.h>
///vowel_consonent
int main(){
char vowel;
scanf("%c",&vowel);
switch(vowel){
case 'a': printf("It is vowel");
break;
case 'e': printf("It is vowel");
break;
case 'i': printf("It is vowel");
break;
case 'o': printf("It is vowel");
break;
case 'u': printf("It is vowel");
break;
default:printf("It is consonent");
break;
}
return 0;
}
output: depend on your value
2:
#include <stdio.h>
///switch case:
int main()
{
int number;
scanf("%d",&number);
switch(number){
case 1:
printf("The number is 1\n");
break;
case 2:
printf("The number is 2\n");
break;
case 3:
printf("The number is 3\n");
break;
}
return 0;
}
output: depend on your value
#include<stdio.h>
///vowel_consonent
int main(){
char vowel;
scanf("%c",&vowel);
switch(vowel){
case 'a': printf("It is vowel");
break;
case 'e': printf("It is vowel");
break;
case 'i': printf("It is vowel");
break;
case 'o': printf("It is vowel");
break;
case 'u': printf("It is vowel");
break;
default:printf("It is consonent");
break;
}
return 0;
}
output: depend on your value
2:
#include <stdio.h>
///switch case:
int main()
{
int number;
scanf("%d",&number);
switch(number){
case 1:
printf("The number is 1\n");
break;
case 2:
printf("The number is 2\n");
break;
case 3:
printf("The number is 3\n");
break;
}
return 0;
}
output: depend on your value
Basic input & output(2)
1:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%d",12345);
return 0;
}
output: 12345
2:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%5d",123);
return 0;
}
output: 123
///***it will show two space before 123
3:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%-5d %-5d",123,456);
return 0;
}
output:123 456
4:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%05d%5d",123,456);
return 0;
}
output: 00123 456
5:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%6.2f",12.0);
return 0;
}
output: 12.00 ///***one space before 12.00
6:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%*.2f",6,12.0);
return 0;
}
output: 12.00
7:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%10.*f",2,12.0);
return 0;
}
output: 12.00 ///***five space before 12.00
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%d",12345);
return 0;
}
output: 12345
2:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%5d",123);
return 0;
}
output: 123
///***it will show two space before 123
3:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%-5d %-5d",123,456);
return 0;
}
output:123 456
4:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%05d%5d",123,456);
return 0;
}
output: 00123 456
5:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%6.2f",12.0);
return 0;
}
output: 12.00 ///***one space before 12.00
6:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%*.2f",6,12.0);
return 0;
}
output: 12.00
7:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%10.*f",2,12.0);
return 0;
}
output: 12.00 ///***five space before 12.00
Basic input & output(1)
1:
#include <stdio.h>
///***input operation:
int main(){
int a;
scanf("%4d",&a);
printf("%d",a);
return 0;
}
input: 123456
output:1234
2:
#include<stdio.h>
///***printf rules:
int main(){
int a=5,b=6;
printf("%d %d %d",b,a,a+b);
return 0;
}
output: 6 5 11
3:
#include<stdio.h>
///***printf function works from the right side
int main(){
int a,b;
printf("%d %d %d",a+b,b=5,a=4);
return 0;
}
output:9 5 4
4:
#include<stdio.h>
///***printf function works from the right side
int main(){
int a,b;
printf("%d %d %d",b=5,a=4,a+b);
return 0;
}
output: 5 4 garbage
///***because printf function works from the right side
#include <stdio.h>
///***input operation:
int main(){
int a;
scanf("%4d",&a);
printf("%d",a);
return 0;
}
input: 123456
output:1234
2:
#include<stdio.h>
///***printf rules:
int main(){
int a=5,b=6;
printf("%d %d %d",b,a,a+b);
return 0;
}
output: 6 5 11
3:
#include<stdio.h>
///***printf function works from the right side
int main(){
int a,b;
printf("%d %d %d",a+b,b=5,a=4);
return 0;
}
output:9 5 4
4:
#include<stdio.h>
///***printf function works from the right side
int main(){
int a,b;
printf("%d %d %d",b=5,a=4,a+b);
return 0;
}
output: 5 4 garbage
///***because printf function works from the right side
Math(5)
1:
#include<stdio.h>
///***subtraction without using(-)
int main(){
int a,b;
int sum;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);
sum = a + ~b + 1;
printf("Difference of two integers: %d",sum);
return 0;
}
output: depend on your value
///***(a+(-b-1)+1=ans
2:
#include<stdio.h>
///***addition without using(+)
int main(){
int a,b;
int sum;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);
sum = a - ~b -1;
printf("Sum of two integers: %d",sum);
return 0;
}
output: depend on your value
///***(a-(-b+1)+1
3:
#include <stdio.h>
///***find largest number
int main(){
int a, b, c;
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
if(a>=b && a>=c)
printf("Largest number = %d", a);
if(b>=a && b>=c)
printf("Largest number = %d", b);
if(c>=a && c>=b)
printf("Largest number = %d", c);
return 0;
}
output: depend on your value
#include<stdio.h>
///***subtraction without using(-)
int main(){
int a,b;
int sum;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);
sum = a + ~b + 1;
printf("Difference of two integers: %d",sum);
return 0;
}
output: depend on your value
///***(a+(-b-1)+1=ans
2:
#include<stdio.h>
///***addition without using(+)
int main(){
int a,b;
int sum;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);
sum = a - ~b -1;
printf("Sum of two integers: %d",sum);
return 0;
}
output: depend on your value
///***(a-(-b+1)+1
3:
#include <stdio.h>
///***find largest number
int main(){
int a, b, c;
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
if(a>=b && a>=c)
printf("Largest number = %d", a);
if(b>=a && b>=c)
printf("Largest number = %d", b);
if(c>=a && c>=b)
printf("Largest number = %d", c);
return 0;
}
output: depend on your value
Tuesday, December 30, 2014
Math(4)
1:
#include<stdio.h>
///***NCR
int main(){
int n,r,ncr;
printf("Enter any two numbers->");
scanf("%d %d",&n,&r);
ncr=fact(n)/fact(r)*fact(n-r);
printf("The NCR factor of %d and %d is %d",n,r,ncr);
return 0;
}
int fact(int n){
int i=1;
while(n!=0){
i=i*n;
n--;
}
return i;
}
output: depend on your value
2:
#include<stdio.h>
///***NPR
int main(){
int n,r,ncr;
printf("Enter any two numbers->");
scanf("%d %d",&n,&r);
ncr=fact(n)/fact(n-r);
printf("The NPR factor of %d and %d is %d",n,r,npr);
return 0;
}
int fact(int n){
int i=1;
while(n!=0){
i=i*n;
n--;
}
return i;
}
output: depend on your value
3:
#include<stdio.h>
///***Leap year
int main(){
int year;
printf("Enter any year: ");
scanf("%d",&year);
if(((year%4==0)&&(year%100!=0))||(year%400==0))
printf("%d is a leap year",year);
else
printf("%d is not a leap year",year);
return 0;
}
output: depend on your value
#include<stdio.h>
///***NCR
int main(){
int n,r,ncr;
printf("Enter any two numbers->");
scanf("%d %d",&n,&r);
ncr=fact(n)/fact(r)*fact(n-r);
printf("The NCR factor of %d and %d is %d",n,r,ncr);
return 0;
}
int fact(int n){
int i=1;
while(n!=0){
i=i*n;
n--;
}
return i;
}
output: depend on your value
2:
#include<stdio.h>
///***NPR
int main(){
int n,r,ncr;
printf("Enter any two numbers->");
scanf("%d %d",&n,&r);
ncr=fact(n)/fact(n-r);
printf("The NPR factor of %d and %d is %d",n,r,npr);
return 0;
}
int fact(int n){
int i=1;
while(n!=0){
i=i*n;
n--;
}
return i;
}
output: depend on your value
3:
#include<stdio.h>
///***Leap year
int main(){
int year;
printf("Enter any year: ");
scanf("%d",&year);
if(((year%4==0)&&(year%100!=0))||(year%400==0))
printf("%d is a leap year",year);
else
printf("%d is not a leap year",year);
return 0;
}
output: depend on your value
Math(3)
1:
#include <stdio.h>
///***celsius-farenheit
int main()
{
double celsius, farenheit;
printf("Enter the temperature in celsius: ");
scanf("%lf", &celsius);
farenheit = 1.8 * celsius + 32;
printf("Temperature in farenheit is: %.2lf\n", farenheit);
return 0;
}
output: depend on your value
2:
#include<stdio.h>
///***L.C.M
int main(){
int x,y,m,i;
printf("Insert any two number: ");
scanf("%d%d",&x,&y);
if(x>y)
m=y;
else
m=x;
for(i=m;i>=1;i--){
if(x%i==0&&y%i==0){
printf("L.C.M of two number is : %d",x*y/i) ;
break;
}
}
return 0;
}
output: depend on your value
3:
#include<stdio.h>
///***G.C.D
int main(){
int x,y,m,i;
printf("Insert any two number: ");
scanf("%d%d",&x,&y);
if(x>y)
m=y;
else
m=x;
for(i=m;i>=1;i--){
if(x%i==0&&y%i==0){
printf("GCD of two number is : %d",i) ;
break;
}
}
return 0;
}
output: depend on your value
#include <stdio.h>
///***celsius-farenheit
int main()
{
double celsius, farenheit;
printf("Enter the temperature in celsius: ");
scanf("%lf", &celsius);
farenheit = 1.8 * celsius + 32;
printf("Temperature in farenheit is: %.2lf\n", farenheit);
return 0;
}
output: depend on your value
2:
#include<stdio.h>
///***L.C.M
int main(){
int x,y,m,i;
printf("Insert any two number: ");
scanf("%d%d",&x,&y);
if(x>y)
m=y;
else
m=x;
for(i=m;i>=1;i--){
if(x%i==0&&y%i==0){
printf("L.C.M of two number is : %d",x*y/i) ;
break;
}
}
return 0;
}
output: depend on your value
3:
#include<stdio.h>
///***G.C.D
int main(){
int x,y,m,i;
printf("Insert any two number: ");
scanf("%d%d",&x,&y);
if(x>y)
m=y;
else
m=x;
for(i=m;i>=1;i--){
if(x%i==0&&y%i==0){
printf("GCD of two number is : %d",i) ;
break;
}
}
return 0;
}
output: depend on your value
Math(2)
1:
#include<stdio.h>
///***trapezium
int main(){
float b1,b2,h;
float area;
printf("Enter the size of two bases and height of the trapezium : ");
scanf("%f%f%f",&b1,&b2,&h);
area = 0.5 * ( b1 + b2 ) * h ;
printf("Area of trapezium is: %.2f",area);
return 0;
}
output:depend on your value
2:
#include<stdio.h>
#include<math.h>
///***equilateral triangle
int main(){
float a;
float area;
printf("Enter size of side of the equilateral triangle : ");
scanf("%f",&a);
area = sqrt(3)/4*(a*a);
printf("Area of equilateral triangle is: %.2f",area);
return 0;
}
output:depend on your value
3:
#include<stdio.h>
///***cube surface and volume
int main(){
float a,surface,volume;
printf("Enter size of any side of a cube : ");
scanf("%f",&a);
surface= 6 * (a * a);
volume = a * a * a;
printf("Surface area of cube is: %.2f",surface);
printf("Volume of cube is : %.2f",volume);
return 0;
}
output:depend on your value
3:
#include<stdio.h>
#define PI 3.141
///***perimeter of circle
int main()
{
float r;
printf("Enter the radius value:");
scanf("%f",&r);
printf("Area of circle : %.2f ", PI*r*r);
printf("Perimeter of the circle : %.2f ", 2*PI*r);
return 0;
}
#include<stdio.h>
///***trapezium
int main(){
float b1,b2,h;
float area;
printf("Enter the size of two bases and height of the trapezium : ");
scanf("%f%f%f",&b1,&b2,&h);
area = 0.5 * ( b1 + b2 ) * h ;
printf("Area of trapezium is: %.2f",area);
return 0;
}
output:depend on your value
2:
#include<stdio.h>
#include<math.h>
///***equilateral triangle
int main(){
float a;
float area;
printf("Enter size of side of the equilateral triangle : ");
scanf("%f",&a);
area = sqrt(3)/4*(a*a);
printf("Area of equilateral triangle is: %.2f",area);
return 0;
}
output:depend on your value
3:
#include<stdio.h>
///***cube surface and volume
int main(){
float a,surface,volume;
printf("Enter size of any side of a cube : ");
scanf("%f",&a);
surface= 6 * (a * a);
volume = a * a * a;
printf("Surface area of cube is: %.2f",surface);
printf("Volume of cube is : %.2f",volume);
return 0;
}
output:depend on your value
3:
#include<stdio.h>
#define PI 3.141
///***perimeter of circle
int main()
{
float r;
printf("Enter the radius value:");
scanf("%f",&r);
printf("Area of circle : %.2f ", PI*r*r);
printf("Perimeter of the circle : %.2f ", 2*PI*r);
return 0;
}
Math(1)
1:
#include<stdio.h>
#include<math.h>
///***triangle
int main(){
float a,b,c;
float s,area;
printf("Enter size of each sides of triangle:");
scanf("%f%f%f",&a,&b,&c);
s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of triangle is: %.2f",area);
return 0;
}
output: depend on your value
2:
#include<stdio.h>
///***rectangle
int main(){
float l,w;
float area;
printf("Enter size of each sides of the rectangle : ");
scanf("%f%f",&l,&w);
area = l * w;
printf("Area of rectangle is: %.2f",area);
return 0;
}
output: depend on your value
3:
#include <stdio.h>
#define PI 3.141
///***circle
int main(){
float r, area;
printf("Please enter Radius of circle: ");
scanf("%f", &r);
area = PI * r * r;
printf("Area of cirle is:%.2f\n", area);
return 0;
}
output: depend on your value
#include<stdio.h>
#include<math.h>
///***triangle
int main(){
float a,b,c;
float s,area;
printf("Enter size of each sides of triangle:");
scanf("%f%f%f",&a,&b,&c);
s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of triangle is: %.2f",area);
return 0;
}
output: depend on your value
2:
#include<stdio.h>
///***rectangle
int main(){
float l,w;
float area;
printf("Enter size of each sides of the rectangle : ");
scanf("%f%f",&l,&w);
area = l * w;
printf("Area of rectangle is: %.2f",area);
return 0;
}
output: depend on your value
3:
#include <stdio.h>
#define PI 3.141
///***circle
int main(){
float r, area;
printf("Please enter Radius of circle: ");
scanf("%f", &r);
area = PI * r * r;
printf("Area of cirle is:%.2f\n", area);
return 0;
}
output: depend on your value
conditional logic(2)
1:
#include <stdio.h>
///***or condition
int main()
{
int num =3;
if(num >= 1 || num <= 10) {
printf("yes\n");
}
else {
printf("no\n");
}
return 0;
}
output: yes
2:
#include <stdio.h>
///***and condition
int main()
{
int num = -5;
if(num >= 1 && num <= 10) {
printf("yes\n");
}
else {
printf("no\n");
}
return 0;
}
output: no
3:
#include <stdio.h>
///***check upeer and lower case letter
int main()
{
char ch = 'M';
if(ch >= 'a' && ch <= 'z') {
printf("It is lower case\n");
}
else if(ch >= 'A' && ch <= 'Z') {
printf("It is upper case\n");
}
return 0;
}
output: It is upper case
#include <stdio.h>
///***or condition
int main()
{
int num =3;
if(num >= 1 || num <= 10) {
printf("yes\n");
}
else {
printf("no\n");
}
return 0;
}
output: yes
2:
#include <stdio.h>
///***and condition
int main()
{
int num = -5;
if(num >= 1 && num <= 10) {
printf("yes\n");
}
else {
printf("no\n");
}
return 0;
}
output: no
3:
#include <stdio.h>
///***check upeer and lower case letter
int main()
{
char ch = 'M';
if(ch >= 'a' && ch <= 'z') {
printf("It is lower case\n");
}
else if(ch >= 'A' && ch <= 'Z') {
printf("It is upper case\n");
}
return 0;
}
output: It is upper case
conditional logic(1)
1:
#include <stdio.h>
///*** positive or negative or zero:
int main()
{
int num;
printf("Enter a number:");
scanf("%d",&num);
if(num > 0) {
printf("The number is positive\n");
}
if(num == 0) {
printf("The number is zero\n");
}
if(num<0) {
printf("The number is negative\n");
}
return 0;
}
output: depend on your value
2:
#include <stdio.h>
///*** prove even odd
int main()
{
int number,sum;
printf("Enter a number:");
scanf("%d",&number);
sum=number%2;
if(sum==0) {
printf("The number is even\n");
}
else {
printf("The number is odd\n");
}
return 0;
}
output: depend on your value
3:
#include <stdio.h>
///*** prove vowel consonant
int main()
{
char alphabet;
printf("Enter a alphabet:");
scanf("%c",&alphabet);
if(alphabet=='a'){
printf("It is vowel");
}
if(alphabet=='e'){
printf("It is vowel");
}
if(alphabet=='i'){
printf("It is vowel");
}
if(alphabet=='o'){
printf("It is vowel");
}
if(alphabet=='u'){
printf("It is vowel");
}
else {
printf("It is consonant");
}
return 0;
}
output: depend on your value
#include <stdio.h>
///*** positive or negative or zero:
int main()
{
int num;
printf("Enter a number:");
scanf("%d",&num);
if(num > 0) {
printf("The number is positive\n");
}
if(num == 0) {
printf("The number is zero\n");
}
if(num<0) {
printf("The number is negative\n");
}
return 0;
}
output: depend on your value
2:
#include <stdio.h>
///*** prove even odd
int main()
{
int number,sum;
printf("Enter a number:");
scanf("%d",&number);
sum=number%2;
if(sum==0) {
printf("The number is even\n");
}
else {
printf("The number is odd\n");
}
return 0;
}
output: depend on your value
3:
#include <stdio.h>
///*** prove vowel consonant
int main()
{
char alphabet;
printf("Enter a alphabet:");
scanf("%c",&alphabet);
if(alphabet=='a'){
printf("It is vowel");
}
if(alphabet=='e'){
printf("It is vowel");
}
if(alphabet=='i'){
printf("It is vowel");
}
if(alphabet=='o'){
printf("It is vowel");
}
if(alphabet=='u'){
printf("It is vowel");
}
else {
printf("It is consonant");
}
return 0;
}
output: depend on your value
operator(6)
1:
#include <stdio.h>
///conditional operator:
int main ()
{
int a,b,c;
a=5;b=10;
c=(a<b)? a:b;
printf("%d",c);
return 0;
}
output: 5
2:
#include <stdio.h>
///conditional operator:
int main ()
{
int a,b,c;
a=5;b=10;
c=(a>b)? a:b;
printf("%d",c);
return 0;
}
output: 10
3:
#include <stdio.h>
///comma operator:
int main()
{
int a,b,cma;
cma=(a=7,b=5,a-b);
printf("%d",cma);
return 0;
}
output: 2
4:
#include <stdio.h>
int main()
{
int a=5,b=6;
printf("%d %d %d",a,b,a+b);
return 0;
}
output: 5 6 11
#include <stdio.h>
///conditional operator:
int main ()
{
int a,b,c;
a=5;b=10;
c=(a<b)? a:b;
printf("%d",c);
return 0;
}
output: 5
2:
#include <stdio.h>
///conditional operator:
int main ()
{
int a,b,c;
a=5;b=10;
c=(a>b)? a:b;
printf("%d",c);
return 0;
}
output: 10
3:
#include <stdio.h>
///comma operator:
int main()
{
int a,b,cma;
cma=(a=7,b=5,a-b);
printf("%d",cma);
return 0;
}
output: 2
4:
#include <stdio.h>
int main()
{
int a=5,b=6;
printf("%d %d %d",a,b,a+b);
return 0;
}
output: 5 6 11
operator(5)
Bitwise operator
1:
#include <stdio.h>
///bitwise operator:
int main()
{
int a,b;
a=5;b=6;
printf("%d %d %d",a&b,a|b,a^b);
return 0;
}
output:4 7 3
2:
#include <stdio.h>
///left shift -right shift
int main()
{
int a;
a=3;
printf("%d %d",a<<1,a>>1);
return 0;
}
output: 6 1
3:
#include <stdio.h>
///conditional operator:
int main()
{
int a,b;
a=5;b=10;
(a<b)? printf("%d",a) : printf("%d",b);
return 0;
}
output: 5
1:
#include <stdio.h>
///bitwise operator:
int main()
{
int a,b;
a=5;b=6;
printf("%d %d %d",a&b,a|b,a^b);
return 0;
}
output:4 7 3
2:
#include <stdio.h>
///left shift -right shift
int main()
{
int a;
a=3;
printf("%d %d",a<<1,a>>1);
return 0;
}
output: 6 1
3:
#include <stdio.h>
///conditional operator:
int main()
{
int a,b;
a=5;b=10;
(a<b)? printf("%d",a) : printf("%d",b);
return 0;
}
output: 5
operator(4)
1:
#include <stdio.h>
///logical operator:
int main()
{
int ssc,hsc,prove;
ssc=5;hsc=5;
prove=(ssc==5 || hsc==6);
printf("%d",prove);
return 0;
}
output: 1
2:
#include <stdio.h>
///logical operator:
int main()
{
int ssc,hsc,prove;
ssc=5;hsc=5;
prove=!(ssc==5);
printf("%d",prove);
return 0;
}
output: 0
3:
#include <stdio.h>
///logical operator:
int main()
{
int ssc,hsc,prove;
ssc=5;hsc=5;
prove=!(ssc==5,hsc==5);
printf("%d",prove);
return 0;
}
output: 0
4:
#include <stdio.h>
///logical operator:
int main()
{
int ssc,hsc,prove;
ssc=5;hsc=5;
prove=(ssc==5 && hsc==5);
printf("%d",prove);
return 0;
}
output:1
5:
#include <stdio.h>
///logical operator:
int main()
{
int ssc,hsc,prove;
ssc=5;hsc=5;
prove=(ssc==5 || hsc==6);
printf("%d",prove);
return 0;
}
output: 1
/***condition true=1
/***condition false=0
#include <stdio.h>
///logical operator:
int main()
{
int ssc,hsc,prove;
ssc=5;hsc=5;
prove=(ssc==5 || hsc==6);
printf("%d",prove);
return 0;
}
output: 1
2:
#include <stdio.h>
///logical operator:
int main()
{
int ssc,hsc,prove;
ssc=5;hsc=5;
prove=!(ssc==5);
printf("%d",prove);
return 0;
}
output: 0
3:
#include <stdio.h>
///logical operator:
int main()
{
int ssc,hsc,prove;
ssc=5;hsc=5;
prove=!(ssc==5,hsc==5);
printf("%d",prove);
return 0;
}
output: 0
4:
#include <stdio.h>
///logical operator:
int main()
{
int ssc,hsc,prove;
ssc=5;hsc=5;
prove=(ssc==5 && hsc==5);
printf("%d",prove);
return 0;
}
output:1
5:
#include <stdio.h>
///logical operator:
int main()
{
int ssc,hsc,prove;
ssc=5;hsc=5;
prove=(ssc==5 || hsc==6);
printf("%d",prove);
return 0;
}
output: 1
/***condition true=1
/***condition false=0
Monday, December 29, 2014
operator(3)
1:
#include <stdio.h>
///***decrement operator:
int main()
{
int a,b;
a=7;
a--;
printf("%d\n",a);
--a;
printf("%d\n",a);
b=a--;
printf("%d %d\n",a,b);
b=--a;
printf("%d %d\n",a,b);
return 0;
}
output: 6
5
4 5
3 3
2:
#include <stdio.h>
///relation operator:
int main()
{
int a=5,b=6,condition;
condition=a>b; ///if-true=1,false=0
printf("%d",condition);
return 0;
}
///*** !=not equal
///*** c=a>=b---wrong--0
///*** c=a<=b---true--1
///*** c=a!=b---true--1
///***c=a==b---false-0
///*** a=b=c ---6
output: 0 ///***condition is wrong so ans is 0
3:
#include <stdio.h>
///***logical operator:
int main()
{
int ssc,hsc,prove;
ssc=5;hsc=5;
prove=(ssc==5 && hsc==5);
printf("%d",prove);
return 0;
}
output: 1
#include <stdio.h>
///***decrement operator:
int main()
{
int a,b;
a=7;
a--;
printf("%d\n",a);
--a;
printf("%d\n",a);
b=a--;
printf("%d %d\n",a,b);
b=--a;
printf("%d %d\n",a,b);
return 0;
}
output: 6
5
4 5
3 3
2:
#include <stdio.h>
///relation operator:
int main()
{
int a=5,b=6,condition;
condition=a>b; ///if-true=1,false=0
printf("%d",condition);
return 0;
}
///*** !=not equal
///*** c=a>=b---wrong--0
///*** c=a<=b---true--1
///*** c=a!=b---true--1
///***c=a==b---false-0
///*** a=b=c ---6
output: 0 ///***condition is wrong so ans is 0
3:
#include <stdio.h>
///***logical operator:
int main()
{
int ssc,hsc,prove;
ssc=5;hsc=5;
prove=(ssc==5 && hsc==5);
printf("%d",prove);
return 0;
}
output: 1
operator(2)
1:
#include <stdio.h>
int main()
{
float a,b,sum;
a=5;b=2;
sum=a/b;
printf("%.0f / %.0f=%.2f",a,b,sum);
return 0;
}
output: 2.50
2:
#include <stdio.h>
///***assignment operator:
int main()
{
int a=5,b=6;
a+=5;
a-=b;
printf("%d %d",a,b);
return 0;
}
output: 4 6
3:
#include <stdio.h>
///***increment operator:
int main()
{
int a,b;
a=5;
a++;
printf("%d\n",a);
++a;
printf("%d\n",a);
b=a++;
printf("%d %d\n",a,b);
b=++a;
printf("%d %d\n",a,b);
return 0;
}
output: 6
7
8 7
9 9
#include <stdio.h>
int main()
{
float a,b,sum;
a=5;b=2;
sum=a/b;
printf("%.0f / %.0f=%.2f",a,b,sum);
return 0;
}
output: 2.50
2:
#include <stdio.h>
///***assignment operator:
int main()
{
int a=5,b=6;
a+=5;
a-=b;
printf("%d %d",a,b);
return 0;
}
output: 4 6
3:
#include <stdio.h>
///***increment operator:
int main()
{
int a,b;
a=5;
a++;
printf("%d\n",a);
++a;
printf("%d\n",a);
b=a++;
printf("%d %d\n",a,b);
b=++a;
printf("%d %d\n",a,b);
return 0;
}
output: 6
7
8 7
9 9
operator(1)
1:
operator-
///*** arithmatic operator
///***1.integer arithmatic= +,-,*,/,%
///***2.real arithmatic(float,double-forall)=(+,-,/,*)
2:
#include <stdio.h>
///***integer arithmatic.
int main()
{
int a,b,sum;
printf("please enter 1st number:",a);
scanf("%d",&a);
printf("please enter 2nd number:",b);
scanf("%d",&b);
sum= a+b;
printf("%d + %d =%d",a,b,sum);
return 0;
}
input: 5 2
output: 7
3:
#include <stdio.h>
///***integer arithmatic:(modulas)
int main()
{
int a,b,sum;
printf("please enter 1st integer:",a);
scanf("%d",&a);
printf("please enter 2nd integer:",b);
scanf("%d",&b);
sum= a%b;
printf("%d mod with %d=%d",a,b,sum);
return 0;
}
input: 5 2
output: 1
4:
#include <stdio.h>
int main ()
{
int a,b,c;
a=1;b=2;
printf("before interchange a=%d b=%d\n",a,b);
c=a;
a=b;
b=c;
printf("after interchange a=%d b=%d",a,b);
return 0;
}
output: a=2
b=1
operator-
///*** arithmatic operator
///***1.integer arithmatic= +,-,*,/,%
///***2.real arithmatic(float,double-forall)=(+,-,/,*)
2:
#include <stdio.h>
///***integer arithmatic.
int main()
{
int a,b,sum;
printf("please enter 1st number:",a);
scanf("%d",&a);
printf("please enter 2nd number:",b);
scanf("%d",&b);
sum= a+b;
printf("%d + %d =%d",a,b,sum);
return 0;
}
input: 5 2
output: 7
3:
#include <stdio.h>
///***integer arithmatic:(modulas)
int main()
{
int a,b,sum;
printf("please enter 1st integer:",a);
scanf("%d",&a);
printf("please enter 2nd integer:",b);
scanf("%d",&b);
sum= a%b;
printf("%d mod with %d=%d",a,b,sum);
return 0;
}
input: 5 2
output: 1
4:
#include <stdio.h>
int main ()
{
int a,b,c;
a=1;b=2;
printf("before interchange a=%d b=%d\n",a,b);
c=a;
a=b;
b=c;
printf("after interchange a=%d b=%d",a,b);
return 0;
}
output: a=2
b=1
Sunday, December 28, 2014
Datatype(4)
1:
#include <stdio.h>
int main()
{
int a, b, sum;
a = 10;
b = 2;
sum = a / b;
printf("%d\n", sum);
return 0;
}
output: 5
2:
#include <stdio.h>
int main()
{
int a, b, sum;
a = 10;
b = 2;
sum = a - b;
printf("%d\n", sum);
return 0;
}
output: 8
3:
#include <stdio.h>
int main()
{
double a, b, sum;
a = 5;
b = 2;
sum = a / b;
printf("%.2lf\n", sum);
return 0;
}
output: 2.50
/***here %lf is double idientifier***/
4:
#include <stdio.h>
int main()
{
double a, b, sum;
a = 2.5;
b = 2;
sum = a * b;
printf("%.2lf\n", sum);
return 0;
}
output: 5.00
#include <stdio.h>
int main()
{
int a, b, sum;
a = 10;
b = 2;
sum = a / b;
printf("%d\n", sum);
return 0;
}
output: 5
2:
#include <stdio.h>
int main()
{
int a, b, sum;
a = 10;
b = 2;
sum = a - b;
printf("%d\n", sum);
return 0;
}
output: 8
3:
#include <stdio.h>
int main()
{
double a, b, sum;
a = 5;
b = 2;
sum = a / b;
printf("%.2lf\n", sum);
return 0;
}
output: 2.50
/***here %lf is double idientifier***/
4:
#include <stdio.h>
int main()
{
double a, b, sum;
a = 2.5;
b = 2;
sum = a * b;
printf("%.2lf\n", sum);
return 0;
}
output: 5.00
Datatype(3-ASCII value)
1:
#include <stdio.h>
///***ASCII value:
int main()
{
char num;
num=78;
printf("%c",num);
return 0;
}
output: N
/***here %c identifies 78th number ASCII value which is N ***/
2:
int main()
{
char num;
num='N';
printf("%c",78);/// ***here printf will show character value of num
return 0;
}
output: N
#include <stdio.h>
///***ASCII value:
int main()
{
char num;
num=78;
printf("%c",num);
return 0;
}
output: N
/***here %c identifies 78th number ASCII value which is N ***/
2:
int main()
{
char num;
num='N';
printf("%c",78);/// ***here printf will show character value of num
return 0;
}
output: N
Datatype(2-sizeof)
1:
#include <stdio.h>
///***size of character:
int main()
{
char ch;
ch=5;
printf("char=%d byte",sizeof(char));
return 0;
}
output: 1
2:
#include <stdio.h>
///***size of integer:
int main()
{
int ch;
ch=5;
printf("int=%d byte",sizeof(int));
return 0;
}
output: 4
3:
#include <stdio.h>
///***size of float:
int main()
{
float ch;
ch=5;
printf("float=%d byte",sizeof(float));
return 0;
}
output: 4
4:
#include <stdio.h>
///***size of double:
int main()
{
double ch;
ch=5;
printf("Double=%d byte",sizeof(double));
return 0;
}
output: 8
/***little discussion:
#char= 1 byte=8 bit
int= 4 byte=32 bit
float= 4 byte=32 bit
double= 8 byte=64 bit
#include <stdio.h>
///***size of character:
int main()
{
char ch;
ch=5;
printf("char=%d byte",sizeof(char));
return 0;
}
output: 1
2:
#include <stdio.h>
///***size of integer:
int main()
{
int ch;
ch=5;
printf("int=%d byte",sizeof(int));
return 0;
}
output: 4
3:
#include <stdio.h>
///***size of float:
int main()
{
float ch;
ch=5;
printf("float=%d byte",sizeof(float));
return 0;
}
output: 4
4:
#include <stdio.h>
///***size of double:
int main()
{
double ch;
ch=5;
printf("Double=%d byte",sizeof(double));
return 0;
}
output: 8
/***little discussion:
#char= 1 byte=8 bit
int= 4 byte=32 bit
float= 4 byte=32 bit
double= 8 byte=64 bit
Datatype(1)
1:
#include <stdio.h>
/***Datatype(1)
int main()
{
int a,b,sum;
a=3,b=6;
sum = a + b;
printf(" %d\n", sum);
return 0;
}
output: 9
/***guys /n using for new line***/
/***here %d is an identifier of int***/
2:
#include <stdio.h>
/***Datatype(1)
int main()
{
int a,b;
a=6;
b=6+a;
printf("%d\n",b);
return 0;
}
output: 12
3:
#include <stdio.h>
/***Datatype(1)
int main()
{
int a=5,b=6,sum;
sum=a*b;
printf("The multiplication is:%d\n",sum);
return 0;
}
output: 30
#include <stdio.h>
/***Datatype(1)
int main()
{
int a,b,sum;
a=3,b=6;
sum = a + b;
printf(" %d\n", sum);
return 0;
}
output: 9
/***guys /n using for new line***/
/***here %d is an identifier of int***/
2:
#include <stdio.h>
/***Datatype(1)
int main()
{
int a,b;
a=6;
b=6+a;
printf("%d\n",b);
return 0;
}
output: 12
3:
#include <stdio.h>
/***Datatype(1)
int main()
{
int a=5,b=6,sum;
sum=a*b;
printf("The multiplication is:%d\n",sum);
return 0;
}
output: 30
c programming(start-printf)
1:
#include<stdio.h>
int main( )
{
printf("Hello world");
return 0;
}
output: Hello world
2:(without using semicolon(;))
#include<stdio.h>
void main( )
{
while(!printf("Hello world") ){
}
}
3:
#include <stdio.h>
///***it will change your bg clor and font color:
int main()
{
system("color 0C");
printf("Hello world");
return 0;
}
output: Hello world
4:
#include <stdio.h>
///***without using semicolon
void main()
{
system("color 0C");
if(printf("Hello world")){
}
}
output: Hello world
5:
#include <stdio.h>
///***without using semicolon
void main()
{
system("color 0C");
switch(printf("Hello world)){
}
}
output: Hello world
///***here 0 use for background color and C is use for font color:follow this pattern
///***0=Black A=Light green
1= Blue B=Light Aqua
2=Green C=Light Red
3=Aqua D=Light Purple
4=Red E=Light Yellow
5=Purple F=Bright White
6=Yellow
7=White
8=Gray
9=Light Blue
#include<stdio.h>
int main( )
{
printf("Hello world");
return 0;
}
output: Hello world
2:(without using semicolon(;))
#include<stdio.h>
void main( )
{
while(!printf("Hello world") ){
}
}
3:
#include <stdio.h>
///***it will change your bg clor and font color:
int main()
{
system("color 0C");
printf("Hello world");
return 0;
}
output: Hello world
4:
#include <stdio.h>
///***without using semicolon
void main()
{
system("color 0C");
if(printf("Hello world")){
}
}
output: Hello world
5:
#include <stdio.h>
///***without using semicolon
void main()
{
system("color 0C");
switch(printf("Hello world)){
}
}
output: Hello world
///***here 0 use for background color and C is use for font color:follow this pattern
///***0=Black A=Light green
1= Blue B=Light Aqua
2=Green C=Light Red
3=Aqua D=Light Purple
4=Red E=Light Yellow
5=Purple F=Bright White
6=Yellow
7=White
8=Gray
9=Light Blue
My Vision
Hi there! I am Koushik. I'm in love with my computer. <3 Solving problems is
my passion and I've come to realize how easy it is to do so with computer
programming.
I work daily on problems and solve a tiny chunk of them bit by bit. Learning
new things along the way I've seen ways to look at things. It's a form of
art to me or maybe more. With all the help I get from the internet, I wish
to share what ever I learned even if it is very little.
I'm currently working with the 'C' programming language. Hope everyone finds
my solutions interesting. I'll be happy if these helped even a
person in this world.
Adios :)
my passion and I've come to realize how easy it is to do so with computer
programming.
I work daily on problems and solve a tiny chunk of them bit by bit. Learning
new things along the way I've seen ways to look at things. It's a form of
art to me or maybe more. With all the help I get from the internet, I wish
to share what ever I learned even if it is very little.
I'm currently working with the 'C' programming language. Hope everyone finds
my solutions interesting. I'll be happy if these helped even a
person in this world.
Adios :)
Subscribe to:
Posts (Atom)