C (assign- 20-25) 🎆




meine apne prespective se question kiya

toh koi or suggestion ho toh batana


ankh khol kar likhna mein ankh

band karke codes likhta huu


Q20. 

//value

#include <stdio.h>
void swap(int, int);
void main()
{
    int n1, n2;
    printf("Enter the two numbers to be swapped\n");
    scanf("%d%d", &n1, &n2);
    printf("\nBefore Swap n1=%d n2=%d", n1, n2);
    swap(n1, n2);

}

void swap(int n1, int n2)
{
    int temp;
    temp = n1;
    n1 = n2;
    n2 = temp;
    printf("\nAfter Swap n1=%d n2=%d", n1, n2);
}


// ref..
#include <stdio.h>
void swap1(int *num1, int *num2);
int main()
{
    int num1, num2;
    printf("Enter two numbers: ");
    scanf("%d%d", &num1, &num2);
 
    printf("\nBefore swap of num1 = %d num2 = %d \n", num1, num2);
    swap1(&num1, &num2);
    return 0;
}
void swap1(int *num1, int *num2)
{
    int temp;
    temp = *num1;
    *num1 = *num2;
    *num2 = temp;
    printf("\nAfter Swap of num1 = %d num2 = %d", *num1, *num2);
}


Q.21

#include <stdio.h>
void main()
{
    int arr1[20];
    int i, n, sum = 0;
    int *pt;
    printf(" Input the number of elements to store in the array (max 20) : ");
    scanf("%d", &n);

    printf(" Input %d number of elements in the array : \n", n);
    for (i = 0; i < n; i++)
    {
        printf(" element - %d : ", i + 1);
        scanf("%d", &arr1[i]);
    }

    pt = arr1;

    for (i = 0; i < n; i++)
    {
        sum = sum + *pt;
        pt++;
    }

    printf(" The sum of array is : %d\n\n", sum);
}



Q22.

// 22. Design a structure student to contain name, roll no,
// total marks obtained.Write a program to print percentage along with the information.
#include <stdio.h>
#include <stdlib.h>
struct student
{
    char name[20];
    int roll_no;
    float per;
    int physics, chem, maths, com, eng, total;
};
void main()
{
    struct student s[10], temp;
    int n, i, j;
    printf("Enter the number of students :");
    scanf("%d", &n);
    for (i = 1; i <= n; i++)
    {

        printf("Enter the student's name, roll number and marks in five subjects: ");
        scanf("%s %d %d %d %d %d %d", s[i].name, &s[i].roll_no, &s[i].physics, &s[i].chem, &s[i].com, &s[i].eng, &s[i].maths);
        s[i].total = s[i].physics + s[i].chem + s[i].maths;
        s[i].per = ((s[i].total * 100) / 500);
    }
    printf("\nName\tRollNo\tPhysics\tChem\tMaths\tComputer\tEnglish\t\tTotal\tPercentage  \n");
    for (i = 1; i <= n; i++)
    {
        printf("%s\t%d\t%d\t%d\t%d\t%d\t\t%d\t\t%d\t%f\n", s[i].name, s[i].roll_no, s[i].physics, s[i].chem, s[i].maths, s[i].com, s[i].eng, s[i].total, s[i].per);
    }
}



Q23.

// Design a union employee to contain emp_name, deptment, designation and salary.Write a program to print employee information.
#include <stdio.h>
#include <stdlib.h>
union employe
{
    char name[20];
    char department[1];
    char designation[1];
    float salary;
};
void main()
{
    union employe s;

    printf("\nEnter the employe's name ");
    scanf("%s", s.name);
    printf("the employe's name is : %s\n\n", s.name);

    printf("Enter the department ");
    scanf("%s", s.department);
    printf("the department is: %s \n\n", s.department);

    printf("Enter the designation ");
    scanf("%s", s.designation);
    printf("the designation is : %s \n\n", s.designation);

    printf("Enter the salary : ");
    scanf("%f", &s.salary);
    printf("the salary is : %f ", s.salary);

   
}


24. 

 problem solved 😶‍🌫️

// Write a program to open a file employee and store the following information in it.
// a.Emp_id
//     b.Emp_name
//         c.Department
//             d.Salary

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

int main()
{
    char name[20];
    char department[10];
    char designation[10];
    float salary;

    FILE *ptr;
    ptr = fopen("employ.txt", "w");

    printf("\nEnter the employe's name ");
    scanf("%s", name);
    printf("Enter the department ");
    scanf("%s", department);
    printf("Enter the designation ");
    scanf("%s", designation);
    printf("Enter the salary : ");
    scanf("%f", &salary);
    fprintf(ptr, "Name: %s\t department: %s \tdesignation :%s \t salary: %f \n", name, department, designation, salary);
    fclose(ptr);
    return 0;
}




Q25.

problem solved😶‍🌫️

// Write a program to open a file book and store the following information in it
//.a.title
//     b.author
//         c.pages
//             d.prize

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

int main()
{
    char title[20];
    char author[15];
    int pages;
    float price;

    FILE *ptr;
    ptr = fopen("book.txt", "w");

    printf("\nEnter the title ");
    scanf("%s", title);

    printf("Enter the author ");
    scanf("%s", author);

    printf("Enter the pages ");
    scanf("%d", &pages);

    printf("Enter the price: ");
    scanf("%f", &price);
    fprintf(ptr, "Title: %s\t Author: %s \tpages:%d\tprice: %f \n", title, author, pages, price);

    fclose(ptr);
    return 0;
}





Comments

Popular posts from this blog

O.S. MIDSEM by god

O.S. UNIT 5 (QUES/ANS)

MINI project format >> 1st sem