Posts

Showing posts from April, 2018

Write a program to input two number and find smallest number.

Image
In this program we input two number and check which number is smallest. For this, we give a condition As:- If 1st number is smallest then print 1st number else 2nd number is smallest and print 2nd number. #include<stdio.h> #include<conio.h> void main() { int a,b; clrscr(); printf("Enter 1st number="); scanf("%d",&a); printf("Enter 2nd number="); scanf("%d",&b); if(a<b) printf("\n1st number is smallest"); else printf("\n2nd number is smallest"); getch(); } OUTPUT   Enter 1st number=7 Enter 2nd number =10 1st number is smallest Related Examples  Write a program to input a number and check number is positive or not. Write a program to input a number and check number is negative or not.  Write a program to input a number and check number is positive,negative or nuteral. Write a program to input two number and find highest number.  Follow for recently updates ,Share...

Write a program to input two number and find highest number.

Image
In this program we input two number and check which number is highest. For this, we give a condition As:- If 1st number is highest then print 1st number else 2nd number is highest and print 2nd number. #include<stdio.h> #include<conio.h> void main() { int a,b; clrscr(); printf("Enter 1st number="); scanf("%d",&a); printf("Enter 2nd number="); scanf("%d",&b); if(a>b) printf("\n1st number is highest"); else printf("\n2nd number is highest"); getch(); } OUTPUT   Enter 1st number=9 Enter 2nd number =7 1st number is highest Related Examples  Write a program to input a number and check number is positive or not. Write a program to input a number and check number is negative or not.  Write a program to input a number and check number is positive,negative or nuteral.   Follow for recently updates ,Share and Comment. 

Write a program to input a number and check number is positive,negative or nuteral.

Image
In this program input a number and check number is positive, negative or nuteral. If number is greater than Zero then print positive , if less than zero then print negative and if both condition false then print nuteral. #include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf("Enter a number="); scanf("%d",&n); if(n>0) printf("Positive number"); else if(n<0) printf("Negative number"); else printf("Nuteral"); getch(); } OUTPUT  Enter a number=4 Positive number                Or Enter a number=-4 Negative number                Or Enter a number=0 Nuteral Related Examples  1. Write a program to input a number and check number is positive or not. 2. Write a program to input a number and check number is negative or not.  Follow for recently updates on Google+ or subscribe. 

Write a program to input a number and check number is negative or not.

Image
In this program we input a number and check number is negative or not means if number is less than Zero then number is negative or not. #include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf("Enter a number="); scanf("%d",&n); if(n<0) printf("\nNegative number"); else printf("Not negative number"); getch(); } OUTPUT  You can follow me on Google+. Subscribe for recently updates. 

Write a Program to input a number and check number is positive or not.

Image
In this program we input a number and check number is positive or not. If number is greater than Zero, then number is positive. #include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf("Enter a number="); scanf("%d",&n); if(n>0) printf("Positive number"); else printf("Not positive number"); getch(); } Follow for recently updates. 

Program to input three number and print their Reverse.

Image
In this program we input three numbers and print their Reverse. First we find 1st digit by (n/100), 2nd digit by(n/10)%10 and 3rd digit by (n%10). Then finally we add a program logic. #include<stdio.h> #include<conio.h> void main() { int n,d1,d2,d3,r=0; clrscr(); printf("Enter three digit number="); scanf("%d",&n); d1=(n/100); d2=(n/10)%10; d3=n%10; r=(d3*100)+(d2*10)+d1; printf("\nReverse of number=%d",r); getch(); } OUTPUT 

Program to input three number and print their sum of digits in C.

Image
In this program we input three numbers and print their sum of digit. First we find 1st digit by (n/100), 2nd digit by(n/10)%10 and 3rd digit by (n%10). Then finally sum of digits. #include<stdio.h> #include<conio.h> void main() { int n,d1,d2,d3,s=0; clrscr(); printf("Enter three digit number="); scanf("%d",&n); d1=(n/100); d2=(n/10)%10; d3=n%10; s=d1+d2+d3; printf("\nSum of digits=%d",s); getch(); } OUTPUT 

Program to input two digit number and print their Reverse.

Image
In this program input two digit number and print the sum of its digits. For this we find 1st digit by number/10 and 2nd digit by n%10 . In the end we multiply 2nd number to 10 and add 1st number. #include<stdio.h> #include<conio.h> void main() { int n,d1,d2,r=0; clrscr(); printf("Enter two digit number="); scanf("%d",&n); d1=n/10; d2=n%10; r=(d2*10)+d1; printf("\nReverse of number=%d",r); getch(); } OUTPUT 

Program to input two digit number and print Sum of its digits.

Image
In this program input two digit number and print the sum of its digits. For this we find 1st digit by number/10 and 2nd digit by n%10.  #include<stdio.h> #include<conio.h> void main() { int n,d1,d2,s=0; clrscr(); printf("Enter two digit number="); scanf("%d",&n); d1=n/10; d2=n%10; s=d1+d2; printf("\nSum of digits=%d",s); getch(); } OUTPUT 

Program to input two number and print their values after interchange(Swap) without using third value.

Image
/* Program to swap two number in C */ #include<stdio.h> #include<conio.h> void main() { int a,b; clrscr(); printf("Enter first number="); scanf("%d",&a); printf("Enter second number="); scanf("%d",&b); a=a+b; b=a-b; a=a-b; printf("\nFirst number=%d",a); printf("\nSecond number=%d",b); getch(); } OUTPUT  Note: If any problems in this program please comment and never forget to Share. Follow for recently updates.

Program to input two numbers and print their values after interchange(Swap) using third value.

Image
#include<stdio.h> #include<conio.h> void main() { int a,b,c=0; clrscr(); printf("Enter first number="); scanf("%d",&a); printf("Enter second number="); scanf("%d",&b); c=a; a=b; b=c; printf(\nFirst number=%d",a); printf("\nSecond number=%d",b); getch(); } OUTPUT Note:- If any problem in this program please comment and never forget to share.

Program to input three number and calculate their Average.

Image
#include<stdio.h> #include<conio.h> void main() { int a,b,c,m=0; clrscr(); printf("Enter three number="); scanf("%d%d%d",&a,&b,&c); d=(a+b+c)/3; printf("Average=%d",d); getch(); } OUTPUT  Note:- If you want to calculate floating value (value which contains point) or fractional value ,you can use "float " and "%f" replace to "int " and "%d". If you want to calculate both use "double".

Program to input sell price and cost price and calculate Profit.

Image
/*Program to calculate Profit */ #include<stdio.h> #include<conio.h> void main() { int sp,cp,p=0; clrscr(); printf("Enter sell price="); scanf("%d",&sp); printf("Enter cost price="); scanf("%d",&cp); p=sp-cp; printf("Profit=%d",p); getch(); } OUTPUT