0% found this document useful (0 votes)
39 views

CSE PDF

This document contains 15 code snippets written in C programming language. Each snippet demonstrates a different programming concept such as: calculating the sum of two numbers, multiplying three float numbers, finding the largest of two or three numbers, calculating GPA based on test scores, calculating employee payment based on regular/overtime hours, calculating the distance between two points, and calculating price discounts of different tiers. The snippets each include comments describing their purpose and use basic conditional and mathematical operations like if-else statements, loops, and square root functions.

Uploaded by

Badhon Rahman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

CSE PDF

This document contains 15 code snippets written in C programming language. Each snippet demonstrates a different programming concept such as: calculating the sum of two numbers, multiplying three float numbers, finding the largest of two or three numbers, calculating GPA based on test scores, calculating employee payment based on regular/overtime hours, calculating the distance between two points, and calculating price discounts of different tiers. The snippets each include comments describing their purpose and use basic conditional and mathematical operations like if-else statements, loops, and square root functions.

Uploaded by

Badhon Rahman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

//sum two number

#include<stdio.h>
#include<math.h>
int main(){
int num1, num2, sum;
scanf("%d %d", &num1, &num2);
sum = num1 + num2;
printf("Result: %d",sum);
return 0;
}

//Multiplication threee float number


#include<stdio.h>
int main(){
float num1, num2, num3, multi;
scanf("%f %f %f", &num1, &num2, &num3);
multi = num1 * num2 * num3;
printf("Multiplication result is: %f", multi);
return 0;
}

//from two number large number found


#include<stdio.h>
int main(){
int a, b;
scanf("%d %d", &a, &b);
if(a>b){
printf("%d is large number.", a);
}
else{
printf("%d is large number.", b);
}
return 0;
}

// GPA calculation
#include<stdio.h>
int main(){
int result = 56;
if(result>=80){
printf("Result is A+");
}
else if(result>=70){
printf("Result is A");
}
else if(result>=60){
printf("Result is A-");
}
else{
printf("Fail in the exam");
}
return 0;
}

//gpa calculation
#include<stdio.h>
int main(){
int result;
scanf("%d", result);
if(result>=90){
printf("Result is A");
}
else if (result >= 80){
printf("Result is B");
}
else if(result >= 70){
printf("Result is C");
}
else if(result >= 60){
printf("Result is D");
}
else{
printf("Result is F");
}

return 0;
}

//largest number from three number


#include<stdio.h>
int main(){
int a,b,c;
scanf("%d %d %d", &a, &b, &c);
if(a>b && a>c){
printf("Largest number %d",a);
}
else if(b>a && b>c){
printf("Largest number: %d",b);
}
else{
printf("Largest number: %d",c);
}
return 0;
}
//large number from three number
#include<stdio.h>
int main(){
int num1,num2,num3;
scanf("%d %d %d", &num1 ,&num2 ,&num3);
if(num1>num2 && num1>num3){
printf("%d",num1);
}
else if(num2>num1 && num2>num3){
printf("%d",num2);
}
else{
printf("%d",num3);
}
return 0;
}

//find largest number from two number;

#include<stdio.h>
int main(){
int num1,num2;
scanf("%d %d",&num1,&num2);
if(num1>num2){
printf("%d",num1);
}
else{
printf("%d",num2);
}
return 0;
}
//gpa calculaton
#include<stdio.h>
int main(){
int result;
scanf("%d",&result);
if(result>=80){
printf("A+");
}
else if(result>=75){
printf("A");
}
else if(result>=70){
printf("A-");
}
else if(result>=65){
printf("B+");
}
else{
printf("fail");
}
return 0;
}

//regular hours works

#include<stdio.h>
int main(){
int hours,payment;
scanf("%d",&hours);
if(hours<=40){
payment = hours * 10;
printf("%d",payment);
}
else{
payment = (40*10) + (hours-40) * 15;
printf("%d",payment);
}
return 0;
}

//Second largest number


#include<stdio.h>
int main(){
int a,b,c;
scanf("%d %d %d", &a, &b, &c);
if(a>b && a>c){
if(b>c){
printf("Second largest number:%d", b);
}
else{
printf("Second largest number:%d", c);
}
}
else if(b>c && b>a){
if(a>c){
printf("Second largest number:%d", a);
}
else{
printf("Second largest number:%d", c);
}
}
else{
if(a>b){
printf("Second largest number:%d", a);
}
else{
printf("Second largest number:%d", b);
}
}
return 0;
}

//tri angle result


#include<stdio.h>
#include<math.h>
int main(){
int x1,x2,y1,y2,dx,dy,sq_dx,sq_dy;
scanf("%d %d %d %d", &x1, &x2, &y1, &y2);
double sprit;
dx = x2-x1;
dy = y2-y1;
sq_dx = pow(dx,2);
sq_dy = pow(dy,2);
sprit = sqrt(sq_dx + sq_dy);
printf("Result: %lf",sprit);
return 0;
}

// discount calculation
#include<stdio.h>
int main(){
int discount,price,subs1,subs2;
scanf("%d", price);
if(price<=5000){
discount = price * 0.05;
printf("Discount: %d",discount);
}
else if(price<=15000){
subs1 = price - 5000;
discount = 5000 * 0.05 + subs1 * 0.1;
printf("Discount: %d",discount);
}
else{
subs1 = price - 5000;
if(subs1 <= 15000){
discount = 5000 * 0.05 + subs1 * 0.1;
printf("Discount: %d",discount);
}
else{
subs2 = subs1 - 15000;
discount = 5000 * 0.05 + 15000 * 0.1 + subs2 * 0.2;
printf("Discount: %d",discount);
}
}
return 0;
}

You might also like