Friday 25 June 2021

function in c programs

 function in c 

#include <stdio.h>
int Area_Square(int side); // prototype

int main()
{
    int c;
    c = Area_Square(45);
    printf("Area of Square is %d"c);

    return 0;
}
int Area_Square(int side)
{
    int c;
    c = side * side;
    return c;
}



# include<stdio.h> 
void display();
 int main(){ 
int a ;
printf("initial statement  \n ");
display();
printf("final ending function \n ");
     
     return 0
}

void display(){

    printf("Display can be seen ! \n "); 
}


#include <stdio.h>
void good_morning();
void good_afternoon();
void good_night();

int main()
{
    good_morning();
    good_afternoon();
    good_night();

    return 0;
}

void good_morning()
{
    printf("Hello buddy Good Morning! \n");
}
void good_afternoon()
{
    printf("Hello buddy Good Afternoon! \n");
}
void good_night()
{
    printf("Hello buddy Good Night! \n");
}



#include <stdio.h>
int sum(int a); // function prototype
int main()
{
    int numberc;
    printf("enter the number to sum");
    scanf("%d"&number);
    c = sum(number);
    printf("sum is %d"c);

    return 0;
}

int sum(int a)
{
    if (a != 0)
    {
        return a + sum(a - 1);
    }
    else
    {
        return a;
    }
}


#include <stdio.h>
int factorial(int a); // prototype
int main()
{
    int a = 10;
    printf("the value of fac %d is %d"afactorial(a));

    return 0;
}

int factorial(int a)
{
    printf("calling function %d \n"a);
    if (a == 1 || a == 0)
    {
        return 1;
    }

    else
    {
        return a * factorial(a - 1);
    }
}


# include<stdio.h> 
# include<math.h>

 int main(){ 
int side;
printf("enter the side \n");
scanf("%d",&side);
printf("The area of square is %f \n",pow(side,2));
     
     return 0
}




C project random number generator problem

 Random number Generator problem

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{

    int numberguessn_guess = 1;
    srand(time(0));
    number = rand() % 100 + 2;
    // printf("The random number is %d \n", number);

    do
    {
        printf("Enter the guess number from 2-100 : \n");
        scanf("%d"&guess);
        if (guess < number)
        {
            printf("Please Enter Higher Number! \n");
        }
        else if (guess > number)
        {
            printf("Please Enter Lower Number ! \n");
        }
        else
        {
            printf("You Guessed at %d attempts \n"n_guess);
        }
        n_guess++;

    } while (guess != number);

    return 0;
}

C programs Strings Question and problems

 string problems 

#include <stdio.h>

int main()
{
    char str[13= "Upendra Yadav";
    char *ptr = str;
    for (int i = 0i < 13i++)
    {
        printf("%c"*ptr);
        ptr++;
    }

    char st[] = "Upendra Bhai";
    printf("%s"st);

    return 0;
}


#include <stdio.h>

int main()
{
     char str1[10];
     char str2[10];
     char c;

     printf("enter the name of Users:");
     scanf("%s"str1);
     printf("%s"str1);

     return 0;
}


#include <stdio.h>
int strlen(char *str)
{
  char *ptr = str;
  int len = 0;
  while (*ptr != '\0')
  {
    len++;
    ptr++;
  }
  return len;
}
int main()
{

  char str[] = "UpendraYadav";
  int l = strlen(str);
  printf("The length of string is %d"l);

  return 0;
}


#include <stdio.h>

int main()
{

    char str[] = "Upendra";
    char *ptr = str;
    int n = 0;
    while (*ptr != '\0')
    {
        n++;
        ptr++;
    }
    printf("the length of string is %d "n);

    return 0;
}


#include <stdio.h>
void slice(char *strint aint b)
{
    int i = 0;

    while (i < b)
    {

        str[i= str[i + a];

        i++;
    }
    str[i= '\0';
}
int main()
{
    char str[] = "Upendraduiadhuaduha";
    slice(str110);
    printf("%s"str);

    return 0;
}


# include<stdio.h> 
# include<string.h>
 int main(){ 
char st[]="Upendra";
char st1[20];

strcpy(st1,st);
printf("%s",st1);
     
     return 0
}


#include <stdio.h>

int main()
{

    char st[] = "Upendra";
    char *ptr = st;

    return 0;
}


# include<stdio.h> 
void Encript(char *c){
    char *ptr=c;
    while (*ptr!='\0')
    {
        *ptr=(*ptr-65)/45;
        ptr++;
    }
    
}
 int main(){ 
char c[]="Hey Guys  Come To come I want U";
Encript(c);
printf("Encript message is :%s",c);
     
     return 0
}


# include<stdio.h> 
void Decript(char *c){
    char *ptr=c;
    while (*ptr!='\0')
    {
        *ptr=*ptr;
        ptr++;
    }
    
}
 int main(){ 
char c[]="BCCABCCCAABCCCABCACCCCABACCCCAB";
Decript(c);
printf("decript message is :%s",c);
     
     return 0
}


#include <stdio.h>
int Counting(char *c)
{
    char *ptr = c;
    int n = 0;
    while (*ptr != '\0')
    {
        n++;
        ptr++;
    }
    return n;
}
int main()
{
    char c[] = "Upendra";
    int a = Counting(c);
    printf("No . of character in given string is %d"a);

    return 0;
}


#include <stdio.h>
int Occurence(char *cchar b)
{
    char *ptr = c;
    int n = 0;
    while (*ptr != '\0')
    {
        if (*ptr == b)
        {
            n++;
        }
        ptr++;
    }
    return n;
}
int main()
{

    char c[] = "Yadav8888888";
    int b = Occurence(c'8');
    printf("%d time occurced"b);
    return 0;
}


#include <stdio.h>
void check_ch(char *cchar a)
{
    char *ptr = c;
    while (*ptr != '\0')
    {
        if (*ptr == a)
        {
        }
        ptr++;
    }
    printf("character is present");
}
int main()
{

    char c[] = "Yogesh";
    check_ch(c'a');
    return 0;
}


#include <stdio.h>

int main()
{
   char str[] = {'U''P''E''N''D''R''A''\0'};
   char *ptr = str;
   while (*ptr != '\0')
   {
      printf("%c"*ptr);
      ptr++;
   }

   return 0;
}


#include <stdio.h>
#include <string.h>
int main()
{

    char *str1 = "Upendra";
    char str2[10= "Upendra";
    int val = strcmp(str1str2);
    printf("The value us %d"val);

    return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
    char str1[20= "hello";
    char *str2 = "Upendra";

    strcat(str1str2);
    printf("Hey bro %s"str1);

    return 0;
}


#include <stdio.h>

int main()
{
     char str[20];
     printf("Enter Urs name:\n");
     scanf("%s"str);
     printf("Your name is %s"str);

     return 0;
}


#include <stdio.h>

int main()
{
    char str[50];
    printf("Enter Urs Name:");
    gets(str);
    puts(str);

    return 0;
}


# include<stdio.h> 

 int main(){ 

     char *ptr="Upendra Yadav";
     char ptr1[]="Upendra Yadav";
     printf("%s\n",ptr);
     printf("%s",ptr1);

     return 0
}



C programs Structs problems

 # include<stdio.h>

# include<string.h>
struct employee{
    int code;
    float salary;
    char name[15];

};
 int main(){ 
struct employee e1,e2,e3;

printf("enter the employee Id ");
scanf("%d"&e1.code);
printf("enter the employee salary "); 
scanf("%f"&e1.salary);
printf("enter the employee name ");
scanf("%s"&e1.name);

printf("enter the employee Id ");
scanf("%d"&e2.code);
printf("enter the employee salary ");
scanf("%f"&e2.salary);
printf("enter the employee name ");
scanf("%s"&e2.name);

printf("enter the employee Id ");
scanf("%d"&e3.code);
printf("enter the employee salary ");
scanf("%f"&e3.salary);
printf("enter the employee name ");
scanf("%s"&e3.name);

     
     return 0
}


# include<stdio.h> 
# include<string.h>
struct employees{
    int code;
    float salary;
    char name[15];

};
void show(struct employees e){

printf("employees id is %d\n",e.code);
printf("employees salary is %f\n",e.salary);
printf("employees name is %s\n",e.name);

}

 int main(){ 
     struct employees e1={100,123.25,"Upendra"};
     show(e1);

     
     return 0
}



#include <stdio.h>
#include<string.h>
struct employees
{
    int code;
    float salary;
    char name[15];
};
int main()
{
    struct employees e1;
    struct employees *ptr = &e1;
    ptr->code = 120;
    ptr->salary = 120.254
    strcpy(ptr->name,"Upendra");
    
    printf("employees id is %d  \n",e1.code);
    printf("employees id is %f \n",e1.salary);
    printf("employees id is %s  \n",e1.name);
    

    return 0;
}



#include <stdio.h>
#include <string.h>
struct employees
{
    int code;
    float salary;
    char name[50];
};

int main()
{

    struct employees facebook[10];
    facebook[0].code=250;
    facebook[0].salary=253.25;
   strcpy (facebook[0].name,"Upendra");
    facebook[1].code=250;
    facebook[1].salary=253.25;
   strcpy (facebook[1].name,"Upendra");
    facebook[2].code=250;
    facebook[2].salary=253.25;
   strcpy (facebook[2].name,"Upendra");
    facebook[3].code=250;
    facebook[3].salary=253.25;
   strcpy (facebook[3].name,"Upendra");
   printf("Done");

    return 0;
}




# include<stdio.h> 
# include<string.h>
struct employee{
    int code;
    float salary;
    char name[15];

};


 int main(){ 
     struct employee e1;
     e1.code=125;
     e1.salary=256.30;
     strcpy(e1.name,"Upendra");
     printf("Employee id is %d\n",e1.code);
     printf("Employee salary is %.2f\n",e1.salary);
     printf("Employee Name is %s\n",e1.name);
    
     
     

     
     return 0
}




# include<stdio.h> 
#include<string.h>
typedef struct employees
{
    int code;
    float salary;
    char name[15];
   
}emp;

 int main(){ 
 emp e1;
    emp *ptr = &e1;
    ptr->code = 120;
    ptr->salary = 120.254
    strcpy(ptr->name,"Upendra");
    
    printf("employees id is %d  \n",e1.code);
    printf("employees id is %f \n",e1.salary);
    printf("employees id is %s  \n",e1.name);
    
     
     return 0
}



# include<stdio.h> 
# include<string.h>
typedef struct student_marks{
    int marks;
    char name[15];
    char subjects[10];
}marks;


 int main(){ 
     marks m1;
     marks *ptr=&m1;
     ptr->marks=45;
   strcpy(ptr->subjects,"Maths");
   strcpy(ptr->name,"Upendra");
   printf("%d \n",m1.marks);
   printf("%s \n",m1.subjects);
   printf("%s \n",m1.name);
     
     


     
     return 0
}



# include<stdio.h> 
typedef struct points_function{
    float x;
    float y;
}points;

void display(points p){
    printf("the points are (x,y) is (%d,%d) \n ",p.x,p.y);


}
 int main(){ 
     points p[5];
     for (int i = 0i < 5i++)
     {
        printf("enter the number in x axis of point %d:",i+1);
        scanf("%f",&p[i].x);
        printf("enter the number in y axis of point %d:",i+1);
        scanf("%f",&p[i].y);
     }
     for (int i = 0i < 5i++)
     {
        display(p[i]);
     }
     



     
     return 0
}



#include <stdio.h>
typedef struct vector
{
    int x;
    int y;

vec;

vec sumVector(vec v1,vec v2){
    vec results;
    results.x=v1.x+v2.x;
    results.y=v1.y+v2.y;
    printf("the sum of x axis of vector is %d \n",results.x);
    printf("the sum of y axis of vector is %d \n",results.y);


}
int main(){
    vec v1v2sum;
    v1.x = 20;
    v1.y = 40;
    v2.x = 10;
    v2.y = 50;
    sum= sumVector(v1,v2);


    return 0;
}


#include <stdio.h>
typedef struct complex_no
{
    int real;
    int complex;

com;
void dispaly(com c){
    printf("the value of real part of complex num is %d \n"c);
    printf("the value of imaginary part of complex num is %d \n"c);
}

int main()
{
    com cnums[5];
    for (int i = 0i < 5i++)
    {
        printf("Enter the value of real %d num:\n"i + 1);
        scanf("%d",&cnums[i].real);
        printf("Enter the value of imaginary  %d num:\n"i + 1);
        scanf("%d",&cnums[i].complex);
    }
    for (int i = 0i < 5i++)
    {
        dispaly(cnums[i]);
    }

    return 0;
}



#include <stdio.h>
#include <string.h>
typedef struct bank_account
{
    int Account_number;
    char Name[20];
    float deposit;
    char Branch[25];
account;

void display(account *cint b)
{
    for (size_t i = 0i < 5i++)
    {
        printf("the Acount number of customer %d is: %d \n"i + 1, (*c).Account_number);
        printf("the Name of customer %d is: %s \n"i + 1, (*c).Name);
        printf("the Amount Desposited by of customer %d is: %f \n"i + 1, (*c).deposit);
        printf("the Branch of customer %d is:%s \n"i + 1, (*c).Branch);
    }
}

int main()
{
    account customer[5];
    for (int i = 0i < 5i++)
    {
        printf("Enter the Account number of Customer %d:\n"i + 1);
        scanf("%d"&customer[i].Account_number);
        printf("Enter the Name of Customer %d:\n"i + 1);
        scanf("%s"&customer[i].Name);
        printf("Enter the Amount Deposit by of Customer %d:\n"i + 1);
        scanf("%f"&customer[i].deposit);
        printf("Enter the Branch of Customer %d:\n"i + 1);
        scanf("%s"&customer[i].Branch);
    }
    display(customer5);

    return 0;
}



#include <stdio.h>
typedef struct timestamp
{
    int date;
    int month;
    int year;
    int hours;
    int minutes;
    int seconds;
time;
void display(time c)
{
    printf("the Timestamp is %d-%d-%d\t%d:%d:%d\n"c.datec.monthc.yearc.hoursc.minutesc.seconds);
}
int Time_comp(time c1,time c2){
if (c1.seconds>c2.seconds)
{
    return 1;
}
else if (c1.seconds<c2.seconds)
{
    return -1;
}
else if (c1.minutes>c2.minutes)
{
   return 1;

}
else if (c1.minutes<c2.minutes)
{
    return -1;
}
else if (c1.hours>c2.hours)
{
    return 1;
}
else if (c1.hours<c2.hours)
{
    return -1;
}
else if (c1.year>c2.year)
{
    return 1;
}
else if (c1.year<c2.year)
{
    return -1;
}
else if (c1.month>c2.month)
{
    return 1;
}
else if (c1.month<c2.month)
{
    return -1;
}
else if (c1.date>c2.date)
{
    return 1;
}
else if (c1.date<c2.date)
{
    return -1;
}

return 0;





}

int main()
{

    time T1 = {25062020126012};
    time T2 = {25062020126012};
    display(T1);
    display(T2);
    int c = Time_comp(T1T2);
    printf("the value return after comparison is %d",c);

    return 0;
}




Python if / else

 Python if / else a1 = int ( input (" Enter the number: \n ")) a2 = int ( input (" Enter the number: \n ")) a3 = int ( i...