Saturday, 1 January 2022

Recurtions

 //Why are recursions?

//We can solve difficult long iteratively can be
solved simply recursively.
// there are some problems which suited to be
solved recursively.
// eg. tower of Hanoi, Fibonacci series,
factorial finding.

#include <stdio.h>
int factorial(int number)
{
    if(number == 1 || number == 0)
    {
    return 1;
    }
    else{
        return (number * factorial(number-1));
    }

}
int main ()
{
    int num;
    printf ("Enter the number which factorial value you want: ");
    scanf ("%d", &num);

    printf ("The factorial value of %d is %d.",num, factorial(num));
    return 0;
}

output:_ Enter the number which factorial value you want: 7 The factorial value of 7 is 5040.

Wednesday, 22 December 2021

function

 // functions are besic tools by using them we will be able to

break our programme in small segments.

// funtion can be called multiple times and can provide our
c programme reusebility & modularity.
// function is also known as subroutine and procedure.
because by using this we break intire routine into small
sub-routine.
// we can avoid logic rewriting through function.
// we can devide wrok among programmer using functions.
// we can easily debug programme by finding the function
with error.
// function with bug will needed to debug and rest won't
need to be change.

// declaration, defining & calling a function.
// A function is declared to tell the compiler about its existence.
// declaration of a function is the process of calling
the compiler about it's existence.
(compiler ko function ke bare me batana)
// A function is defined to get some task done.
(It means when we define function we write
whole code of that function. In this actual implementation
of function is done.)
// (exectly function {code} he kya)
// defining a function is to get some certain task done
// A function is called in order to be used.
// (function ko use hone ke liya bulana)
// calling a function is to use it.
// types of function 1.library function 2.user defined function
// library functions are predefined functions of a programming
language.(basiclly include in header files)
// user defined function also known as created by user function
to reduse the hustle & complexcibility of a c-programme.
// besic function code example
// 1.without argument(condition,input) and return value.
// 2.with argument (condition,input) but without return value.
// 3.without argument (condition,input) but with retuen value.
// 4.with argument (condition,input) and return value.

#include <stdio.h>
int sum(int a, int b); // with argument and return value.
void printstar (int n);//without argument but retuen value.
int takenumber();//with argument but without return value.
void myname()
{
    printf ("my name is hemansh");
}
int main()
{
    int a,b,c,d,n;
    a = 46;
    b = 34;
    c = sum(a,b);

    // d=takenumber();
    // printstar(1);
    // printf ("he sum is %d",c);
    // printf ("The number entered is %d.",d);
    myname();

    return 0;
}

 int sum(int a, int b)
{
    return a+b;
}


 void printstar (int n)
{
    for (int i = 0; i < n; i++)
    {
        printf ("%c",'*');
        // ""ke ander string & ''ke andar character
lete he.
       
    }
}


 int takenumber()
{
    int i;
    printf ("Enter a number: \n");
    scanf ("%d", &i);
    return i;
}

//additional
#include <stdio.h>
void name()
{
    printf ("My name is Hemansh.\n");
   
}
void printhash (int n)
{
    int i;
    for ( i = 0; i < n; i++)
    {
        printf ("%c\n",'#');

    }
   
}
int enternum()
{
    int num;
    printf ("enter a number: \n");
    scanf ("%d",&num);
    return num;
}
int sumnum()
{
    int a;
    int b;
    printf ("Enter the first number: ");
    scanf ("%d", &a);

    printf ("Enter the second number: ");
    scanf ("%d", &b);

    return a+b;
}

int main()
{
    name();
    printhash(4);
    int c;
    c=enternum();
    printf ("The number entered is %d.\n",c);
    int a,b,d;
   
    d = sumnum(a,b);
    printf ("The sum is %d.\n",d);
   
    return 0;
}
output:_
My name is Hemansh. # # # # enter a number: 23 The number entered is 23. Enter the first number: 81 Enter the second number: 256 The sum is 337.


Saturday, 18 December 2021

typecasting

 // what typecasting is?

// typecasting is the process of inter-converting one data type
to another.
// ek data type ko dusre data type me change karne ki process
ko typecasting kahte he.
// to tpyecast a specific data usse pahle ("") ke andr vo data
type likhte he jo type karana ho.
// float b= 54/5, then b will be 10 not 10.8 because both
54&5 integer he to result integer hi hoga.
#include <stdio.h>
int main()
{
    int a = 3;
    float b = (float)54/5;
    printf ("the value of a is %f\n", (float)a);
    printf ("the value of b is %f\n", b);
    return 0;
}
output:_
the value of a is 3.000000 the value of b is 10.800000

go to statement

obstacle statements:

continue, break and goto statements are obstacles use to terminate our programme.

1.continue statement me only aapka continue ke bad ka code jo loop me he execute nhi oga baki pahle ke loop ka code tab tak execute hoga jab tak loop ki condition false na ho jaye.

2.break statement ka use karne par code jese hi break statement ko reach karega vo break statement jis corresponding loop me hoga usko terminate kar dega.

3.goto statement is also known as the ultimate obstacle, jese hi code goto statement ko reach karga sabhi corresponding loops ko break karke out of loop dal dega. 

// go to statement as its name it calls our programme to go

where it (go to statement) tells to go.

// it is also knon as jump statement.
// it transfers the programme to the pre-difined lable.
// it is prefer not to use go to statement because less
understandable to your fellow programmers.
// but still is used to break miltiple loops in just one
statement.
// besic syntex of go statement is that:
/* {
    lable
    printf ("     ");
    ..
    ..
    ..
    ..
    go to lable;
}*/

// exanple:_1
#include <stdio.h>
int main()
{
lable:
    printf("we are in a lable.\n");

    printf("hello  world");
    goto lable;

    return 0;
}
output:_
we are in lable.
hello world
............infinite loop
............
we are in lable.
hello world

// example:_2
#include <stdio.h>
int main()
{
lable:
    printf("we are in a lable.\n");
    goto end;
    printf("hello  world");
    goto lable;
end:
    printf("hullo world");

    return 0;
}
output:_
we are in a lable.
hullo world



Friday, 17 December 2021

break & continue

 // break statements are used to bring the program out of the loop.

// usually break statements are used inside loops & switch statements.

// continue statement is used to skip some portion of the loop and
the code will jump to the next iteration.
//It is so important when we want to skip some lines of code for
a particular condition.

#include <stdio.h>
int main()
{
    char name[20];
    int age;
    printf ("enter your name: \n");
    scanf ("%s", &name);

    printf ("hello %s, how are you?\n");
    printf ("hope you will be fine.\n");

    for (int i = 1; i < 11; i++)
    {
        // senario_1 there is no obstacle in the path of code.
        // senario_2 there is continue statement.
(continue ke bad wala code terminate hoga.)
        // senario_3 there is break statement.
(break ke bad ka complete loop hi terminate ho jayega.)
        printf ("%d\n", i);
        break;
        printf ("enter you age: \n");
        scanf ("%d", &age);
    }
    return 0;
   
}
different output in different scenario:_
scenario:_1 {no obstacle}
(jab tak loop condition false nhi ho gayi tab tak loop chala.)
PS E:\c programming> cd "e:\c programming\" ; if ($?)
{ gcc breakcont.c -o breakcont } ; if ($?) { .\breakcont } enter your name: lalu hello lalu, how are you? hope you will be fine. 1 enter you age: 23 2 enter you age: 29 3 enter you age: 29 4 enter you age: 0 5 enter you age: 0 6 enter you age: 9 7 8 8 enter you age: 7 9 enter you age: 6 10 enter you age: 5
scenario:_2{continue statement}(continue statement se pahle wala pura
loop code chala)
# yaha what is your age wala code execute nhi hua because usse pahle
continue statement tha and for loop ke ander ka complete
i wala code chala.
PS E:\c programming> cd "e:\c programming\" ; if ($?)
{ gcc breakcont.c -o breakcont } ; if ($?) { .\breakcont }
enter your name: 
kalu
hello kalu, how are you?
1
2
3
4
5
6
7
8
9
10
scenario:_3 {break statement}(jaha par break statement aa gaya vahi se
complete loop terminate ho gaya.)
#yaha loop only loop ke initial output 1 ko print karke hi terminate ho
gaya.
PS E:\c programming> cd "e:\c programming\" ; if ($?)
{ gcc breakcont.c -o breakcont } ; if ($?) { .\breakcont } enter your name: bhalu hello bhalu, how are you? hope you will be fine. 1



Monday, 13 December 2021

for loop

 // why use for loop?

// for loop is used to breakdown a prt of program several times.
// it has a little different structure then do-while & whlie loop.
// besic syntex of for loop:
/*
for (size_t i = 0(expression:_1); i < count(condition:_2); i++ = i+1(expression:_3))
{
    // code to be execute //
}
*/  

/*#include <stdio.h>
int main()
{
    int num;

    printf ("enter the number which's table you want to be print: ");
    scanf ("%d", &num);

    for ( int i = 1, j=3
   
    //ex:_1 is the initialization of for loop//
    // 2. we can initialise more then one variablein for loop.
    // 3. agar variavle ki value pahle hi define ho rakhi he then
ex:_1 ki koi need nhi hoti.
    // so ex:_1 isn't not must.
    ; i < 11
   
    //ex:_2 is basically a conditional expression hota he,
    // isme basically ioop termination ki condition likhi hoti he,
    // 2. agar as ex:_2 multiple ocnditions ho then only last
condition ko true consider kiya jayega.
    /*for (size_t i = 0; i < 4(con1), j<6(con2); i++) is eg me
only con2 ko true consider kiya jayega.
    {
        //code //
     }*/
    // only last condition ko true mana jayega and baki sab ko
as it is execute kar diya jayega.
    /*for (size_t i = 0; i=4(con1),j>5(con2); i++)
    yaha only condition 2 follow hogi and con 1 as it as execute ho jayegi
    con1 ko as statement treat kiya jayega
    {
        // code //
    }
   
   
    ; i++)
    // ex:_3 is used to update(change karne ke liye)
the value of the corresponding variable.
    // 2. we can change values of more then one variable in
ex:_3 like:_i++,J++ karke.
    // 3. ex:_3 is also optioanl hota he, not must,
isko printf statement ke bad bhi likh sakte he.
    {
        printf ("%d * %d= %d\n", num,i,num*i);
        // vvvvvvvvvv. importent thing to note
        // here a imp stuff is that ki printf statement ke ander
jitne bhi  data type symbols use,
        // vo jis indentity se relate karte he ""end hone ke bad ,
lagakar ek ek karke mention kar,
        // liye ye instruct kiya jat he ki konsa symbol kis identity
ko represent karta he.

        printf ("%d",j);
    }

    // printf ("hello rishabh");
    return 0;

}*/
// project:_1(table)
#include <stdio.h>
int main()
{
    int num;
    printf ("enter the number which's table you want to print: ");
    scanf ("%d", &num);
    for (int i = 1; i < 11;)        
    {
    printf ("%d * %d= %d\n",num,i,num*i);
    i=i+1;
    }
    return 0;

}
// project_2
#include <stdio.h>
int main()
{
    int i;
    int j;
    for ( i = 0;j= 3, i < 10; i++,j++)    
    {
       printf ("%d %d\n",i,j);
    }
    return 0;
}


while loop

 // whlie loop is almost similar to "do whlie loop".

// but the basic difference over here is that ki jaha do while at
least ek bar to execute hota hi he,
// but whlie tabhi me code tabhi execute hoga jab whlie condition
true hogi otherwise nhi.
// whlie loop me string litteral statement me ";" nhi use hota he.
// besic syntex of whlie loop:
/* while (condition)
{
    // code to executed //(no semicolon)
}*/
#include <stdio.h>

int main(int argc, char const *argv[])
{
    int i = 0;
    printf ("enter a number less then 15: ");
    scanf ("%d", &i);
   
    while (i < 15)
    {

        printf("%d\n", i);
        i = i+1;
    }
    return 0;
}

do-while loop

 // do whlie loop at ek bar to execute hota hi he.

// ek bar execute hone ke bad ye condition tak execute hota hi rahega,
// and condition flase hone par he loop se exit ho jayega.
// besic syntex of do while loop
/* do{
    /code to be executed./
} while (condition)
eg.
{
    int i=0;
do
{
    i=i+1;
    printf ("%d", i);
} whlie (i<10)
return 0;
}*/

#include <stdio.h>
int main()
{
    int num;
    int index=0;
    printf ("enter the number:\n");
    scanf ("%d",&num);

    do{
        printf ("%d\n", index+1);
        index= index+1;

    } while(index<num);

    return 0;

}
// project:_2
/*#include <stdio.h>
int main()
{
    int num;
    int sum=0;
    do
    {
        printf ("enter the number: ");
        scanf ("%d",&num);
        sum +=num;

    } while (num != 0);
    printf ("the sum is= %d", sum);

    return 0;
   
}*/
/*#include <stdio.h>
int main()
{
    int n, sum = 0;
    do
    {  
printf("Enter a number: ");
scanf("%i", &n);
        sum += n;
    }
    while(n != 0);
    printf("Sum is = %d",sum);

    return 0;
}*/



Sunday, 12 December 2021

loops

 // why do we make a program and do all those coding stuff?

// simply by programming & coding we want to instruct your machine
to perform the task we want to be performed.
// loops are like a superior weapon for programmers to
make their programs more efficient and convenient.
//If a programmer wants to write a specific code for n times
(more than one time) with traditional methods,
// he has to face a lot of hustle to create an efficient program.
//At this point loop helps a programmer a lot by doing all that
repetition stuff.
// types of loops:_ 1. do while loop 2. while loop 3. for loop
//

// project:_1 (counting)
#include <stdio.h>

int main()
{
    int num;

    printf("enter the number where you want to start counting:\n");
    scanf("%d", &num);

    printf("counting from %d is as follows:\n", num);

    for (int i = 0; i < 10; i++)
    {
        printf("%d\n", num + i);
    }

    return 0;
}

Saturday, 11 December 2021

switch statement

 // besically switch case statement is a conviniance stuff for user.

// syntex for switch case statement is that
/*
{   int a;

    switch (a){
        case 3;
        printf ("valuec is 2");

        case 4;
        printf ("value id 4")
        ..
        ..
        default:
        printf ("noting matched")

 
    }
rules for a switch case statement
1. The switch expression must be an integer or character.
2. The case also must be an integer or character.
3. break isn't a must.
4. The case must come inside the switch.
5. break ke bad wala switch statement execute nhi hota break is used to
terminate code.
6. switch ke ander bhi switch statement dala ja sakta he.  
*/

#include <stdio.h>
int main ()
{
    int age;
    printf ("enter your age:\n");
    scanf ("%d", & age);

    int marks;
    printf ("enter your marks:\n");
    scanf ("%d", & marks);

    switch (age)
    {
    case 3:
        printf("your age is 3\n");
        switch (marks)
        {
        case 9:
            printf ("your marks are 9\n");
            break;
       
        default:
        printf ("your marks aren't 9\n");
            break;
        }
        break;
   
    case 13:
        printf("your age is 13\n");
        break;

    case 23:
        printf ("your age is 23\n");
        break;
   
    default:
        printf ("age isn't 3,13 & 23");
        break;
    }
    return 0;
}

additional:_2

#include <stdio.h>
void main()
{
    char name;
    int code;

    printf("enter the code\n");
    printf("enter 1 to print your first name:\n");
    printf("enter 2 to print your last name:\n");
    scanf ("%d",&code);

    switch (code)
    {
    case 1:
        printf ("my first name is hemansh\n");
        break;
   
    case 2:
        printf ("my last name is mishra\n");
        break;

    default:
        break;
    }
    return 0;

}
// pw course fee assitent program
/*#include <stdio.h>
int main()
{
    int num;
    char name;
    printf ("enter your name\n");
    scanf ("%c", &name);

    printf ("enter the class course of which you want to buy:\n");
    scanf ("%d", &num);

    switch (num)
    {
    case 10:
        printf ("Fee of your course is ₹2499/-\n");
        break;

    case 11:
        printf ("Fee of your course is ₹3499/-\n");
        break;

    case 12:
        printf ("Fee of your course is ₹4499/-\n");
        break;

    default:
        printf ("no course is available for you.\n");
        break;

        return 0;
    }

}*/
//modified form of this is below.

// project:_16 (pw home page with switch statement)
#include<stdio.h>
int main()
{
    char name[20];
    int num;
    char mail[20];
    int class;

    printf ("Please enter your name: \n");
    scanf ("%s", &name);

    printf ("Please enter your contect number: \n");
    scanf ("%d", &num);

    printf ("Please enter your contect EMAIL ID: \n");
    scanf ("%s", &mail);

    printf ("enter the class of whose course you want: \n");
    scanf ("%d", &class);

    printf ("%s, you have entered %dth as your class, ",name,class);

    switch (class)
    {
    case 10:    
        printf ("fee for class %dth course is ₹2499 only.\n", class);
        break;

    case 11:
        printf ("fee for class %dth course is ₹3499 only.\n", class);
        break;

    case 12:
        printf ("fee for class %dth course is ₹4499 only.\n", class);
        break;
 
    default:
    printf (" sorry! %s there is no course available for class %dth at this time.\n", name,class);
    printf ("we will notify you when course will available for class %dth.\n", class);

    break;
    }
}
output:_ Please enter your name: prafull Please enter your contect number: 9057513102 Please enter your contect EMAIL ID: prafull07@gmail.com enter the class of whose course you want: 10 prafull, you have entered 10th as your class, fee for class 10th course is ₹2499 only.

// exercise:_1 (claculator)
#include <stdio.h>
int main()
{
    char name[20];
    printf ("Enter your name: ");
    scanf ("%s", &name);

    printf ("Hello %s! welcome to NUMBx your maths friend toolkit,\n");
    printf ("who is always prepare to solve your mathemetical problems,\n");
    printf ("So let's begin.\n");

    float a,b;

    printf ("a: ");
    scanf ("%f", &a);

    printf ("b: ");
    scanf ("%f", &b);

    int o;
    printf ("press 1 for addtion.\n");
    printf ("press 2 for substraction.\n");
    printf ("press 3 for multiply.\n");
    printf ("press 4 for divide.\n");
    scanf ("%d", &o);

    switch (o)
    {
    case 1:
        printf ("The result is: %.2f\n", a+b);
        break;

    case 2:
        printf ("The result is: %.2f\n", a-b);
        break;

    case 3:
        printf ("The result is: %.2f\n", a*b);
        break;

    case 4:
        printf ("The result is: %.2f\n", a/b);
        break;

    default:
        printf ("sorry! you have entered wrong input.\n");
        break;
    }
    printf ("thanks for using NUMBx.");
    return 0;
}
output:_
Enter your name: prafull Hello prafull! welcome to NUMBx your maths friend toolkit, who is always prepare to solve your mathemetical problems, So let's begin. a: 203 b: 10.15 press 1 for addtion. press 2 for substraction. press 3 for multiply. press 4 for divide. 4 The result is: 20.00 thanks for using NUMBx.


Recurtions

  //Why are recursions? //We can solve difficult long iteratively can be solved simply recursively. // there are some problems which suite...