Coding exercise
Q(1).WPA to calculate circumference and area of circle using radius as a input.
Ans-
#include<stdio.h>
#include<conio.h>
#define pi 3.1416
int main(){
int r,cir,area;
printf("enter the radius of circle for circumfernce and area of it's\n");
scanf("%d",&r);
cir=2*pi*r;
area=pi*pow(r,2);
printf("the circumference of the circle is %d\n",cir);
printf("the area of circle is %d",area);
printf("execution done by Nabin sah");
return 0;
}
Result of this program –
Q(2).WAP to calculate the permutation{p(n,r)} and combination {c(n,r)} given n and r
are the inputs. Also write your own function to calculate factorial using recursion .
Ans-
#include<stdio.h>
#include<conio.h>
int fact(int n){
if(n<=1){
return 1;
}else{
return n*fact(n-1);
}
}
int main(){
int n,r,per,com;
printf("enter the valur of N and r\n");
scanf("%d%d",&n,&r);
per=fact(n)/fact(n-r);
com=fact(n)/fact(n-r)*fact(r);
printf("the value of permutation is %d\n",per);
printf("the value of combination is %d \n",com);
printf("written by Nabin sah");
return 0;
}
Execution of this program -
Q(3).WAP using structure to input the data of 10 teachers and display them .
The details of teachers include ,Name, Teacher id, subject taught, gradestotaught.
Ans-
#include<stdio.h>
#include<conio.h>
struct teacherinfo{
char name[20];
int teacherid;
int grades;
char subject[30];
}info[10];
void enter_detail(){
struct teacherinfo info[10];
for(int i=0;i<=9;i++){
printf("enter the details of teacher\n");
printf("teacher Name\n");
scanf("%s",&info[i].name);
printf("teacher id\n");
scanf("%d",&info[i].teacherid);
printf("teacher taught to which grades\n");
scanf("%d",&info[i].grades);
printf("subjects taughts by teachers\n");
scanf("%s",&info[i].subject);
}
}
void print_details(){
struct teacherinfo info[10];
for(int i=0;i<=9;i++){
printf("Teacher name=%s\n Teacher id = %d\n Teachers to teach garde=%d \n
teacher's subject =%s\n", info[i].name,info[i].teacherid,info[i].grades,info[i].subject);
}
}
int main(){
enter_detail();
print_details();
printf(“written by nabin sah”);
return 0;
}
Note- this program is too long SO I didn’t upload that result here.