ArpitB

Codes

Aug 15th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.38 KB | None | 0 0
  1. //Q 6.
  2. #include <stdio.h>
  3.  
  4. long power (int, int);
  5.  
  6. int main()
  7. {
  8.     int pow, num;
  9.     long result;
  10.  
  11.     printf("Enter a number: \n");
  12.     scanf("%d", &num);
  13.     printf("Enter it's power: \n");
  14.     scanf("%d", &pow);
  15.     result = power(num, pow);
  16.     printf("%d^%d is %ld", num, pow, result);
  17.     return 0;
  18. }
  19.  
  20. long power (int num, int pow)
  21. {
  22.     if (pow)
  23.     {
  24.         return (num * power(num, pow - 1));
  25.     }
  26.     return 1;
  27. }
  28.  
  29.  
  30. //Q 7.
  31.  
  32. #include<stdio.h>
  33. #include<string.h>
  34.  
  35. int main() {
  36.    char str[100], temp;
  37.    int i, j = 0;
  38.  
  39.    printf("\nEnter the string :");
  40.    gets(str);
  41.  
  42.    i = 0;
  43.    j = strlen(str) - 1;
  44.  
  45.    while (i < j) {
  46.       temp = str[i];
  47.       str[i] = str[j];
  48.       str[j] = temp;
  49.       i++;
  50.       j--;
  51.    }
  52.  
  53.    printf("\nReverse string is :%s", str);
  54.    return (0);
  55. }
  56.  
  57.  
  58. //Q 8.
  59.  
  60. #include <stdio.h>
  61. #include <string.h>
  62.  
  63. void delchar(char *x,int a, int b);
  64.  
  65. void main()
  66. {
  67. char string[10];
  68. int n,pos,p;
  69.  
  70. printf("Enter the string \n");
  71. scanf("%s",string);
  72. printf("Enter the position from where to delete: \n");
  73. scanf("%d",&pos);
  74. printf("Enter the number of characters to be deleted: \n");
  75. scanf("%d",&n);
  76. printf("Final string is: ");
  77. delchar(string, n,pos);
  78. }
  79.  
  80. // Function to delete n characters
  81. void delchar(char *x,int a, int b)
  82. {
  83. if ((a+b-1) <= strlen(x))
  84.   {
  85.   strcpy(&x[b-1],&x[a+b-1]);
  86.   puts(x);
  87.   }
  88. }
  89.  
  90. //Q 9.
  91.  
  92. #include <stdio.h>
  93. #include <string.h>
  94.  
  95. struct employee
  96. {
  97.      int id;
  98.      char name[30];
  99.      int age;
  100.      int salary;
  101.      
  102. };
  103.  
  104. int main()
  105. {
  106.      int i;
  107.      struct employee record[10];
  108.  
  109.     for(i=0; i<10; i++)
  110.      {
  111.          printf("Enter details of employee %d :  \n", i+1);
  112.        
  113.          printf("Enter Id : ");
  114.          scanf("%d", &record[i].id);
  115.          printf("\n");
  116.          
  117.          printf("Enter Name : ");
  118.          scanf("%s", record[i].name);
  119.          printf("\n");
  120.          
  121.          printf("Enter Age : ");
  122.          scanf("%d", &record[i].age);
  123.          printf("\n");
  124.          
  125.          printf("Enter Salary : ");
  126.          scanf("%d", &record[i].salary);
  127.          printf("\n\n");
  128.          
  129.          
  130.      }
  131.      printf("\n");
  132.      for(i=0; i<10; i++)
  133.      {
  134.          printf("Records of Employee : %d \n", i+1);
  135.          printf("Id is: %d \n", record[i].id);
  136.          printf("Name is: %s \n", record[i].name);
  137.          printf("Age is: \n",record[i].age);
  138.          printf("Salary is: \n",record[i].age);
  139.           printf("\n");
  140.      }
  141.      return 0;
  142. }
  143.  
  144.  
  145. //Q 10.
  146.  
  147. #include <stdio.h>
  148. struct student
  149. {
  150.     char name[50];
  151.     int roll;
  152.     float marks;
  153. } s[10],*p[10];
  154.  
  155. int main()
  156. {
  157.     int i;
  158.     int Pointer[10];
  159.     for(i = 0; i< 10; i++){
  160.         p[i] = &s[i];
  161.     }
  162.  
  163.     printf("Enter information of students:\n");
  164.  
  165.     // storing information
  166.     for(i=0; i<10; ++i)
  167.     {
  168.         s[i].roll = i+1;
  169.  
  170.         printf("\nFor roll number%d,\n",s[i].roll);
  171.        
  172.         printf("Enter name: ");
  173.         scanf("%s",s[i].name);
  174.  
  175.         printf("Enter marks: ");
  176.         scanf("%f",&s[i].marks);
  177.  
  178.         printf("\n");
  179.     }
  180.  
  181.     printf("Displaying Information:\n\n");
  182.     // displaying information
  183.     for(i=0; i<10; ++i)
  184.     {
  185.         printf("\nRoll number: %d\n",i+1);
  186.         printf("Name: ");
  187.         puts(p[i]->name);
  188.         printf("Marks: %.1f",p[i]->marks);
  189.         printf("\n");
  190.     }
  191.     return 0;
  192. }
Add Comment
Please, Sign In to add comment