Posts

Showing posts from April, 2021

write a programme to compare time stamp in c

 #include<stdio.h> #include<string.h> typedef struct time_stamp{ int year; int month; int date; int hour; int minute; int seacond; }time_stamp; void display(time_stamp dt1,time_stamp dt2){ printf("the time stamp is: %d/%d/%d-%d:%d:%d\n",dt1.year,dt1.month,dt1.date,dt1.hour,dt1.minute,dt1.seacond); //} //void display(time_stamp dt2){ printf("the time stamp is: %d/%d/%d-%d:%d:%d\n",dt2.year,dt2.month,dt2.date,dt2.hour,dt2.minute,dt2.seacond); } int time_stampcmp(time_stamp dt1,time_stamp dt2){ if(dt1.hour>dt2.hour){ return 1; } if(dt1.hour<dt2.hour){ return -1; } if(dt1.minute>dt2.minute){ return 1; } if(dt1.minute<dt2.minute){ return -1; } if(dt1.seacond>dt2.seacond){ return 1; } if(dt1.seacond<dt2.seacond){ return -1; }     if(dt1.year>dt2.year){ return 1; } if(dt1.year<dt2.year){ return -1; } if(dt1.month>dt2.month){ return 1; } if(d...

write a struct programme to keep bank details in c

#include<stdio.h> #include<string.h> struct customer{ int account_num; int IFSE_code; float Balance; char name[10]; }; int main() {    struct customer n1 = {6066,58741,9854123,"nilabhru"};    printf("%d\n",n1.account_num);  printf("%d\n",n1.IFSE_code);  printf("%0.3f\n",n1.Balance);  printf("%s\n",n1.name);   return 0; } 

write down a display programme for complex numbers in c

 #include<stdio.h> typedef struct complex{ int real; int imaginaey; }comp; void display(comp c){ printf("Enter the valuie of real number %d\n\n",c.real); printf("Enter the valuie of imaginary number %d\n\n",c.imaginaey); } int main() { comp complexnums[5]; for(int i=0;i<5;i++){ printf("Ente the real value for %d is num\n",i+1); scanf("%d",&complexnums[i].real); printf("Ente the imagenary value for %d is num\n",i+1); scanf("%d",&complexnums[i].imaginaey); }  for(int i=0;i<5;i++){ display(complexnums[i]); } return 0; }

Measuring string lenth in c

 #include<stdio.h> int strlen(char *st){ char *ptr = st; int len = 0; while(*ptr!='\0'){ len++; ptr++; } return len; } int main() { char st[] = "Harry"; int l = strlen(st); printf("The lenth of this string is %d",l); return 0; }

how to encrypt and decrypt a data in c

 #include<stdio.h> void encrypt(char *c){    char *ptr = c;    while(*ptr!= '\0'){     *ptr = *ptr + 2;     ptr++;    } } int main() { char c[] = "nilabhru come on amd fuck me"; encrypt(c); printf("Encrypted string is: %s",c); return 0; } #include<stdio.h> void decrypt(char *c){    char *ptr = c;    while(*ptr!= '\0'){     *ptr = *ptr - 2;     ptr++;    } } int main() { char c[] = "pkncdjtw eqog qp cof hwem og"; decrypt(c); printf("Decrypted string is: %s",c); return 0; }

structure formate in c

 #include<stdio.h> #include<string.h> struct employee{ int code; float salary; char name[10]; }; int main() {    struct employee e1 = {100,3645285,"nilabhru"};  /*struct employee e1;  e1.code = 100;  e1.salary = 34.542;*/   // strcpy(e1.name , "Nilabhru");    printf("%d\n",e1.code);  printf("%0.3f\n",e1.salary);  printf("%s\n",e1.name);   return 0; }

Usage of strcpy, strcat, strcmp (strings) in c

 #include<stdio.h> #include<string.h> int main() { char *st = "Nilabhru"; char st2[45]; strcpy(st2,st); printf("now the st2 is %s",st2); return 0; } #include<stdio.h> #include<string.h> int main() { char st1[45] = "Hello"; char *st2 = "Nilabhru"; strcat(st1,st2); printf("now the st2 is %s",st1); return 0; } #include<stdio.h> #include<string.h> int main() { char st1[45] = "Hello"; char *st2 = "Nilabhru"; int val = strcmp(st1,st2); printf("now the st2 is %d",val); return 0; }

Reverse printing in c

 #include<stdio.h> int i,team,arr; void reverse(int *arr, int n){ for(i=0;i<(n/2);i++){ team = arr[1]; arr[i] = arr[n-i-1]; arr[n-i-1] = team; } } int main() {   int arr[] = {1,2,3,4,5,6,7};   reverse(arr, 7);   for(i=0;i<7;i++){   printf("The value of %d element is: %d\n", i,arr[i]);   }   return 0; }

Making tabels with arry in c

 #include<stdio.h> int main() {    int mul[10],i,n;        printf("Enter the number which table you want\n");    scanf("%d", &n);        for( i=0; i<10; i++){     mul[i] = n*(i+1);    }    for( i=0; i<10; i++){     printf("%d*%d=%d\n",n,i+1,mul[i]);    } return 0; }

Making 2 dimentional arry in c

#include<stdio.h> int main() { int n_students = 2; int n_subjects = 6; int i,j; int markes[2][6]; for(i=0; i<n_students ; i++){ for(j=0; j<n_subjects ;j++){ printf("Enter the markes of students %d in subject %d \n",i+1,j+1); scanf("%d", &markes[i][j]); } } for(i=0; i<n_students ; i++){ for(j=0; j<n_subjects ;j++){ printf("The markes of students %d in subject %d is: %d\n",i+1,j+1,markes[i][j]); } } return 0; } 

printing value for arry in c

#include<stdio.h> int printArry(int *ptr, int n){ for(int i=0;i<n;i++){ printf("The value of element %d is & %d\n",i+1,ptr[i]); } ptr[2]= 555;//This value will be change in arry of main as well } int main() {     int arr[] = {45,445,4546,44,465};         printArry(arr,5) ;     printf("%d",arr[2]);     return 0; } 

print markes using Arry in c

 #include<stdio.h> int main() {    int markes[4],i;    int *ptr;    ptr = &markes[0];        for(i=0;i<4;i++){    printf("Enter the value of markes for student %d:\n",i+1);    scanf("%d",ptr);    ptr++;    }        for(i=0;i<4;i++){    printf("The value of markes for student %d is %d \n",i+1,markes[i]);    }     return 0; }

swaping value by using pointers in c

 #include<stdio.h> int swap ( int *a, int *b); int main() {    int x = 3, y = 4;    printf("The value of x and y before swap is %d and %d\n", x, y);    swap(&x,&y);//will work due to call by reference    printf("The value of x and y after swap is %d and %d\n", x, y); return 0; } int swap ( int *a, int *b){ int temp; temp = *a; *a = *b; *b = temp; }

calculate sum and average with pointers in c

 #include<stdio.h> void SumAndAvg( int a,  int b, int *sum, float *avg){ *sum = a + b; *avg = (float)(*sum)/2; } int main() {      int i, j, sum; float avg; printf("Enter the value of i %d"); scanf("%d", &i);     printf("Enter the value of j %d"); scanf("%d", &j);     SumAndAvg( i, j, &sum, &avg);      printf("The value of sum is %d\n", sum); printf("The value of avg is %f\n", avg); return 0; }

draw a star pattern in c

 #include<stdio.h> int main() {   int i,j,r,k=0;      printf("Enter number of rows:");   scanf("%d",&r);      for(i=1;i<=r;++i,k=0)   {   for(j=1;j<=r-i;++j)     {   printf(" ");     }   while(k != 2*i-1)   {   printf("*");   ++k;   }   printf("\n");    }  return 0; }

Find the Nth Fibonacci Number using Recursion in C

 #include<stdio.h> int fibo(int); int main() {     int num,result;       printf("Enter the nth number in fibonacci series: ");     scanf("%d", &num);          if (num < 0)     {         printf("Fibonacci of negative number is not possible.\n");     }     else     {         result = fibo(num);         printf("The %d number in fibonacci series is %d\n", num, result);     }     return 0; } int fibo(int num) {     if (num == 0)     {         return 0;     }     else if (num == 1)     {         return 1;     }     else     {         return(fibo(num - 1) + fibo(num - 2));     } }

calculate force in c

 #include<stdio.h> float force(float mass),result; int main() { float m; printf("Enter the value of mass  in kgs\n"); scanf("%f", &m); printf("The value of forcr in Newton is %.2f\n", force(m)); //%0.2f for numbers after decimal we need return 0; } float force(float mass){ result = mass*9.8; return result; }