1. Addition of two Numbers using C language
Algorithm:
STEP 1: Start
STEP 2: Input two numbers.
STEP 3: Add the two numbers and assign the result into another variable.
STEP 4: Print the result value.
STEP 5: End
Flow Chart:
C Program code using static Input:
#include<stdio.h>
int main() {
int a=5;//first Number
int b=6;//Second Number
int result;
result = a+b;
printf("The result is %d",result);//print the result
return 0;
}
OUTPUT:
C Program code using Dynamic Input(scanf()):
#include<stdio.h>
int main() {
int a;//first Number
int b;//Second Number
int result;
printf("Enter the two numbers\n");
scanf("%d%d",&a,&b);
result = a+b;
printf("The result is %d",result);
return 0;
}
OUTPUT:
#include<stdio.h>
int main() {
float a;//first Number
float b;//Second Number
float result;
printf("Enter the two numbers\n");
scanf("%f%f",&a,&b);
result = a+b;
printf("The result is %f",result);
return 0;
}
OUTPUT
C Program - Average and Percentage of numbers.
#include<stdio.h>
int main(){
int Marks_Physics,Marks_Chemistry,Marks_Biology;
int Total_Marks;
float Average;
float percent_marks;
printf("Enter the marks for three subjects of full marks 50");
scanf("%d%d%d",&Marks_Physics,&Marks_Chemistry,&Marks_Biology);
Total_Marks = Marks_Physics+Marks_Chemistry+Marks_Biology;
printf("You got %d marks out of 150\n",Total_Marks);
Average = (float)Total_Marks/3;
percent_marks = (float)(Total_Marks*100)/150;
printf("You got average = %.3f marks\n",Average);
printf("Your Percentage of Marks is =%f",percent_marks);
return 0;
}
}
OUTPUT
0 Comments