Problem : Finding out the grade of a subject by putting it’s mark.
Solution:
Introduction: In this problem, we found out the grade of subject by giving mark of it as the input
through C programming by using codeblocks. Each instruction in a C program is written as a
separate statement. C has no specific rules for the position at which a statement is to be written in
a given line. That’s why it is often called a free-form language. #include is a preprocessor directive.
Then we used int main ( ) with a {}. We used it to start our programming We used printf ( ) to
show data, information etc. on the screen. We used scanf for taking input from the user. We used
int here to take two variables. Here, m and r are two numbers which were given by user.
Code:
#include<stdio.h>
int main( ) {
int m;
printf("Enter your mark:");
scanf("%d",&m);
if (m>80) {
printf("A+"); }
else if (80>m && 75<=m) {
printf("A") ; }
else if (75>m && 70<=m) {
printf("A-") ; }
else if (70>m && 65<=m) {
printf("B+"); }
else if (65>m && 60<=m) {
printf("B"); }
else if (60>m && 55<=m) {
printf("B-"); }
else if (55>m && 50<=m) {
printf("C+"); }
else if (50>m && 45<=m) {
printf("C"); }
else if (45>m && 40<=m) {
printf("D"); }
else if (m<40) {
printf("Fail :(");}
return 0; }
Output:
Discussion: We successfully run the program by using codeblocks. Here, we took m=59 and the
output was B- which was seen on the display automatically and the result was absolutely correct.
So, we could see that by using C programming we can find any grade by putting the mark without
any possibility of any kind of error.
Problem: Finding out the biggest number among the three numbers.
Solution:
Introduction: In this problem, we found out the biggest number among the three numbers . Three
numbers were given by the user as the input through C programming by using codeblocks. Each
instruction in a C program is written as a separate statement. C has no specific rules for the position
at which a statement is to be written in a given line. That’s why it is often called a free-form
language. #include is a preprocessor directive. Then we used int main ( ) with a {}. We used it to
start our programming We used printf ( ) to show data, information etc. on the screen. We used
scanf for taking input from the user. We used int here to take three varriables. Here, p,q and r were
three numbers which were given by user.
Code:
#include<stdio.h>
int main()
{
int p,q,r;
printf("enter the 1st number:");
scanf("%d",&p);
printf("enter the 2nd number:");
scanf("%d",&q);
printf("enter the 3rd number:");
scanf("%d",&r);
if (p>q && p>r) { printf ("THe bigger number is:%d",p) ;
}
else if (q>p && q>r) { printf ("THe bigger number is:%d",q)
;
}
else if (r>p && r>q) { printf ("THe bigger number is:%d",r)
;
}
else { printf ("Three numbers are equal") ;
}
}
Output:
Discussion: We successfully run the program by using codeblocks. Here, we took p=34and q=65
and r=92 and the biggest number was 92 which was seen on the display automatically and the
result was absolutely correct. And if the user gave three equal numbers, it could show the equality
too. So, we could see that by using C programming we can calculate anything without any
possibility of any kind of error.
Problem : Finding out the smallest number among the three numbers.
Solution:
Introduction: In this problem, we found out the smallest number among the three numbers . Three
numbers were given by the user as the input through C programming by using codeblocks. Each
instruction in a C program is written as a separate statement. C has no specific rules for the position
at which a statement is to be written in a given line. That’s why it is often called a free-form
language. #include is a preprocessor directive. Then we used int main ( ) with a {}. We used it to
start our programming We used printf ( ) to show data, information etc. on the screen. We used
scanf for taking input from the user. We used int here to take three variables. Here, p,q and r were
three numbers which were given by user.
Code:
#include<stdio.h>
int main()
{
int p,q,r;
printf("enter the 1st number:");
scanf("%d",&p);
printf("enter the 2nd number:");
scanf("%d",&q);
printf("enter the 3rd number:");
scanf("%d",&r);
if (p<q && p<r) { printf ("THe bigger number is:%d",p) ;
}
else if (q<p && q<r) { printf ("THe bigger number is:%d",q)
;
}
else if (r<p && r<q) { printf ("THe bigger number is:%d",r)
;
}
else { printf ("Three numbers are equal") ;
}
}
Output:
Discussion: We successfully run the program by using codeblocks. Here, we took p=34 and q=65
and r=92 and the smallest number was 34 which was seen on the display automatically and the
result was absolutely correct. And if the user gave three equal numbers, it could show the equality
too. So, we could see that by using C programming we can calculate anything without any
possibility of any kind of error.
Problem: Finding out a number is even or odd.
Solution:
Introduction: In this problem, we found out the smallest number among the three numbers . Three
numbers were given by the user as the input through C programming by using codeblocks. Each
instruction in a C program is written as a separate statement. C has no specific rules for the position
at which a statement is to be written in a given line. That’s why it is often called a free-form
language. #include is a preprocessor directive. Then we used int main ( ) with a {}. We used it to
start our programming We used printf ( ) to show data, information etc. on the screen. We used
scanf for taking input from the user. We used int here to take a number. Here, n was a varriable
for the number which was given by the user.
Code:
#include<stdio.h>
int main (){
int n ;
printf("Enter the number");
scanf("%d",&n);
if ( n%2 == 0 ){
printf("%d is an even number",n);}
else { printf ("%d is an odd number",n);}
}
Output:
Discussion: We successfully run the program by using codeblocks. Here, we took n=6, which
was an even number and was seen on the display automatically and the result was absolutely
correct. And if the user gave three equal numbers, it could show the equality too. So, we could see
that by using C programming we can calculate anything without any possibility of any kind of
error.
.
Post a Comment