Showing posts with label Numbers. Show all posts
Program to tell whether entered number is +ive,-ive or Zero
//Program to tell whether entered number is +ive,-ive or Zero
#include<stdio.h>
#include<conio.h>
//main function
void main()
{
int x;
printf("Enter x:");
scanf("%d",&x);
if(x==0)
{
printf("The number is Zero");
}
else if(x>0)
{
printf("The number is Positive");
}
else if(x<0)
{
printf("The number is Negative");
}
getch();
}
#include<stdio.h>
#include<conio.h>
//main function
void main()
{
int x;
printf("Enter x:");
scanf("%d",&x);
if(x==0)
{
printf("The number is Zero");
}
else if(x>0)
{
printf("The number is Positive");
}
else if(x<0)
{
printf("The number is Negative");
}
getch();
}
Saturday, 17 January 2015
Posted by Unknown
Program/code to swap two numbers in C language
This code demonstrate the swaping of two numbers.
//program to swap two numbers input by user
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,a;
printf("Enter x:");
scanf("%d",&x);
printf("Enter y:");
scanf("%d",&y);
a=x;
x=y;
y=a;
printf("x is %d\n",x);
printf("y is %d",y);
getch();
}
//program to swap two numbers input by user
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,a;
printf("Enter x:");
scanf("%d",&x);
printf("Enter y:");
scanf("%d",&y);
a=x;
x=y;
y=a;
printf("x is %d\n",x);
printf("y is %d",y);
getch();
}
Posted by Unknown
Arithmetic Operators, Largest & Smallest Value And Odd & Even Numbers
//Arithmetic operation on three numbers
#include<stdio.h>;
#include<conio.h>;
//executing main program
void main()
{
//creating var for storing values
int i;
int j;
int k;
//take input from user
printf("Input three different integers \n");
scanf("%d %d %d", &i, &j, &k);
//calculating and displaying results of
//Adition
printf("\nThe sum is %d \n", i + j + k);
//average
printf("The average is %d \n", (i + j + k)/3);
//product
printf("The product is %d", i * j * k);
//smallest and largest no.
//first number
if (i < j & j<= k)
{
printf("\n \nThe smallest is %d", i);
} /*end if*/
if (j > i & j > k)
{
printf("\n \nThe largest is %d", i);
} /*end if*/
//2nd number
if (j < k & j <= i)
{
printf("\nThe smallest is %d", j);
} /*end if*/
if (j > k & j >= i)
{
printf("\nThe Largest is %d", j);
} /*end if*/
//3rd number
if (k < j & j<= i)
{
printf("\nThe smallest is %d", k);
} /*end if*/
if (k > j & j >= i)
{
printf("\nThe Largest is %d", k);
} /*end if*/
//chk and display even and odd no
//first no.
if ((i%2) == 0)
{
printf("\n \n%d is even", i);
}
else
{
printf("\n \n%d is odd", i);
}
//2nd no.
if (j%2 == 0)
{
printf("\n \n%d is even", j);
}
else
{
printf("\n \n%d is odd", j);
}
//3rd no.
if (k%2 == 0)
{
printf("\n \n%d is even", k);
}
else
{
printf("\n \n%d is odd", k);
}
//for disabling automatic close off of program after execution of program
_getch();
}//end
#include<stdio.h>;
#include<conio.h>;
//executing main program
void main()
{
//creating var for storing values
int i;
int j;
int k;
//take input from user
printf("Input three different integers \n");
scanf("%d %d %d", &i, &j, &k);
//calculating and displaying results of
//Adition
printf("\nThe sum is %d \n", i + j + k);
//average
printf("The average is %d \n", (i + j + k)/3);
//product
printf("The product is %d", i * j * k);
//smallest and largest no.
//first number
if (i < j & j<= k)
{
printf("\n \nThe smallest is %d", i);
} /*end if*/
if (j > i & j > k)
{
printf("\n \nThe largest is %d", i);
} /*end if*/
//2nd number
if (j < k & j <= i)
{
printf("\nThe smallest is %d", j);
} /*end if*/
if (j > k & j >= i)
{
printf("\nThe Largest is %d", j);
} /*end if*/
//3rd number
if (k < j & j<= i)
{
printf("\nThe smallest is %d", k);
} /*end if*/
if (k > j & j >= i)
{
printf("\nThe Largest is %d", k);
} /*end if*/
//chk and display even and odd no
//first no.
if ((i%2) == 0)
{
printf("\n \n%d is even", i);
}
else
{
printf("\n \n%d is odd", i);
}
//2nd no.
if (j%2 == 0)
{
printf("\n \n%d is even", j);
}
else
{
printf("\n \n%d is odd", j);
}
//3rd no.
if (k%2 == 0)
{
printf("\n \n%d is even", k);
}
else
{
printf("\n \n%d is odd", k);
}
//for disabling automatic close off of program after execution of program
_getch();
}//end
Wednesday, 24 December 2014
Posted by Unknown
Tag :
& Smallest,
Arithmetic,
C,
c++,
code,
coding,
even,
Largest,
Numbers,
odd,
Operators,
program,
project,
project c++(basic),
Value