-
-
Save bikashthapa01/90e8f132e3099fa855eae3612e89713b to your computer and use it in GitHub Desktop.
Lab Works 1 programs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Write a program to find simple interest using function | |
#include <stdio.h> | |
float simpleInterest(int p, int t, int r); | |
int main(){ | |
int p,t,r; | |
float si; | |
printf("Enter principle : \n"); | |
scanf("%d",&p); | |
printf("Enter Time : \n"); | |
scanf("%d",&t); | |
printf("Enter Rate of Interest : \n"); | |
scanf("%d",&r); | |
si = simpleInterest(p,t,r); | |
printf("Simple Interest is: %0.2f",si); | |
return 0; | |
} | |
float simpleInterest(int p, int t, int r){ | |
return p*t*r/100; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Write a program to find greatest number among four different numbers | |
#include <stdio.h> | |
int greatestNumber(int a, int b, int c , int d); | |
int main(){ | |
int a,b,c,d,max; | |
printf("Enter Four Numbers to find Greatest Number: \n"); | |
scanf("%d%d%d%d",&a,&b,&c,&d); | |
max = greatestNumber(a,b,c,d); | |
printf("Greatest Number is %d.",max); | |
return 0; | |
} | |
int greatestNumber(int a, int b, int c , int d){ | |
if(a>b && a>c && a>d){ | |
return a; | |
}else if(b>a && b>c && b > d){ | |
return b; | |
}else if(c > a && c > b && c > d ){ | |
return c; | |
}else { | |
return d; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void printTable(int); | |
int main(){ | |
int n; | |
printf("Enter number to print multiplication Table: \n"); | |
scanf("%d",&n); | |
printTable(n); | |
return 0; | |
} | |
void printTable(int n){ | |
int i; | |
for(i=1;i<=10;i++){ | |
printf("%d x %d = %d\n", n,i,n*i); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int sum(int n, int numbers[]); | |
int main(){ | |
int n,i,s,a; | |
printf("Enter Size of Array: \n"); | |
scanf("%d",&n); | |
int numbers[n]; | |
for(i=0;i<n;i++){ | |
printf("Enter Array Element: \n"); | |
scanf("%d",&numbers[i]); | |
} | |
s = sum(n,numbers); | |
a = s/n; | |
printf("Sum = %d \nAverage = %d",s,a); | |
return 0; | |
} | |
int sum(int n, int numbers[]){ | |
int s = 0; | |
int j; | |
for(j=0;j<n;j++){ | |
s += numbers[j]; | |
} | |
return s; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int findMax(int n, int numbers[]); | |
int main(){ | |
int n,i,max; | |
printf("Enter Size of Array: \n"); | |
scanf("%d",&n); | |
int numbers[n]; | |
for(i=0;i<n;i++){ | |
printf("Enter Array Element: \n"); | |
scanf("%d",&numbers[i]); | |
} | |
max = findMax(n,numbers); | |
printf("Greatest Number is %d.",max); | |
return 0; | |
} | |
int findMax(int n, int numbers[]){ | |
int i,max; | |
max = numbers[0]; | |
for(i=0;i<n;i++){ | |
if(max<numbers[i]){ | |
max = numbers[i]; | |
} | |
} | |
return max; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment