Posts

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; }