#include<stdio.h>
#include<conio.h>
int main()
{
float r,ar,c;
printf("Enter The Radius Of The Circle:");
scanf("%f",&r);
ar=3.14*r*r;
c=2*3.14*r;
printf("The Area Of The Circle is %f",ar);
printf("The Circumferance Of The Circle is %f",c);
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
char ch;
printf("Enter The Character:");
ch=getche();
printf("Ascii Value of %c is %u",ch,ch);
getch();
return(0);
}
#include<stdio.h>
int main()
{
int fnum ,snum;
printf("Enter the first number.\n");
scanf("%d",&fnum);
printf("Enter the second number.\n");
scanf("%d",&snum);
int min = fnum > snum ? snum : fnum;
// Code for calculating HCF of two numbers.
for(int i = min; i >= 1; i--)
{
if(fnum % i == 0 && snum % i == 0)
{
printf("%d is The HCF of %d and %d.\n",i, fnum , snum);
break;
}
}
}
#include<stdio.h>
int main()
{
int fnum , snum;
printf("Enter the first number.\n");
scanf("%d",&fnum);
printf("Enter the second number.\n");
scanf("%d",&snum);
int max = fnum > snum ? fnum : snum;
// code for calculating LCM of two number.
for(int i = max; i <= fnum * snum; i = (i + max))
{
if(i % fnum == 0 && i % snum == 0)
{
printf("%d is the LCM of %d and %d.\n",i , fnum , snum);
return;
}
}
}
#include<stdio.h>
#include<conio.h>
int main()
{
float b,h,ar;
printf("Enter The Base Of The Triangle:");
scanf("%f",&b);
printf("Enter The Height Of the Triangle:");
scanf("%f",&h);
ar=0.5*b*h;
printf("The Area Of The Triangle Is %f",ar);
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
char fname[20],mname[20],lname[20];
printf("Enter The Full Name:");
scanf("%s%s%s",fname,mname,lname);
printf("The Abbreviated Name is %c%c%s",fname[20],mname[20],lname);
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
float p,r,i;
int t;
printf("Enter The Principal Amount:");
scanf("%f",&p);
printf("Enter The Rate Of The Interest:");
scanf("%f",&r);
printf("Enter The Time Period:");
scanf("%d",&t);
i=(p*r*t)/100;
printf("The Amount Of Interest is %f",i);
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
float bs,da,hra,p,t;
printf("Enter The Basic Salary:");
scanf("%f",&bs);
printf("Enter The Dearness Allowance:");
scanf("%f",&da);
printf("Enter The House Rent Allowance:");
scanf("%f",&hra);
printf("Enter The P-Tax:");
scanf("%f",&p);
t=bs+da+hra-p;
printf("The given salary is %f",t);
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
float a,b,c,d,e,t,p;
printf("Enter the marks of the first subject:");
scanf("%f",&a);
printf("Enter the Marks Of the second subject:");
scanf("%f",&b);
printf("Enter the Marks Of the third subject:") ;
scanf("%f",&c);
printf("Enter the Marks Of the fourth subject:");
scanf("%f",&d);
printf("Enter the Marks Of the fifth subject:");
scanf("%f",&e);
t=a+b+c+d+e;
p=(t/500)*100;
printf("The total marks is %f",t);
printf("The percentage of marks is %f",p);
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
float g,c;
printf("Enter The Temperature in Celcius Scale:");
scanf("%f",&c);
g=1.8*c+32;
printf("The temperature in farenheit scale is %f",g);
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
printf("char is %d bytes",sizeof(char));
printf("unsigned char is %d bytes",sizeof(unsigned char));
printf("integer is %d bytes",sizeof(int));
printf("short integer is %d bytes",sizeof(short int));
printf("unsigned short integer is %d bytes",sizeof(unsigned short int));
printf("long integer is %d bytes",sizeof(long int));
printf("unsigned long integer is %d bytes",sizeof(unsigned long int));
printf("float is %d bytes",sizeof(float));
printf("double is %d bytes",sizeof(double));
printf("long double is %d bytes",sizeof(long double));
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
int n,fact=1;
printf("Enter The Number:");
scanf("%d",&n);
while(n>1)
{
fact*=n;
n--;
}
printf("The factorial of the number is %d",fact);
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
printf("Enter the number:");
scanf("%d",&n);
printf("%d%d%d",n,n*n,n*n*n);
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
float r,ar;
printf("Enter The Radius Of The circle:");
scanf("%f",&r);
ar=3.14*r*r;
printf("The Area Of The Circle Is %f",ar);
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
printf("Enter The Three Numbers:");
scanf("%d%d%d",&a,&b,&c);
if(a>b && a>c)
{
printf("The Greatest Of Three Numbers Is %d",a);
}
else
if(b>a && b>c)
{
printf("The Greatest Of Three Numbers Is %d",b);
}
else
printf("The Greatest OF The Three Numbers Is %d",c);
getch;
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,table=1;
printf("Enter The Number:");
scanf("%d",&n);
for(i=1;i<=10;i++)
{
table=n*i;
printf("The Table Of The Number Is %d",table);
}
getch();
return(0);
}
#include <stdio.h>
int main()
{
int fnum , snum ,tnum;
printf("Enter the first number.\n");
scanf("%d",&fnum);
printf("Enter the second number.\n");
scanf("%d",&snum);
printf("Enter the third number.\n");
scanf("%d",&tnum);
// 1. Method.
if(fnum > snum && fnum > tnum)
{
printf("%d is Greater than %d and %d.\n",fnum , snum , tnum);
}
else if(snum > fnum && snum > tnum)
{
printf("%d is Greater than %d and %d.\n",snum , fnum, tnum);
}
else if(tnum > fnum && tnum > snum)
{
printf("%d is Greater than %d and %d.\n",tnum , fnum ,snum);
}
// 2. Method. this method is better than first method.
if(fnum > snum && fnum > tnum)
{
printf("%d is Greater than %d and %d.\n",fnum , snum , tnum);
}
else if(snum > tnum)
{
printf("%d is Greater than %d and %d.\n",snum , fnum, tnum);
}
else
{
printf("%d is Greater than %d and %d.\n",tnum , fnum ,snum);
}
}
#include <stdio.h>
int main()
{
int num;
printf("Enter the number.\n");
scanf("%d",&num);
// Condition.
if(num > 0)
{
printf("%d is Positive Number.\n",num);
}
else if(num < 0)
{
printf("%d is Negative Number.\n",num);
}
else
{
printf("%d is Zero.\n",num);
}
}
#include <stdio.h>
int main()
{
char ch;
printf("Enter the Character.\n");
scanf("%c",&ch);
if((ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') || (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'U'))
{
printf("%c is VoWel.\n",ch);
}
else
{
printf("%c is Cosonant.\n",ch);
}
}
//OUTPUT.
//Enter the Character.
//y
//y is Cosonant.
//
//********************
//
//Enter the Character.
//a
//a is VoWel.
#include <stdio.h>
int main()
{
char ch;
printf("Enter the Character.\n");
scanf("%c",&ch);
// Condition. or Logic
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("%c is Alphabet.\n",ch);
}
else
{
printf("%c is not Alphabet.\n",ch);
}
}
//OUTPUT
//Enter the Character.
//a
//a is Alphabet.
//
//*********************
//
//Enter the Character.
//7
//7 is not Alphabet.
#include <stdio.h>
int main()
{
char ch;
printf("Enter the Character.\n");
scanf("%c",&ch);
// Logic or Conditon.
if(ch >= 'a' && ch <= 'z')
{
printf("%c is LowerCase Character.\n",ch);
}
else if(ch >= 'A' && ch <= 'Z')
{
printf("%c is UpperCase Character.\n",ch);
}
else if(ch >= '0' && ch <= '9')
{
printf("%c is Digit.\n",ch);
}
else
{
printf("%c is Special Character.\n",ch);
}
}
//OUTPUT
//Enter the Character.
//#
//# is Special Character.
//******************************
//Enter the Character.
//A
//A is UpperCase Character.
//*******************************
//Enter the Character.
//x
//x is LowerCase Character.
//*******************************
//Enter the Character.
//8
//8 is Digit.
#include <stdio.h>
int main()
{
int num;
printf("Enter the number.\n");
scanf("%d",&num);
// Logic
if(num % 2 == 0)
{
printf("%d is Even Number.\n",num);
}
else {
printf("%d is Odd Number.\n",num);
}
}
//OUTPUT
//Enter the number.
//7
//7 is Odd Number.
//**********************
//Enter the number.
//24
//24 is Even Number.
#include <stdio.h>
int main()
{
int fnum , snum;
printf("Enter the First number.\n");
scanf("%d",&fnum);
printf("Enter the second number.\n");
scanf("%d",&snum);
// Logic
if(fnum > snum)
{
printf("%d is Greater than %d\n",fnum , snum);
}
else {
printf("%d is Greater than %d\n",snum , fnum);
}
}
//OUTPUT
//Enter the First number.
//8
//Enter the second number.
//7
//8 is Greater than 7
#include <stdio.h>
int main()
{
int ageOfVoter;
printf("Enter Your Age.\n");
scanf("%d",&ageOfVoter);
if(ageOfVoter >= 18)
{
printf("You Are Eligible.\n");
}
else
{
printf("You are Not Eligible.\n");
}
}
//OUTPUT
//Enter Your Age.
//2
//You are Not Eligible.
//******************************
//Enter Your Age.
//23
//You Are Eligible.
#include <stdio.h>
int main()
{
int num;
printf("Enter the Number.\n");
scanf("%d",&num);
// logic
if(num % 5 == 0 && num % 11 == 0)
{
printf("Yes %d is divisible by 5 and 11.\n",num);
}
else
{
printf("%d is not divisible by 5 and 11.\n",num);
}
}
//OUTPUT
//Enter the Number.
//55
//Yes 55 is divisible by 5 and 11.
//**************************************
//Enter the Number.
//77
//77 is not divisible by 5 and 11.
#include <stdio.h>
int main()
{
int weekNumber;
printf("Enter a Week Number.\n");
scanf("%d",&weekNumber);
// Logic
if(weekNumber == 1)
{
printf("Sunday.\n");
}
else if(weekNumber == 2)
{
printf("Monday.\n");
}
else if(weekNumber == 3)
{
printf("Tuesday.\n");
}
else if(weekNumber == 4)
{
printf("Wednesday.\n");
}
else if(weekNumber == 5)
{
printf("Thursday.\n");
}
else if(weekNumber == 6)
{
printf("Friday.\n");
}
else
{
printf("Saturday.\n");
}
}
#include <stdio.h>
int main()
{
int monthNumber;
printf("Enter the Month Number.\n");
scanf("%d",&monthNumber);
if(monthNumber == 1)
{
printf("31 days.");
}
else if(monthNumber == 2)
{
printf("28 / 29 days.");
}
else if(monthNumber == 3)
{
printf("31 days.");
}
else if(monthNumber == 4)
{
printf("30 days.");
}
else if(monthNumber == 5)
{
printf("31 days.");
}
else if(monthNumber == 6)
{
printf("30 days.");
}
else if(monthNumber == 7)
{
printf("31 days.");
}
else if(monthNumber == 8)
{
printf("31 days.");
}
else if(monthNumber == 9)
{
printf("30 days.");
}
else if(monthNumber == 10)
{
printf("31 days.");
}
else if(monthNumber == 11)
{
printf("30 days.");
}
else if(monthNumber == 12)
{
printf("31 days.");
}
}
//OUTPUT
// Enter the Month Number.
// 12
// 31 days.
#include <stdio.h>
int main()
{
int amount;
int twoThousand = 0 , fiveHundere = 0, twoHundred = 0, hundred = 0
, fifty = 0 , twenty = 0 , ten = 0, five = 0 , two = 0, one = 0;
printf("Enter the Amount.\n");
scanf("%d",&amount);
while(amount > 0)
{
if(amount >= 2000)
{
twoThousand++;
amount -= 2000;
continue;
}
if(amount >= 500)
{
fiveHundere++;
amount -= 500;
continue;
}
if(amount >= 100)
{
hundred++;
amount -= 100;
continue;
}
if(amount >= 50)
{
fifty++;
amount -= 50;
continue;
}
if(amount >= 20)
{
twenty++;
amount -= 20;
continue;
}
if(amount >= 10)
{
ten++;
amount -= 10;
continue;
}
if(amount >= 5)
{
five++;
amount -= 5;
continue;
}
if(amount >= 2)
{
two++;
amount -= 2;
continue;
}
if(amount >= 1)
{
one++;
amount -= 1;
continue;
}
}
printf("%d : %d.\n",2000 , twoThousand);
printf("%d : %d.\n",500 , fiveHundere);
printf("%d : %d.\n",100 , hundred);
printf("%d : %d.\n",50 , fifty);
printf("%d : %d.\n",20 , twenty);
printf("%d : %d.\n",10 , ten);
printf("%d : %d.\n",5 , five);
printf("%d : %d.\n",2 , two);
printf("%d : %d.\n",1 , one);
}
//OUTPUT
//Enter the Amount.
//5299
//2000 : 2.
//500 : 2.
//100 : 2.
//50 : 1.
//20 : 2.
//10 : 0.
//5 : 1.
//2 : 2.
//1 : 0.
#include <stdio.h>
int main()
{
int num;
printf("Enter the Number.\n");
scanf("%d",&num);
// Logic
while(num != 0)
{
printf("%d",num % 10);
num /= 10;
}
}
//OUTPUT
//
//Enter the Number.
//12345
#include <stdio.h>
int main()
{
int n;
printf("Enter the Number.\n");
scanf("%d",&n);
int sum_of_NaturalNumber;
int temp = n; // Copy value of n into temp variable.
while(n != 0)
{
sum_of_NaturalNumber += n;
n--;
}
printf("The Sum %d Natural Number is %d.\n",temp , sum_of_NaturalNumber);
}
//OUTPUT
//
//Enter the Number.
//10
//The Sum 10 Natural Number is 55.
#include <stdio.h>
int main()
{
int num;
printf("Enter the Number.\n");
scanf("%d",&num);
// Logic
// 1. Method
int first = 0 , second = 1 , result = 0;
for(int i = 0; i < num; i++)
{
if(i <= 1)
{
printf("%d + ",i);
}
else
{
result = first + second;
first = second;
second = result;
if(i != num -1)
{
printf("%d + ",result);
}
else
{
printf("%d.\n",result);
}
}
}
// 2. Method this logic is little bit tricky.
// int this method we use previous variable like ( first , second or result)
first = 0;
second = 1;
result = 0;
for(int i = 0; i < num; i++)
{
if(i != num -1)
{
printf("%d + ",first);
}
else
{
printf("%d.\n",first);
}
result = first + second;
first = second;
second = result;
}
}
//OUTPUT
//
//Enter the Number.
//10
//0 + 1 + 1 + 2 + 3 + 5 + 8 + 13 + 21 + 34.
#include <stdio.h>
int main()
{
int num;
printf("Enter the Number.\n");
scanf("%d",&num);
// Logic
int temp = num; // copy the value of num into temp variable.
int reverseNumber = 0;
while(num > 0)
{
int lastDigit = num % 10; // Get Last digit from the number.
num /= 10; // Remove Last digit from the number.
reverseNumber = reverseNumber * 10 + lastDigit;
}
printf("Reverse of %d is %d.\n",temp , reverseNumber);
}
//OUTPUT
//
//Enter the Number.
//12345
//Reverse of 12345 is 54321.
#include <stdio.h>
int main()
{
int num;
int revNum;
printf("Enter the Number.\n");
scanf("%d",&num);
// Code for Reversing a num.
int temp = num;
while(temp != 0)
{
int lastDigit = temp % 10;
temp /= 10;
revNum = revNum * 10 + lastDigit;
}
// reverse of the number equal to actual number then the number is Palindrome.
if(revNum == num)
{
printf("%d is Palindrome.\n",num);
}
else
{
printf("%d is Not Palindrome.\n",num);
}
}
//OUTPUT
//Enter the Number.
//123
//123 is Not Palindrome.
//***************************
//Enter the Number.
//121
//121 is Palindrome.
#include <stdio.h>
int main()
{
int num;
printf("Enter the number.\n");
scanf("%d",&num);
int countOfDigit = 0;
int temp = num;
// Logic
while(num != 0)
{
countOfDigit++;
num /= 10;
}
printf("%d digits are Present in %d.\n",countOfDigit, temp);
}
//OUTPUT
//Enter the number.
//747932
//6 digits are Present in 747932.
#include <stdio.h>
int main()
{
int num;
printf("Enter the Number.\n");
scanf("%d",&num);
int binary = 0;
int i = 1;
printf("Binary of %d is ",num);
// Logic
while(num != 0)
{
int lastDigit = num % 2;
num /= 2;
binary = binary + lastDigit * i;
i *= 10;
}
printf("%d.\n",binary);
}
//OUTPUT
//Enter the Number.
//5
//Binary of 5 is 101.
#include <stdio.h>
int main()
{
int num;
printf("Enter the Binary Number.\n");
scanf("%d",&num);
int decimal = 0;
int i = 1;
printf("Decimal of %d is ",num);
// Logic
while(num != 0)
{
int lastDigit = num % 10;
num /= 10;
decimal = decimal + lastDigit * i;
i *= 2;
}
printf("%d.\n",decimal);
}
//OUTPUT
//Enter the Binary Number.
//101
//Decimal of 101 is 5.
#Loading....
#include <stdio.h>
void main()
{
int num;
printf("Enter a number.\n");
scanf("%d",&num);
for(int i = 1; i <= num; i++) {
printf("%d\n",i);
}
}
// OUTPUT
// Enter a number.
// 5
// 1
// 2
// 3
// 4
// 5
#include <stdio.h>
#include <stdbool.h>
void main()
{
int start = 1, end = 100;
for(int i = start; i <= end; i++) {
// Logic for check given number is prime or not...
bool flag = true;
for(int j = 2; j <= i / 2; j++) {
if(i % j == 0) {
flag = false;
break;
}
}
if(flag) {
printf("%d\t",i);
}
}
printf("\n"); // it is for new line.
}
#include <stdio.h>
void main()
{
char ch = 'a';
for(int i = 0; i <= 25; i++) {
printf("%c\t",ch + i);
}
printf("\n");
}
// OUTPUT
// a b c d e f g h i
// j k l m n o p q r
// s t u v w x y z
#include
void main()
{
int tableNumber;
printf("Enter a Table Number.\n");
scanf("%d",&tableNumber);
for(int i = 1; i <= 10; i++) {
printf("%d x %d = %d\n", tableNumber, i , tableNumber * i);
}
}
// OUTPUT
// Enter a Table Number.
// 5
// 5 x 1 = 5
// 5 x 2 = 10
// 5 x 3 = 15
// 5 x 4 = 20
// 5 x 5 = 25
// 5 x 6 = 30
// 5 x 7 = 35
// 5 x 8 = 40
// 5 x 9 = 45
// 5 x 10 = 50
#Loading....
#Loading....
#Loading....
#Loading....
#Loading....
#Loading....
#include<stdio.h>
#include<conio.h>
int main()
{
int x;
float a,b,c,f;
printf("1.For Farenheit To Celcius Scale:");
printf("2.For Celcius To Farenheit Scale:");
printf("Enter Your Choice:");
scanf("%d",&x);
switch(x)
{
case 1:
printf("Enter The Value Of Faranheit Temperature:");
scanf("%f",&a);
c=5*(a-32)/9;
printf("The Celcius Temperature is %f",c);
break;
case 2:
printf("Enter The Value Of Celcius Temperature:");
scanf("%f",&b);
f=9*(b/5)+32;
printf("The Farenheit Temperature Is %f",f);
break;
default:
printf("Enter A Correct Choice");
}
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
int day;
printf("Enter The Weekday number (1-7):");
scanf("%d",&day);
switch(day)
{
case 1:
printf("1-Sunday");
break;
case 2:
printf("2-Monday");
break;
case 3:
printf("3-Tuesday");
break;
case 4:
printf("4-Wednesday");
break;
case 5:
printf("5-Thursday");
break;
case 6:
printf("6-Friday");
break;
case 7:
printf("7-Saturday");
break;
default:
printf("Enter A Correct Day:");
}
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,r;
char op;
printf("Enter An Expression:");
scanf("%d%c%d",&a,&op,&b);
switch(op)
{
case '+':
r=a+b;
break;
case '-':
r=a-b;
break;
case '*':
r=a*b;
break;
case '/':
r=a/b;
break;
default:
printf("Enter A Correct Expression:");
}
printf("The Result Is %d",r);
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
int score;
printf("Enter The Score(0-100):");
scanf("%d",&score);
switch(score/10)
{
case 10:
case 9:
printf("Grade:A");
break;
case 8:
printf("Grade:B");
break;
case 7:
printf("Grade:C");
break;
case 6:
printf("Grade:D");
break;
case 5:
printf("Grade:E");
break;
default:
printf("Grade:F");
break;
}
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
float r,h,c,v;
int ch;
printf("1.circumferance of the cylinder:") ;
printf("2.volume of the cylinder:");
printf("Enter The Choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
float r,c;
printf("Enter The Radius Of The Circular Base Of The Cylinder:");
scanf("%f",&r);
c=2*3.14*r;
printf("The Circumferance of the cylinder is %f",c);
break;
}
case 2:
{
float r,h,v;
printf("Enter the radius:");
scanf("%f",&r);
printf("Enter The height:");
scanf("%f",&h);
v=3.14*r*r*h;
printf("the volume of the cylinder is %f",v);
break;
}
default:
printf("Enter a correct choice:");
break;
}
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
int month;
printf("Enter month number(1-12)");
scanf("%d",&month);
switch(month)
{
case 1:
printf("31 days");
break;
case 2:
printf("28 or 29 days");
break;
case 3:
printf("31 days");
break;
case 4:
printf("30 days");
break;
case 5:
printf("31 days");
break;
case 6:
printf("30 days");
break;
case 7:
printf("31 days");
break;
case 8:
printf("31 days");
break;
case 9:
printf("30 days");
break;
case 10:
printf("31 days");
break;
case 11:
printf("30 days");
break;
case 12:
printf("31 days");
break;
default:
printf("Enter A correct Month Number:");
break;
}
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
char e;
printf("Enter The Character:");
scanf("%c",&e);
if(e>=65 && e<=90 || e>=97 && e<=122)
{
if(e>=97 && e<=122)
{
e-=32;
}
switch(e)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':printf("It is a vowel");
break;
default:printf("It is a Consonant");
break;
}
}
else
printf("It is not an alphabet:");
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
printf("Enter The Two Numbers:");
scanf("%d%d",&a,&b);
switch(a>b)
{
case 1:
printf("The Maximum of the two numbers is %d",a);
break;
case 0:
printf("The Maximum Of the two numbers is %d",b);
break;
}
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
printf("Enter A Number:");
scanf("%d",&n);
switch(n%2)
{
case 0:printf("The Number Is Even:");
break;
case 1:printf("The Number Is Odd:");
break;
}
getch();
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
printf("Enter The Number:");
scanf("%d",&n);
switch(n>0)
{
case 1:
printf("The Number Is Positive:");
break;
case 0:
switch(n<0)
{
case 1:
printf("The Number Is Negative:");
break;
case 0:
printf("The Number Is Zero:");
break;
}
break;
}
getch();
return(0);
}
#include<stdio.h>
int main()
{
int arr[40];
int size;
printf("Enter the Size of an Array.\n");
scanf("%d",&size);
printf("Enter the Element of an Array.\n");
// code for read data.
for(int i = 0; i < size; i++)
{
scanf("%d",&arr[i]);
}
// code for display data.
printf("Elements Stored in an Array is\n");
for(int i = 0; i < size; i++)
{
printf("%d ",arr[i]);
}
}
//OUTPUT
//
//Enter the Size of an Array.
//5
//Enter the Element of an Array.
//1
//2
//3
//4
//5
//Elements Stored in an Array is
//1 2 3 4 5
#include<stdio.h>
int main()
{
int arr[40];
int size;
printf("Enter the Size of an Array.\n");
scanf("%d",&size);
printf("Enter the Element of an Array.\n");
// code for read data.
for(int i = 0; i < size; i++)
{
scanf("%d",&arr[i]);
}
// code for calculating mean.
int sum = 0;
for(int i = 0; i < size; i++)
{
sum += arr[i];
}
float mean = (float)sum / size;
printf("%f is the Mean of an Array.\n",mean);
}
//OUTPUT
//
//Enter the Size of an Array.
//5
//Enter the Element of an Array.
//1
//2
//3
//4
//5
//3.000000 is the Mean of an Array.
#include<stdio.h>
int main()
{
int arr[40];
int size;
printf("Enter the Size of Array.\n");
scanf("%d",&size);
printf("Enter the Element of Array.\n");
// code for read data.
for(int i = 0; i < size; i++)
{
scanf("%d",&arr[i]);
}
// Logic
int max = arr[0];
for(int i = 1; i < size; i++)
{
if(arr[i] > max)
{
max = arr[i];
}
}
printf("Greatest Element of an Array is %d.\n",max);
}
//OUTPUT
//
//Enter the Size of Array.
//5
//Enter the Element of Array.
//2
//5
//8
//19
//45
//Greatest Element of an Array is 45.
#include<stdio.h>
int main()
{
int arr[40];
int size;
printf("Enter the Size of Array.\n");
scanf("%d",&size);
printf("Enter the Element of Array.\n");
// code for read data.
for(int i = 0; i < size; i++)
{
scanf("%d",&arr[i]);
}
// Logic
int minPosition = 0;
int maxPosition = 0;
for(int i = 1; i < size; i++)
{
if(arr[i] < arr[minPosition])
{
minPosition = i;
}
if(arr[i] > arr[maxPosition])
{
maxPosition = i;
}
}
printf("Before Changing Content of an Array are.\n\n");
for(int i = 0; i < size; i++)
{
printf("%d ",arr[i]);
}
printf("\n\n");
int temp = arr[minPosition];
arr[minPosition] = arr[maxPosition];
arr[maxPosition] = temp;
printf("After Changing Content of an Array are..\n\n");
for(int i = 0; i < size; i++)
{
printf("%d ",arr[i]);
}
printf("\n\n");
}
//OUTPUT
//
//Enter the Size of Array.
//5
//Enter the Element of Array.
//1
//2
//3
//4
//5
//Before Changing Content of an Array are.
//
//1 2 3 4 5
//
//After Changing Content of an Array are..
//
//5 2 3 4 1
#include<stdio.h>
int main()
{
int arr[40];
int size;
printf("Enter the Size of Array.\n");
scanf("%d",&size);
printf("Enter the Element of Array.\n");
// code for read data.
for(int i = 0; i < size; i++)
{
scanf("%d",&arr[i]);
}
// Logic
// 1. Method
int fLargest = arr[0];
for(int i = 0; i < size; i++)
{
if(arr[i] > fLargest)
{
fLargest = arr[i];
}
}
int sLargest = arr[0];
for(int i = 0; i < size; i++)
{
if(arr[i] != fLargest && arr[i] > sLargest)
{
sLargest = arr[i];
}
}
printf("%d is The Second Largest Element in an Array.\n",sLargest);
// 2. Method.
// Here I am Using Previous declare Variable. ( fLargest or sLargest )
fLargest = arr[0];
sLargest = arr[0];
for(int i = 1; i < size; i++)
{
if(arr[i] > fLargest)
{
sLargest = fLargest;
fLargest = arr[i];
}
}
printf("%d is The Second Largest Element in an Array.\n",sLargest);
}
//OUTPUT
//
//Enter the Size of Array.
//5
//Enter the Element of Array.
//1
//2
//3
//4
//5
//4 is The Second Largest Element in an Array.
//4 is The Second Largest Element in an Array.
#include<stdio.h>
int main()
{
int arr[40];
int size;
printf("Enter the Size of Array.\n");
scanf("%d",&size);
printf("Enter the Element of Array.\n");
// code for read data.
for(int i = 0; i < size; i++)
{
scanf("%d",&arr[i]);
}
// Logic
for(int i = 0; i < size - 1; i++)
{
int temp = arr[i];
for(int j = i + 1; j < size; j++)
{
if(arr[j] == temp)
{
printf("Duplicate Element Present in an Array.\n");
return;
}
}
}
printf("Duplicate Element is not Present in an Array.\n");
}
//OUTPUT
//
//Enter the Size of Array.
//5
//Enter the Element of Array.
//1
//2
//3
//3
//5
//Duplicate Element Present in an Array.
#include<stdio.h>
int main()
{
int arr[40];
int size;
printf("Enter the Size of Array.\n");
scanf("%d",&size);
printf("Enter the Element of Array.\n");
// code for read data.
for(int i = 0; i < size; i++)
{
scanf("%d",&arr[i]);
}
// Logic
int result = 0;
int i = 0;
for(int i = 0; i < size; i++)
{
result = result * 10 + arr[i];
}
printf("%d is The Number Obtained form the given Digits.\n",result);
}
//OUTPUT
//
//Enter the Size of Array.
//5
//Enter the Element of Array.
//1
//2
//3
//4
//5
//12345 is The Number Obtained form the given Digits.
#include<stdio.h>
int main()
{
int arr[40];
int size;
printf("Enter the Size of Arrays.\n");
scanf("%d",&size);
printf("Enter the Element of Arrays.\n");
// code for read data.
for(int i = 0; i < size; i++)
{
scanf("%d",&arr[i]);
}
// Logic
int min = arr[0];
int pos = 0;
for(int i = 1; i < size; i++)
{
if(arr[i] < min)
{
pos = i;
min = arr[i];
}
}
printf("%d is the Smallest Number of an Array.\nAt index Number %d.\n",min,pos);
}
//OUTPUT
//
//Enter the Size of Arrays.
//5
//Enter the Element of Arrays.
//1
//2
//3
//4
//5
//1 is the Smallest Number of an Array.
//At index Number 0.
#include <stdio.h>
int binarySearch(int arr[] , int lo , int hi , int data)
{
while(lo <= hi)
{
int mid = (lo + hi) / 2;
if(arr[mid] == data)
{
return mid;
}
else if(arr[mid] > data)
{
hi = mid - 1;
}
else
{
lo = mid + 1;
}
}
return -1;
}
int main()
{
int arr[] = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14};
int lo = 0;
int data = 1;
int hi = 1;
while(arr[hi] < data)
{
hi *= 2;
}
int res = binarySearch(arr , lo , hi , data);
printf("%d \n",res);
}
#include <stdio.h>
int firstIndex(int arr[] ,int lo , int hi, int key)
{
int res = -1;
while(lo <= hi)
{
int mid = (lo + hi) / 2;
if(arr[mid] == key)
{
res = mid;
hi = mid -1;
}
else if(arr[mid] > key)
{
hi = mid -1;
}
else
{
lo = mid + 1;
}
}
return res;
}
int main()
{
int arr[] = {0 , 0, 0, 0, 1, 1, 1,1 ,1 ,1};
int lo = 0;
int hi = 1;
int key = 1;
while(arr[hi] < key)
{
hi *= 2;
}
int res = firstIndex(arr , lo , hi , key);
printf("%d",res);
}
#include <stdio.h>
int main()
{
char string[100];
printf("Enter Your Name.\n");
gets(string);
printf("Your Name is %s.\n",string);
}
//OUTPUT
//
//Enter Your Name.
//Manish Kumar
//Your Name is Manish Kumar.
#include <stdio.h>
int main()
{
char string[100];
printf("Enter a String.\n");
gets(string);
printf("Entered String is %s.\n",string);
int length = 0;
while(string[length] != '\0')
{
length++;
}
printf("Length of the String is %d.\n",length);
}
//OUTPUT
//
//Enter a String.
//Manish Kumar
//Entered String is Manish Kumar.
//Length of the String is 12.
#include <stdio.h>
int main()
{
char string[100];
printf("Enter a String.\n");
gets(string);
printf("Entered String is %s.\n",string);
// logic
for(int i = 0; string[i] != '\0'; i++)
{
if(string[i] >= 'A' && string[i] <= 'Z')
{
string[i] = (char)'a' + string[i] - 'A';
}
}
printf("Transform String is %s.\n",string);
}
//OUTPUT
//Enter a String.
//Manish Kumar
//Entered String is Manish Kumar.
//Transform String is manish kumar.
#include <stdio.h>
int main()
{
char string[100];
printf("Enter a String.\n");
gets(string);
printf("Entered String is %s.\n",string);
// logic
for(int i = 0; string[i] != '\0'; i++)
{
if(string[i] >= 'a' && string[i] <= 'z')
{
string[i] = (char)'A' + string[i] - 'a';
}
}
printf("Transform String is %s.\n",string);
}
//OUTPUT
//Enter a String.
//Mintu Kumar
//Entered String is Mintu Kumar.
//Transform String is MINTU KUMAR.
#Loading....
#Loading....
#Loading....
#Loading....
#Loading....
#Loading....
#include <stdio.h>
int sum(int num1 , int num2) {
return num1 + num2;
}
int main()
{
int res = sum(2 , 4);
printf("%d",res);
res = sum(4 , 4);
printf("%d",res);
}
#include <stdio.h>
void printTable(int tableNumber) {
for(int i = 1; i <= 10; i++) {
printf("%d x %d = %d\n" , tableNumber , i , tableNumber * i);
}
}
int main()
{
int tableNum;
printf("Enter a Table-Number.\n");
scanf("%d",&tableNum);
printTable(tableNum); // Called printTable function
return 0;
}
// OUTPUT
// Enter a Table-Number.
// 10
// 10 x 1 = 10
// 10 x 2 = 20
// 10 x 3 = 30
// 10 x 4 = 40
// 10 x 5 = 50
// 10 x 6 = 60
// 10 x 7 = 70
// 10 x 8 = 80
// 10 x 9 = 90
// 10 x 10 = 100
#include <stdio.h>
char toUpperCase(char ch) {
// It is check that the input character is lowerCase or not.. if Yes then execute if block code other-wise return without any changes
if(ch >= 'a' && ch <= 'z') {
return (ch - 32); // Why substract 32...? Because The Difference Between ASCII Code of lowercase and
// uppercase character is 32. (ex: ASCII Code of 'a' = 97 and ASCII Code of 'A' = 65). 97 - 65 = 32
}
return ch;
}
void main()
{
char ch;
printf("Enter a Character.\n");
scanf("%c",&ch);
char res = toUpperCase(ch);
printf("%c is The UpperCase of %c", res , ch);
}
// OUTPUT
// Enter a Character.
// a
// A is The UpperCase of a
#include <stdio.h>
char toLowerCase(char ch) {
if(ch >= 'A' && ch <= 'Z') {
return (ch + 32);
}
return ch;
}
void main()
{
char ch;
printf("Enter a Character.\n");
scanf("%c",&ch);
char res = toLowerCase(ch);
printf("%c is the LowerCase of %c", res , ch);
}
// OUTPUT
// Enter a Character.
// a
// A is The UpperCase of a
#include <stdio.h>
int toBinary(int num) {
int x = 1;
int res = 0;
while(num > 0) {
int temp = num % 2;
num /= 2;
res = res + temp * x;
x *= 10;
}
return res;
}
void main()
{
int num;
printf("Enter a number\n");
scanf("%d",&num);
int res = toBinary(num);
printf("Binary of %d is %d.\n",num , res);
}
// OUTPUT
// Enter a number
// 31
// Binary of 31 is 11111.
#include <stdio.h>
int toOctal(int num) {
int x = 1;
int res = 0;
while(num > 0) {
int temp = num % 8;
num /= 8;
res = res + temp * x;
x *= 10;
}
return res;
}
void main()
{
int num;
printf("Enter a number\n");
scanf("%d",&num);
int res = toOctal(num);
printf("Octal Number of %d is %d.\n",num , res);
}
// OUTPUT
// Enter a number
// 15
// Octal Number of 15 is 17.
#include &ttstdio.h>
int toHexaDecimal(int num) {
int x = 1;
int res = 0;
while(num > 0) {
int temp = num % 16;
num /= 16;
res = res + temp * x;
x *= 10;
}
return res;
}
void main()
{
int num;
printf("Enter a number\n");
scanf("%d",&num);
int res = toHexaDecimal(num);
printf("Hexa-Decimal Number of %d is %d.\n",num , res);
}
// OUTPUT
// Enter a number
// 150
// Hexa-Decimal Number of 150 is 96.
#include <stdio.h>
int toDecimal(int bNum) {
int res = 0;
int x = 1;
while(bNum > 0) {
int temp = bNum % 10;
bNum /= 10;
res += temp * x;
x *= 2;
}
return res;
}
void main()
{
int bNum;
printf("Enter a Binary Number.\n");
scanf("%d",&bNum);
int res = toDecimal(bNum);
printf("Decimal of %d is %d\n",bNum , res);
}
// OUTPUT
// Enter a Binary Number.
// 1010
// Decimal of 1010 is 10
#include <stdio.h>
#include <stdbool.h>
bool isPrime(int num) {
for(int i = 2; i <= num / 2; i++) {
if(num % i == 0) {
return false;
}
}
return true;
}
void main()
{
int num;
printf("Enter a Number.\n");
scanf("%d",&num);
bool res = isPrime(num);
if(res) {
printf("%d is is Prime Number.\n",num);
} else {
printf("%d is Not Prime Number.\n",num);
}
}
// OUTPUT
// Enter a Number.
// 15
// 15 is Not Prime Number.
#include <stdio.h>
int greaterAmongTwo(int num1 , int num2) {
if(num1 > num2) {
return num1;
} else {
return num2;
}
}
void main()
{
int num1 , num2;
printf("Enter 1st number.\n");
scanf("%d",&num1);
printf("Enter 2nd number.\n");
scanf("%d",&num2);
int res = greaterAmongTwo(num1 , num2);
printf("%d is Greater among %d and %d",res , num1 ,num2);
}
// OUTPUT
// Enter 1st number.
// 5
// Enter 2nd number.
// 6
// 6 is Greater among 5 and 6
....
....
....
#Loading....
#Loading....
#Loading....
#Loading....
#Loading....
#Loading....
#Loading....