You are on page 1of 3

1.

Write a C program for Addition of 2 complex number with the help of


structures

#include <stdio.h>
struct complex
{
float re;
float img;
};
void main()
{
struct complex a,b,c;
scanf("%f%f",&a.re,&a.img);
scanf("%f%f",&b.re,&b.img);
c=add(a,b);
printf("\n%f%f",c.re,c.img);
}
struct complex add (x,y)
struct complex x,y;
{
struct complex t;
t.re=x.re+y.re;
t.img=x.img+y.img;
return(t);
}

2. Write a C program for Addition of 2 complex number with the help of


structures and pointers

#include <stdio.h>
struct complex
{
float re;
float img;
};
void main()
{
struct complex a,b,c;
scanf("%f%f",&a.re,&a.img);
scanf("%f%f",&b.re,&b.img);
c=add(a,b);
printf("\n%f%f",c.re,c.img);
}
void add (x,y,t)
struct complex *x,*y,*t;
{
t->re=x->re+y->re;
t->img=x->img+y->img;
}

3. Write a C program to create a student class with elements reg no,


name, cgpa. Using switch case; sort the class according to each pf the
three elements of the structure

#include<stdio.h>
struct student
{
int roll;
char name[25];
float cgpa;
};
void main()
{
struct student class[100],t;
int j,k,n;
scanf("%d",&n);
for(k=0;k<n;k++)
{
scanf("%d%s%f",&class[k].roll,&class[k].name,&class[k].cgpa);
}
for(j=0;j<n-1;j++)
for(k=j+1;k<n;k++)
{
if(class[j].roll>class[k].roll)
{
t=class[j];
class[j]=class[k];
class[k]=t;
}
}

You might also like