diff --git a/1.c b/1.c new file mode 100644 index 0000000..bb44abf --- /dev/null +++ b/1.c @@ -0,0 +1,35 @@ +// 1+3^3/3!+5^5/5! + +#include + +int main(){ + int num,i,factorial=1,power=1,j,n; + float sum=0; + + printf("Enter a number of the sum: "); + scanf("%d",&num); + + for(i=1;i<=2*num;i++){ + //Since we have to get numeritor + //not affected by the previous calculation so pro =1 + if(i %2 ==0){ + continue; + } + else{ + power=1; + factorial=1; + //incase of factorial is get affected since the + //facotial of number has not so facotial = 1 been used by previous calculation + for(j=1;j<=i;j++){ + factorial =factorial*j; + power=power*i; + } + } + + sum=sum+(power*1.0/factorial); + printf("%f\n",sum); + } + + printf("the sum is: %f",sum); + return 0; +} diff --git a/12.c b/12.c new file mode 100644 index 0000000..428c32a --- /dev/null +++ b/12.c @@ -0,0 +1,31 @@ + + +//1/1!+2^2/2!+3^3/3!.....nth term. + + +#include + +int main(){ + int num,i,factorial=1,power=1,j; + float sum=0; + + printf("Enter a number of the sum: "); + scanf("%d",&num); + + for(i=1;i<=num;i++){ + //Since we have to get numeritor + //not affected by the previous calculation so pro =1 + power=1; + //incase of factorial it does not get affected since the + //facotial of number has been used by previous calculation + factorial =factorial*i; + for(j=1;j<=i;j++){ + power=power*i; + } + sum=sum+(power*1.0/factorial); + printf("%f\n",sum); + } + printf("the sum is: %f",sum); + return 0; +} + diff --git a/TOH.c b/TOH.c new file mode 100644 index 0000000..026e3ae --- /dev/null +++ b/TOH.c @@ -0,0 +1,23 @@ +//wAP for table of hanoi. + +#include + +int TOH(int, int, int, int); + +int main(){ + int n,A=1,B=2,C=3; + printf("Enter a number of disc: "); + + scanf("%d",&n); + TOH(n, A,B,C); +} + +int TOH(int n,int A,int B,int C){ + +if(n > 0){ + TOH (n-1,A,C,B); + printf("move a disk %d to %d\n",A,C); + TOH(n-1,B,A,C); +} +} + diff --git a/Untitled1.c b/Untitled1.c new file mode 100644 index 0000000..16b6030 --- /dev/null +++ b/Untitled1.c @@ -0,0 +1,20 @@ +#include +#include + +int main(){ + int num1,num2; + do{ + printf("Enter a first number: "); + scanf("%d",&num1); + printf("Enter a secound number: "); + scanf("%d",&num2); + } + while(num1 >num2); + + for(num1;num1<=num2;num1++){ + if(num1 % 5 == 0){ + printf("%d is divisible by 5 \n",num1); + } + } + return 0; +} diff --git a/Untitled2.c b/Untitled2.c new file mode 100644 index 0000000..f05c5b0 --- /dev/null +++ b/Untitled2.c @@ -0,0 +1,25 @@ +//1/1!+2^2/2!+3^3/3!.....nth term. + + +#include + +int main(){ + int num,i,factorial=1,power=1,j; + float sum=0; + + printf("Enter a number of the sum: "); + scanf("%d",&num); + + for(i=1;i<=num;i++){ + power=1; + for(j=1;j<=i;j++) + factorial =factorial*i; + power=power*i; + + } + sum=sum+(power*1.0/factorial); + printf("%f\n",sum); + } + printf("the sum is: %f",sum); + return 0; +} diff --git a/Untitled3.c b/Untitled3.c new file mode 100644 index 0000000..57cf327 --- /dev/null +++ b/Untitled3.c @@ -0,0 +1,24 @@ +#include +#include + +int main(){ + int num,i,count=0; + + printf("Enter a number: "); + scanf("%d",&num); + + for(num;num>=1;num--){ + count = 0; + for(i=1;i<=num;i++){ + if(num % i == 0) + { + count++; + } + } + if(count == 2) + { + printf("\n %d is prime number",num); + } +} + return 0; +} diff --git a/fun10_SalaryRealated.c b/fun10_SalaryRealated.c new file mode 100644 index 0000000..9f74e9b --- /dev/null +++ b/fun10_SalaryRealated.c @@ -0,0 +1,28 @@ +/* WAP to input salary of a person and claculate travel allowence (10% of salary) +daily allowencce (12% of alsary) tax(15% of salary) also +calculate net salary of person */ + +#include + +int net_salary(int); + +//Name: Sumit Ojha + +int main() { + int salary; + + printf("Enter the salary of the person: "); + scanf("%d",& salary); + + printf("the net salary is : %d\n", net_salary(salary)); +return 0; +} + + +int net_salary(int i){ + int tra, dai, tax; + tra = 10.0/100*i; + dai = 12.0/100*i; + tax = 15.0/100*i; +return (dai+tra-tax); +} diff --git a/fun11_to_find_odd_n_even.c b/fun11_to_find_odd_n_even.c new file mode 100644 index 0000000..517702e --- /dev/null +++ b/fun11_to_find_odd_n_even.c @@ -0,0 +1,22 @@ +//WAP to find the odd and even number using conditions. + +#include + +int num (int); +int main() { + int n; + printf("Enter a num: "); + scanf("%d",&n); + num(n); +return 0; +} + +int num (int i){ + if (i % 2 == 0){ + printf("its even: %d", i); +} + else{ + printf("its odd: %d", i); + } +return num; +} diff --git a/fun12_incrementdecrement.c b/fun12_incrementdecrement.c new file mode 100644 index 0000000..7216507 --- /dev/null +++ b/fun12_incrementdecrement.c @@ -0,0 +1,26 @@ +//WAP to display the value of a and b or each Line +//a = ++ + ++a +//b = a-- - --a + +#include + +// Name: Sumit Ojha + +int first(int); +int second(int,int); + +int main() { +int a = 10 , b = 5; + +printf("++ + ++a = %d\n", first(a)); +printf("a-- - --b = %d\n", second(a,b)); +return 0; +} + +int first (int i){ +return (i = + i + ++i); +} + +int second(int i, int j) { +return (j = i-- - --j); +} diff --git a/fun13_conv.c b/fun13_conv.c new file mode 100644 index 0000000..e4c4b23 --- /dev/null +++ b/fun13_conv.c @@ -0,0 +1,39 @@ +/*WAP to input height in feet and inch, weight in kg, +convert height into inches and again convert into meters, now divide your weight by +square of your height in meters and finally assign o/p to variable constant factors +*/ + +#include + +float inches (float, float); +float meter (float, float); +float ratio (float, float, float); + +int main() { + float feet1, inches1, weight1, meter1, ratio1; + + printf("Enter the height in feet, inches and weight: "); + scanf("%f %f %f",&feet1, &inches1,&weight1); + + inches1 = inches (inches1, feet1); + printf("the height in inches is: %f \n", inches1); + + meter1=meter(meter1, inches1); + printf("the inches in meter is: %f \n", meter1); + + ratio1=ratio(ratio1, weight1, meter1); + printf("the value of div of your weight sqr of height: %f \n", ratio1); + return 0; +} + +float inches (float i, float j){ +return (i = i+(j*12)); +} + +float meter(float i, float j){ +return (i = 0.254*j); +} + +float ratio (float i ,float j , float k){ +return (i = j/(k*k)); +} diff --git a/fun14_temp.c b/fun14_temp.c new file mode 100644 index 0000000..965ade8 --- /dev/null +++ b/fun14_temp.c @@ -0,0 +1,30 @@ +/*WAP to read the tempr in farenheight and disply the message as follows nice day: temp >60 and and temp <80 , cold day: temp <=60 and hot day: tempr>=80. */ + +#include + +int tep(int); + +//Name: Sumit Ojha. + +int main(){ + float temp; + + printf("Enter temp: "); + scanf("%f",&temp); + tep(temp); + + return 0; +} + +int tep(int i){ + if (i > 60 && i < 80){ + printf("it's a nice day."); +} + else if(i <= 60){ + printf("it's a cold day."); +} + else if (i >=80){ + printf("it's a hot day."); +} +return tep; +} diff --git a/fun15_raterealted.c b/fun15_raterealted.c new file mode 100644 index 0000000..5e77cbd --- /dev/null +++ b/fun15_raterealted.c @@ -0,0 +1,54 @@ +/*An organization is dealing in two items say a and b provide the comission on the scale of there according to the following polocy. +commission rate for is 6% up to scale is 2000 if the scale of these according to following policy*/ + +#include + +float product(float, float); + +// Name: Sumit Ojnd + +int main(){ + int a,b; + product(a,b); +return 0; +} + +float product(float i, float j){ + char product; + float com_i_1, com_j_1, com_i_2, com_j_2; + + printf("Enter the product name: "); + scanf("%c",&product); + + if (product=='a'){ + printf ("enter the price of a: "); + scanf("%f",&i); + + if (i <= 2000){ + com_i_1 = 6.0/100*i; + printf("the comission on a is: %.2f",com_i_1); + } + + else if (i > 2000){ + com_i_2 =(2000*6.0/100)+(i-2000)*7.0/100; + printf("the comission on a is: %.2f \n", com_i_2); + } + } + + else if (product=='b'){ + printf ("enter the price of b: "); + scanf("%f",&j); + + if (j <= 4000) + { + com_j_1 = 10.0/100*j; + printf("the comission on b is: %.2f",com_j_1); + } + else if(j < 4000) + { + com_j_2 = (4000*10.0/100)+(j-2000)*12.0/100; + printf("the comission on b is: %.2f \n", com_j_2); + } + } + return product; +} diff --git a/fun16_factorial.c b/fun16_factorial.c new file mode 100644 index 0000000..53cb713 --- /dev/null +++ b/fun16_factorial.c @@ -0,0 +1,25 @@ +//WAP to do the factorail of the given number: + + +#include +int factorial(int); + +int main(){ + int n; + + printf("Enter a number: "); + scanf("%d",&n); + + printf("the facorial of nis : %d", factorial(n)); + return 0; +} + +int factorial(int a){ + int fact; + + if(a==1){ + return a; +} + fact = a*factorial(a-1); + return fact; +} diff --git a/fun2_cal.c b/fun2_cal.c new file mode 100644 index 0000000..ce25d23 --- /dev/null +++ b/fun2_cal.c @@ -0,0 +1,52 @@ +#include + +/* +Name: Sumit Ojha. +*/ + +//Funtion prototype. +int sum(int, int); +int sub(int, int); +int di(int, int) ; +int pro(int, int); +int mod(int, int); + +//Funtion declaration. +int main(){ +int a,b; + +printf("Enter two number: "); +scanf("%d %d",&a,&b) ; + +printf("the sum is : %d\n",sum(a,b)); +printf("“the sub is : %d\n",sub(a,b)); +printf("the di is: %d\n",di(a,b)); +printf("the pro is: %d\n",pro(a,b)); +printf("the mod is: %d\n",mod(a,b)); +return 0; +} + + +//Funtion defination +int sum(int i, int j){ +return (i+j); +} + +int sub(int i,int j){ +return(i-j); +} + +int di(int i,int j){ +return (i/5); +} + +int pro(int i,int j){ +return (i*j); +} + +int mod(int i, int j){ +return(i%j); +} + + + diff --git a/fun3_SI.c b/fun3_SI.c new file mode 100644 index 0000000..e0c9f81 --- /dev/null +++ b/fun3_SI.c @@ -0,0 +1,31 @@ +//WAP to find the simple intrest +/* + +Name: Sumit Ojha + +*/ + +#include + +//prototype +float si(float, float, float) ; + +//declaration +int main(){ +float t,r,p; + +printf("Enter the value of P,T,R: "); +scanf ("%f %f %f",&p,&t,&r); + +printf("the SI is: %.2f",si(p,t,r)); + +return 0; +} +//defination +float si(float i,float j, float k){ +float si; +si = (i*j*k)/100; +return(si); +} + + diff --git a/fun4_to_dis_the_val_of_char.c b/fun4_to_dis_the_val_of_char.c new file mode 100644 index 0000000..36af4e1 --- /dev/null +++ b/fun4_to_dis_the_val_of_char.c @@ -0,0 +1,22 @@ +//WAP to to display the value of char. + +//Name: Sumit Ojha. + +#include + +//prototype +char ch(char); + +//declaration +int main(){ +char a; + printf("Enter a char: "); + scanf("%c",&a); + ch(a); +return 0; + +//defination +char ch(char i) { + printf("%c:%d",i,i); +return ch; +} diff --git a/fun5_cal_area_of_circle.c b/fun5_cal_area_of_circle.c new file mode 100644 index 0000000..d740195 --- /dev/null +++ b/fun5_cal_area_of_circle.c @@ -0,0 +1,24 @@ +//WAP to calculate the area of cirlce: + +#include +#define pi 3.14 + +//prototype +float area(float); + + +//declartion +int main(){ + float r; + printf("Enter the radious of the circle: "); + scanf("%f",&r); + printf("the area of the circle is : %f", area(r)); +return 0; +} + +//defination +float area(float i) { +float area; +area = pi * i* i; +return area; +} diff --git a/fun6_to_cal_roots_of_a_quad_eqns.c b/fun6_to_cal_roots_of_a_quad_eqns.c new file mode 100644 index 0000000..edd8475 --- /dev/null +++ b/fun6_to_cal_roots_of_a_quad_eqns.c @@ -0,0 +1,35 @@ +//WAP to calculate roots of a quad egn. + +/* +Name: Sumit Ojha. +*/ + +#include +#include + +//funtion prototype +float ri (int , int ,int); +float r2 (int , int , int); + +//funtion calling +int main(){ + int a,b,c; + + printf("Enter three numbers: "); + scanf("%d %d %d",&a,&b,&c); + + printf("first root: %.2f \n", r1(a,b,c)); + printf("Second root: %.2f \n", r2(a,b,c)); + +return 0; +} + +//funtion defination +float r1(int i, int j, int k){ + return ((-j+pow((j*j-4*i*k), 0.5))/(2*i)); +} + + +float r2(int i, int j, int k){ + return ((-j-pow((j*j-4*i*k), 0.5))/(2*i)); +} diff --git a/fun7_to_cal_the_vol_n_area_of_square.c b/fun7_to_cal_the_vol_n_area_of_square.c new file mode 100644 index 0000000..8ee8b78 --- /dev/null +++ b/fun7_to_cal_the_vol_n_area_of_square.c @@ -0,0 +1,28 @@ +//WAP to calculate the volume and area of sphere + +/* +Name: Sumit Ojha +*/ + +#include +#define pi 3.14 + +float vol (float); +float area (float); + +int main(){ + float r; + printf("Enter the value of radious: "); + scanf("%f",&r); + printf("the volume: %\n", vol(r)); + printf("the area: %f\n", area(r)); + return 0; +} + +float vol (float i) { +return(4.0/3*pi*i*i*i); +} + +float area(float i) { +return(4*pi*i*i); +} diff --git a/fun8relatedwithage.c b/fun8relatedwithage.c new file mode 100644 index 0000000..fcd9c25 --- /dev/null +++ b/fun8relatedwithage.c @@ -0,0 +1,24 @@ +//WAP to read the age in year, month and days and convert it into number of days. + +#include + +/* +Name: Sumit Ojha +*/ + +int days(int, int, int); + +int main(){ +int a,b,c; + printf("Enter the year, months, days: "); + scanf("%d %d %d",&a,&b,&c); + printf("the total number of days are: %d", days(a,b,c)); +return 0; +} + + +int days(int i, int j, int k){ + int days; + days = ((2022-i)*365)+(j*30)+k; +return days; +} diff --git a/fun9_relatedToDays.c b/fun9_relatedToDays.c new file mode 100644 index 0000000..7c05fe9 --- /dev/null +++ b/fun9_relatedToDays.c @@ -0,0 +1,30 @@ +//WAP to rad the number of days and conver it into years and months. + +#include + +int years_months(int); + +int main(){ + int days; + + printf("Enter number of days: "); + scanf("%d",&days); + + years_months(days); + return 0; +} + +int years_months(int i){ + int years, months, days, remaining_days; + years =i/365; + remaining_days =i % 365; + months = remaining_days / 30; + i= remaining_days % 30; + + printf("number of years: %d\n", years); + printf("number of months: %d\n", months); + printf("number of days: %d\n", i); + + return years_months; +} + diff --git a/sumofnth3.c b/sumofnth3.c new file mode 100644 index 0000000..885a68a --- /dev/null +++ b/sumofnth3.c @@ -0,0 +1,35 @@ +// 1+3^3/3!+5^5/5!......nth term + +#include + +int main(){ + int num,i,factorial=1,power=1,j,n; + float sum=0; + + printf("Enter a nth term to sind the sum of the number: "); + scanf("%d",&num); + + for(i=1;i<=2*num;i++){ + //Since we have to get numeritor + //not affected by the previous calculation so pro =1 + if(i %2 ==0){ + continue; + } + else{ + power=1; + factorial=1; + //incase of factorial is get affected since the + //facotial of number has not so facotial = 1 been used by previous calculation + for(j=1;j<=i;j++){ + factorial =factorial*j; + power=power*i; + } + } + + sum=sum+(power*1.0/factorial); + printf("%f\n",sum); + } + + printf("the sum is: %f",sum); + return 0; +}