Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Q 6.
- #include <stdio.h>
- long power (int, int);
- int main()
- {
- int pow, num;
- long result;
- printf("Enter a number: \n");
- scanf("%d", &num);
- printf("Enter it's power: \n");
- scanf("%d", &pow);
- result = power(num, pow);
- printf("%d^%d is %ld", num, pow, result);
- return 0;
- }
- long power (int num, int pow)
- {
- if (pow)
- {
- return (num * power(num, pow - 1));
- }
- return 1;
- }
- //Q 7.
- #include<stdio.h>
- #include<string.h>
- int main() {
- char str[100], temp;
- int i, j = 0;
- printf("\nEnter the string :");
- gets(str);
- i = 0;
- j = strlen(str) - 1;
- while (i < j) {
- temp = str[i];
- str[i] = str[j];
- str[j] = temp;
- i++;
- j--;
- }
- printf("\nReverse string is :%s", str);
- return (0);
- }
- //Q 8.
- #include <stdio.h>
- #include <string.h>
- void delchar(char *x,int a, int b);
- void main()
- {
- char string[10];
- int n,pos,p;
- printf("Enter the string \n");
- scanf("%s",string);
- printf("Enter the position from where to delete: \n");
- scanf("%d",&pos);
- printf("Enter the number of characters to be deleted: \n");
- scanf("%d",&n);
- printf("Final string is: ");
- delchar(string, n,pos);
- }
- // Function to delete n characters
- void delchar(char *x,int a, int b)
- {
- if ((a+b-1) <= strlen(x))
- {
- strcpy(&x[b-1],&x[a+b-1]);
- puts(x);
- }
- }
- //Q 9.
- #include <stdio.h>
- #include <string.h>
- struct employee
- {
- int id;
- char name[30];
- int age;
- int salary;
- };
- int main()
- {
- int i;
- struct employee record[10];
- for(i=0; i<10; i++)
- {
- printf("Enter details of employee %d : \n", i+1);
- printf("Enter Id : ");
- scanf("%d", &record[i].id);
- printf("\n");
- printf("Enter Name : ");
- scanf("%s", record[i].name);
- printf("\n");
- printf("Enter Age : ");
- scanf("%d", &record[i].age);
- printf("\n");
- printf("Enter Salary : ");
- scanf("%d", &record[i].salary);
- printf("\n\n");
- }
- printf("\n");
- for(i=0; i<10; i++)
- {
- printf("Records of Employee : %d \n", i+1);
- printf("Id is: %d \n", record[i].id);
- printf("Name is: %s \n", record[i].name);
- printf("Age is: \n",record[i].age);
- printf("Salary is: \n",record[i].age);
- printf("\n");
- }
- return 0;
- }
- //Q 10.
- #include <stdio.h>
- struct student
- {
- char name[50];
- int roll;
- float marks;
- } s[10],*p[10];
- int main()
- {
- int i;
- int Pointer[10];
- for(i = 0; i< 10; i++){
- p[i] = &s[i];
- }
- printf("Enter information of students:\n");
- // storing information
- for(i=0; i<10; ++i)
- {
- s[i].roll = i+1;
- printf("\nFor roll number%d,\n",s[i].roll);
- printf("Enter name: ");
- scanf("%s",s[i].name);
- printf("Enter marks: ");
- scanf("%f",&s[i].marks);
- printf("\n");
- }
- printf("Displaying Information:\n\n");
- // displaying information
- for(i=0; i<10; ++i)
- {
- printf("\nRoll number: %d\n",i+1);
- printf("Name: ");
- puts(p[i]->name);
- printf("Marks: %.1f",p[i]->marks);
- printf("\n");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment