Finding out the year is leap year or not,Converting temperature from Celsius to Fahrenheit and vise versa,Finding out addition , substraction , multiplication, division of two numbers by using switch case,Finding out the eligibility to vote.

 Problem : Finding out the year is leap year or not.

Finding out the year is leap year or not.


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, y was a varriable 

for the year which was given by the user. 


Code:

#include<stdio.h>

int main (){

 int y;

 printf("Enter the year:");

 scanf("%d",&y);

 if ( y%4 == 0 )

 printf("%d is a leap year",y);

 else printf ("%d is not a leap year",y);

}


Output:

Finding out the year is leap year or not.


Discussion: We successfully run the program by using codeblocks. Here, we took y=2012, which 

was a leap year and was seen on the display automatically and the result was absolutely correct. 

And if the user gave a year which was not leap year, then we could see on the screen that the year 

was not leap year. So, we could see that by using C programming we can calculate anything 

without any possibility of any kind of error.


Problem: Converting temperature from Celsius to Fahrenheit and vise versa.

Converting temperature from Celsius to Fahrenheit and vise versa.


Solution: 

Introduction: In this problem, we converted temperature from Celsius to Fahrenheit and vise 

versa. 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 (){

 float c,f ;

 int x;

 printf ( "press one for Fahrenheit to Celsius conversion \n 

Press two for the Celsius to fahrenheit :");

 scanf (" %d", & x);

 if (x==1) {

 printf("\n enter the temperature in Fahrenheit ");

 scanf("%f",&f);

 c=((f-32)*5)/9;

 printf("\n the temperature in celsius is %.2f",c);}

 else if

 (x==2) {

 printf("\n the temperature in Celsius");

 scanf("%f",&c);

 f=((c/5)*9)+32;

 printf("\n thetemperature in Fahrenheit is %.2f",f); }

}

 

Output:

Converting temperature from Celsius to Fahrenheit and vise versa.


Discussion: We successfully run the program by using codeblocks. Here, we gave option to the 

user to choose what conversion he/she wanted and the value of the temperature. Then the converted 

value of the tempature was seen on the display automatically and the result was absolutely correct. 

So, we could see that by using C programming we can calculate anything without any possibility 

of any kind of error.


Problem: Finding out addition , substraction , multiplication, division of two numbers by using switch case.


Finding out addition , substraction , multiplication, division of two numbers by using switch case.


Solution: 

Introduction: In this problem, we found out addition, substraction, multiplication, division of two 

numbers by using switch case two numbers 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, a and b are two 

numbers which were given by user and o is for the option which is given by user.


Code: 

#include<stdio.h>

int main(){

int a,b,o;

printf("Enter your option 1 for the add\n 2 for the subtract\n 3 

for the multification\n 4 for the division\n");

 scanf("%d",&o);

 printf("Enter the two numbers");

 scanf("%d %d", &a,&b);

 switch (o) {

case 1:

 printf("addition=%d",a+b);

 break;

case 2:

 printf("subtraction=%d",a-b);

 break;

case 3:

 printf("multiplication=%d",a*b);

 break;

case 4:

 printf("division=%d",a/b);

 break;

default:

 printf("your option is wrong");

 break; }

}


Output:

Finding out addition , substraction , multiplication, division of two numbers by using switch case.



Discussion: We successfully run the program by using codeblocks. Here, we pressed 3 for the 

option to multiply two numbers. we took a=8 and b=6 and the bigger number was 78 which was

seen on the display automatically and the result was absolutely correct. And if the user gave other 

options, it could show the other operations 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 eligibility to vote.

Solution: 

Finding out the eligibility to vote.



Introduction: In this problem, we found out one is eligible or not to vote 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 one variable. 

Here, i is for the option which is given by user.


Code: 

#include<stdio.h>

int main()

{

 int i;

 printf("Enter your option 1 for more or equal for 18 \n 2 for 

less then 18 age:");

 scanf("%d",&i);

 switch(i){

 case 1:

 printf("eligile");

 break;

 case 2:

 printf("not eligible");

 break;

default : printf("your option is wrong");

 }

}

Output:

Finding out the eligibility to vote.



Discussion: We successfully run the program by using codeblocks. Here, we took option 2

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.







0 Comments

Post a Comment

Post a Comment (0)

Previous Post Next Post