# data[].attributes.body
#include<stdio.h>

int main () {

int number;

printf("Enter an integer:");

scanf("%d",&number);

printf("You entered:%d\n",number);

return 0;

}

# data[].attributes.body
#include <stdio.h>

int main()
{
char ch;

printf("Enter any character: ");
scanf("%c", &ch);

if(ch >= 'A' && ch <= 'Z')
{
printf("'%c' is uppercase alphabet.", ch);
}
else if(ch >= 'a' && ch <= 'z')
{
printf("'%c' is lowercase alphabet.", ch);
}
else
{
printf("'%c' is not an alphabet.", ch);
}

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main()
{
int year;

printf("Enter year : ");
scanf("%d", &year);

if(((year % 4 == 0) && (year % 100 !=0)) && (year % 400==0))
{
printf("leap year");
}
else
{
printf("Not leap year");
}

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main()
{
    char op;
    float num1, num2, result;


    printf("Enter [number 1] [+ - * /] [number 2]\n");


    scanf("%f %c %f", &num1, &op, &num2);

    switch(op)
    {
        case '+':
            result = num1 + num2;
            break;

        case '-':
            result = num1 - num2;
            break;

        case '*':
            result = num1 * num2;
            break;

        case '/':
            result = num1 / num2;
            break;

        default:
            printf("Invalid operator");
    }

    printf("%f", result);

    return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
int i,x;
int blueCount = 0, whiteCount = 0;
printf("Total People:");
scanf("%d",&x);

for (i = 1; i<=x; i++) {
if (i%2!= 0){
whiteCount++;
} else if (i%2== 0) {
blueCount++;
}
}

printf("Number of friends wearing blue t-shirts: %d\n", blueCount);
printf("Number of friends wearing white t-shirts: %d\n", whiteCount);
if (i%2!= 0){

printf("Last people wairing: White");}
else if (i%2== 0) {
printf("Last people wairing: Blue");
}

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {

int a;

printf("Press 1 for for Bio\n Press 2 for Goal\n Press 3 for Family Info:");

scanf("%d",&a);

switch(a){

case 1:

printf("This is the biodata of Sakib");

break;

case 2:

printf("This is the Goal of Sakib");

break;

case 3:

printf("This is the Family info of Sakib");

break;

default:

}

return 0;

}

# data[].attributes.body
#include <stdio.h>

int main() {

int a, b,m;

printf("Input Yout Money=");

scanf("%d",&m);

printf("Press 1 for Cocacola\n Press 2 for Funta\n");

scanf("%d",&a);

switch(a){

case 1:

printf("You select Cocacola\n Your total Costing 30 tk\n");

if(m>=30){

b=m-30;

printf("You got Cocacola\n Your return Money:%d",b);

}else{ printf("You have to pay more then 30 tk");}

break;

case 2:

printf("You select Fanta\n Your total Costing 25 tk\n");

if(m>=25){

b=m-25;

printf("You got Cocacola\n Your return Money:%d",b);

}else{ printf("You have to pay more then 25 tk");}

break;

default:

}

return 0;

}

# data[].attributes.body
#include <stdio.h>

#include <string.h>

int main() {

char S[50];

shimanta:

printf("List of the company name\n 1. Grameen\n2.Banglalink\n\n Enter the name of the company\n\n");

scanf("%s",&S);

if((strcmp(S, "Grameen") == 0)){

printf("Grameenphone=017\n");

}else if((strcmp(S, "Banglalink") == 0)){

printf("Banglalink=019\n");

}else{

printf("You enter wrong Name\n Try again");

goto shimanta;

}

return 0;

}

# data[].attributes.body
problem 12 :
#include <stdio.h>

int main() {
float num1, num2, result;
char op;

printf("Enter two numbers and an operator (+, -, *, /) separated by spaces: ");
scanf("%f %c %f", &num1, &op, &num2);

switch(op) {
case '+':
result = num1+num2;
printf("Result = %f",result);
break;
case '-':
result = num1-num2;
printf("Result = %f",result);
break;
case '*':
result = num1*num2;
printf("Result = %f",result);
break;
case '/':
if (num2 == 0) {
printf("Math Error");
return 0;
} else {
result = num1/num2;
printf("Result = %f",result);
}
break;
default:
printf("Invalid operator");
return 0;
}

return 0;
}

# data[].attributes.body
Problem-11
int main()

{

int num;

printf("Enter any number: ");

scanf("%d", &num);

switch (num > 0)

{

case 1:

printf("%d is positive.", num);

break;

case 0:

switch (num < 0)

{

case 1:

printf("%d is negative.", num);

break;

case 0:

printf("%d is zero.", num);

break;

}

break;

}

return 0;

}

# data[].attributes.body
Problem-10:
#include <stdio.h>

int main()

{

int month;

printf("Enter month number(1-12): ");
scanf("%d",&month);

switch(month)

{

case 1:

printf("Total 31 days");

break;

case 2:

printf("28/29 days");

break;

case 3:

printf("31 days");

break;

case 4:

printf("30 days");

break;

case 5:

printf("31 days");

break;

case 6:

printf("30 days");

break;

case 7:

printf("31 days");

break;

case 8:

printf("31 days");

break;

case 9:

printf("30 days");

break;

case 10:

printf("31 days");

break;

case 11:

printf("30 days");

break;

case 12:

printf("31 days");

break;

default:
printf("Unknown! Please enter month      number between 1-12");

}

return 0;

}

# data[].attributes.body
problem 8:
#include <stdio.h>

int main()
{
int day;
printf("Enter number of day:");
scanf("%d",&day);

if(day==1){
printf("Sunday");
}
else if(day==2){
printf("Monday");
}
else if(day==3){
printf("Tuesday");
}
else if(day==4){
printf("Wednesday");
}
else if(day==5){
printf("Thursday");
}

else if(day==6){
printf("Friday");
}
else if(day==7){
printf("Saturday");
}
return 0;
}

# data[].attributes.body
problem 7:
#include <stdio.h>

int main()
{
int num;
printf("Enter number :");
scanf("%d",&num);

if(num%2==0){
printf("Even Number");}

else {
printf("Odd");
}
return 0;
}

# data[].attributes.body
problem 6:
#include <stdio.h>

int main()
{
int num;
printf("Enter number :");
scanf("%d",&num);

if(num>0){
printf("Positive");}

else if (num<0){
printf("Negative");
}
else if (num==0){
printf("This is 0");
}
else{
printf("You are pro");
}
return 0;
}

# data[].attributes.body
problem 5:
#include <stdio.h>

int main()
{
float num1,num2,num3;
printf("Enter number 1:");
scanf("%f",&num1);

printf("Enter number 2:");
scanf("%f",&num2);

printf("Enter number 3:");
scanf("%f",&num3);

if(num1>num2){
if(num1>num3){
printf("Num 1 is big=%f",num1);}}

else if(num2>num3){
if (num2>num1){
printf("Num 2 is big=%f",num2);}}
else if(num3>num2){
if (num3>num1){
printf("Num 3 is big=%f",num3);}}

else{
printf("Num Equal");
}
return 0;
}

# data[].attributes.body
problem 4:
int main()
{
float num1,num2;
printf("Enter number 1:");
scanf("%f",&num1);

printf("Enter number 2:");
scanf("%f",&num2);

if(num1>num2){
printf("Num 1 is big=%f",num1);}

else if(num1<num2){
printf("Num 2 is big=%f",num2);}
else{
printf("Num is Equal");
}
return 0;
}

# data[].attributes.body
problem 3:
#include <stdio.h>

int main() {
int base, exponent, result;

printf("Enter the base: ");
scanf("%d", &base);

printf("Enter the exponent: ");
scanf("%d", &exponent);

result = pow(base, exponent);

printf("result=%d",result);

return 0;
}

# data[].attributes.body
problem 2:
int main()
{
float C;
float F;

printf("Enter Celcius=");
scanf("%f",&C);

F = (C*9/5)+32;
printf("F=%f",F);
return 0;
}

# data[].attributes.body
problem 1:
#include <stdio.h>

int main() {
float base,hight,area;
printf("enter the value of base\n");
scanf("%f",&base);
printf("enter the value of hight\n");
scanf("%f",&hight);
area=(base*hight)*1/2;
printf("area=%f",area);

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {

int a[3][3]={{3,2,1},{1,2,3},{4,5,6}};
int b[3][3]={{6,9,11},{12,13,14},{15,0,2}};

int c[3][3];
for(int i=0;i<3;i++){
for(int j=0; j<3; j++){
c[i][j]=a[i][j]+b[i][j];
printf("%d \n",c[i][j]);
}
}

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
char str[100];
int i;

printf("Enter an uppercase string: ");
fgets(str, sizeof(str), stdin);

for (i = 0; str[i] != '\0'; i++) {
if (str[i] >= 'A' && str[i] <= 'Z') {
str[i] = str[i] + 32;
}
}

printf("Lowercase string: %s\n", str);

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
int blueShirt = 0;
int whiteShirt = 0;

for (int i = 1; i <= 5; i++) {
if (i % 2 == 0) {
blueShirt++;
} else {
whiteShirt++;
}
}

printf("Number of people wearing blue t-shirts: %d\n", blueShirt);
printf("Number of people wearing white t-shirts: %d\n", whiteShirt);

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
int size, i, j, count = 0;

printf("Enter size: ");
scanf("%d", &size);

int arr[size];

printf("Enter array:\n");
for (i = 0; i < size; i++) {
printf("Element %d: ", i + 1);
scanf("%d", &arr[i]);
}

for (i = 0; i < size; i++) {
for (j = i + 1; j < size; j++) {
if (arr[i] == arr[j]) {
count++;
break;
}
}
}

printf("Total duplicate: %d\n", count);

return 0;
}

# data[].attributes.body
#include <stdio.h>

#include <stdio.h>

int main() {
int size, position, i;

printf("Enter size of array: ");
scanf("%d", &size);

int xx[size];

printf("Enter elements of array:\n");
for (i = 0; i < size; i++) {
printf("Element %d: ", i + 1);
scanf("%d", &xx[i]);
}

printf("Enter position of the element to delete (1-%d): ", size);
scanf("%d", &position);

if (position < 1 || position > size) {
printf("Invalid position! Please enter a position between 1 and %d.\n", size);
} else {

for (i = position - 1; i < size - 1; i++) {
xx[i] = xx[i + 1];
}

size--;
printf("Array after deleting the element:\n");
for (i = 0; i < size; i++) {
printf("%d ", xx[i]);
}
printf("\n");
}

return 0;
}

# data[].attributes.body
int main() {
int size, i, total = 0;

printf("Enter the size of the array: ");
scanf("%d", &size);

int xr[size];

printf("Enter Element:\n");
for (i = 0; i < size; i++) {
printf("Element %d: ", i + 1);
scanf("%d", &xr[i]);
}

for (i = 0; i < size; i++) {
if (xr[i] < 0) {
total++;
}
}

printf("Total negative Number: %d\n", total);

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {

// Write C code here

int i,j;

for(i=1;i<=5;i++){

for(j=1;j<=i;j++){

printf("*");

}

printf("\n");

}

for(i=1;i<=5;i++){

for(j=5;j>=i;j--){

printf("*");

}

printf("\n");

}

return 0;

}

# data[].attributes.body
#include <stdio.h>

int main() {
// Write C code here
int a[7]={1001,100,10,20,32,-3,0};
int evencount=0,evensum=0,oddcount=0,oddsum=0,i;
for(i=0;i<7;i++){
if(a[i]%2==0){
printf("\n%d is a Even number",a[i]);
evencount=evencount+1;
evensum=evensum+a[i];
}
else if(a[i]%2!=0){
printf("\n%d is a Odd number",a[i]);
oddcount=oddcount+1;
oddsum=oddsum+a[i];
}
printf("\n");
}
printf("\nTotal Even number = %d\n",evencount);
printf("\nSumation of total Even number = %d\n",evensum);
printf("\nTotal Odd number = %d\n",oddcount);
printf("\nSumation of total Odd number = %d\n",oddsum);

for(i=0;i<7;i++){
if(a[i]==0){
printf("\n%d is a neutral number",a[i]);
}
else if(a[i]<0){
printf("\n%d is a Positive number",a[i]);
}
else if(a[i]>0){
printf("\n%d is a Negative number",a[i]);
}
printf("\n");
}

return 0;
}

# data[].attributes.body
https://beginnersbook.com/2014/01/c-strings-string-functions/

# data[].attributes.attachment_link.readable_text
String is an array of characters. In this guide, we learn how to declare strings, how to work with strings in C programming and how to use the pre-defined string handling functions.

We will see how to compare two strings, concatenate strings, copy one string to another & perform various string manipulation operations. We can perform such operations using the pre-defined functions of "string.h" header file. In order to use these string functions you must include string.h file in your C program.

String Declaration

Method 1:

char address[]={'T', 'E', 'X', 'A', 'S', '\0'};

Method 2: The above string can also be defined as -

char address[]="TEXAS";

In the above declaration NULL character (\0) will automatically be inserted at the end of the string.

What is NULL Char "\0"?
'\0' represents the end of the string. It is also referred as String terminator & Null Character.

String I/O in C programming

Read & write Strings in C using Printf() and Scanf() functions

#include <stdio.h>
#include <string.h>
int main()
{
    /* String Declaration*/
    char nickname[20];

    printf("Enter your Nick name:");

    /* I am reading the input string and storing it in nickname
     * Array name alone works as a base address of array so
     * we can use nickname instead of &nickname here
     */
    scanf("%s", nickname);

    /*Displaying String*/
    printf("%s",nickname);

    return 0;
}

Output:

Enter your Nick name:Negan
Negan

Note: %s format specifier is used for strings input/output

Read & Write Strings in C using gets() and puts() functions

#include <stdio.h>
#include <string.h>
int main()
{
    /* String Declaration*/
    char nickname[20];

    /* Console display using puts */
    puts("Enter your Nick name:");

    /*Input using gets*/
    gets(nickname);

    puts(nickname);

    return 0;
}

C - String functions

C String function - strlen

Syntax:

size_t strlen(const char *str)

size_t represents unsigned short
It returns the length of the string without including end character (terminating char '\0').
Example of strlen:
#include <stdio.h>
#include <string.h>
int main()
{
     char str1[20] = "BeginnersBook";
     printf("Length of string str1: %d", strlen(str1));
     return 0;
}

Output:

Length of string str1: 13

strlen vs sizeof
strlen returns you the length of the string stored in array, however sizeof returns the total allocated size assigned to the array. So if I consider the above example again then the following statements would return the below values.

strlen(str1) returned value 13.
sizeof(str1) would return value 20 as the array size is 20 (see the first statement in main function).

C String function - strnlen

Syntax:

size_t strnlen(const char *str, size_t maxlen)

size_t represents unsigned short
It returns length of the string if it is less than the value specified for maxlen (maximum length) otherwise it returns maxlen value.
Example of strnlen:
#include <stdio.h>
#include <string.h>
int main()
{
     char str1[20] = "BeginnersBook";
     printf("Length of string str1 when maxlen is 30: %d", strnlen(str1, 30));
     printf("Length of string str1 when maxlen is 10: %d", strnlen(str1, 10));
     return 0;
}

Output:
Length of string str1 when maxlen is 30: 13
Length of string str1 when maxlen is 10: 10

Have you noticed the output of second printf statement, even though the string length was 13 it returned only 10 because the maxlen was 10.

C String function - strcmp

int strcmp(const char *str1, const char *str2)

It compares the two strings and returns an integer value. If both the strings are same (equal) then this function would return 0 otherwise it may return a negative or positive value based on the comparison.

If string1 < string2 OR string1 is a substring of string2 then it would result in a negative value. If string1 > string2 then it would return positive value.
If string1 == string2 then you would get 0(zero) when you use this function for compare strings.
Example of strcmp:
#include <stdio.h>
#include <string.h>
int main()
{
     char s1[20] = "BeginnersBook";
     char s2[20] = "BeginnersBook.COM";
     if (strcmp(s1, s2) ==0)
     {
        printf("string 1 and string 2 are equal");
     }else
      {
         printf("string 1 and 2 are different");
      }
     return 0;
}
Output:
string 1 and 2 are different

C String function - strncmp

int strncmp(const char *str1, const char *str2, size_t n)

size_t is for unassigned short
It compares both the string till n characters or in other words it compares first n characters of both the strings.
Example of strncmp:
#include <stdio.h>
#include <string.h>
int main()
{
     char s1[20] = "BeginnersBook";
     char s2[20] = "BeginnersBook.COM";
     /* below it is comparing first 8 characters of s1 and s2*/
     if (strncmp(s1, s2, 8) ==0)
     {
         printf("string 1 and string 2 are equal");
     }else
     {
         printf("string 1 and 2 are different");
     }
     return 0;
}
Output:
string1 and string 2 are equal

C String function - strcat

char *strcat(char *str1, char *str2)

It concatenates two strings and returns the concatenated string.
Example of strcat:
#include <stdio.h>
#include <string.h>
int main()
{
     char s1[10] = "Hello";
     char s2[10] = "World";
     strcat(s1,s2);
     printf("Output string after concatenation: %s", s1);
     return 0;
}
Output:
Output string after concatenation: HelloWorld

C String function - strncat

char *strncat(char *str1, char *str2, int n)

It concatenates n characters of str2 to string str1. A terminator char ('\0') will always be appended at the end of the concatenated string.
Example of strncat:
#include <stdio.h>
#include <string.h>
int main()
{
     char s1[10] = "Hello";
     char s2[10] = "World";
     strncat(s1,s2, 3);
     printf("Concatenation using strncat: %s", s1);
     return 0;
}
Output:
Concatenation using strncat: HelloWor

C String function - strcpy

char *strcpy( char *str1, char *str2)

It copies the string str2 into string str1, including the end character (terminator char '\0').
Example of strcpy:
#include <stdio.h>
#include <string.h>
int main()
{
     char s1[30] = "string 1";
     char s2[30] = "string 2 : I'm gonna copied into s1";
     /* this function has copied s2 into s1*/
     strcpy(s1,s2);
     printf("String s1 is: %s", s1);
     return 0;
}
Output:
String s1 is: string 2: I'm gonna copied into s1

C String function - strncpy

char *strncpy( char *str1, char *str2, size_t n)
size_t is unassigned short and n is a number.
Case1: If length of str2 > n then it just copies first n characters of str2 into str1.
Case2: If length of str2 < n then it copies all the characters of str2 into str1 and appends several terminator chars('\0') to accumulate the length of str1 to make it n.
Example of strncpy:
#include <stdio.h>
#include <string.h>
int main()
{
     char first[30] = "string 1";
     char second[30] = "string 2: I'm using strncpy now";
     /* this function has copied first 10 chars of s2 into s1*/
     strncpy(s1,s2, 12);
     printf("String s1 is: %s", s1);
     return 0;
}
Output:
String s1 is: string 2: I'm

C String function - strchr

char *strchr(char *str, int ch)

It searches string str for character ch (you may be wondering that in above definition I have given data type of ch as int, don't worry I didn't make any mistake it should be int only. The thing is when we give any character while using strchr then it internally gets converted into integer for better searching.
Example of strchr:
#include <stdio.h>
#include <string.h>
int main()
{
     char mystr[30] = "I'm an example of function strchr";
     printf ("%s", strchr(mystr, 'f'));
     return 0;
}
Output:
f function strchr

C String function - Strrchr

char *strrchr(char *str, int ch)

It is similar to the function strchr, the only difference is that it searches the string in reverse order, now you would have understood why we have extra r in strrchr, yes you guessed it correct, it is for reverse only.

Now let's take the same above example:

#include <stdio.h>
#include <string.h>
int main()
{
     char mystr[30] = "I'm an example of function strchr";
     printf ("%s", strrchr(mystr, 'f'));
     return 0;
}
Output:
function strchr

Why output is different than strchr? It is because it started searching from the end of the string and found the first 'f' in function instead of 'of'.

C String function - strstr

char *strstr(char *str, char *srch_term)

It is similar to strchr, except that it searches for string srch_term instead of a single char.
Example of strstr:
#include <stdio.h>
#include <string.h>
int main()
{
     char inputstr[70] = "String Function in C at BeginnersBook.COM";
     printf ("Output string is: %s", strstr(inputstr, 'Begi'));
     return 0;
}
Output:
Output string is: BeginnersBook.COM

You can also use this function in place of strchr as you are allowed to give single char also in place of search_term string.

# data[].attributes.attachment_link.title
C - Strings and String functions with examples

# data[].attributes.attachment_link.description
String is an array of characters. In this guide, we learn how to declare strings, how to work with strings in C programming and how to use the pre-defined string handling functions. We will see how to compare two strings, concatenate strings, copy one string to another & perform various string manipulation operations.

# data[].attributes.body
Qustion-11  (Write a C program to input a number and check positive negative or zero using switch case)

int main()

{

int num;

printf("Enter any number: ");

scanf("%d", &num);

switch (num > 0)

{

case 1:

printf("%d is positive.", num);

break;

case 0:

switch (num < 0)

{

case 1:

printf("%d is negative.", num);

break;

case 0:

printf("%d is zero.", num);

break;

}

break;

}

return 0;

}

# data[].attributes.body
Qustion-10  (Write a C program to input month number and print total number of days in month using switch...case)

#include <stdio.h>

int main()

{

int month;

printf("Enter month number(1-12): ");
scanf("%d",&month);

switch(month)

{

case 1:

printf("Total 31 days");

break;

case 2:

printf("28/29 days");

break;

case 3:

printf("31 days");

break;

case 4:

printf("30 days");

break;

case 5:

printf("31 days");

break;

case 6:

printf("30 days");

break;

case 7:

printf("31 days");

break;

case 8:

printf("31 days");

break;

case 9:

printf("30 days");

break;

case 10:

printf("31 days");

break;

case 11:

printf("30 days");

break;

case 12:

printf("31 days");

break;

default:
printf("Unknown! Please enter month      number between 1-12");

}

return 0;

}

# data[].attributes.body
Qustion-08  (How to print day of week using if else in C programming)

#include <stdio.h>

int main()

{

int week;

printf("Enter week number (1-7):");

scanf("%d",&week);

if(week == 1)

{

printf("Monday");

}

else if(week == 2)

{

printf("Tuesday");

}

else if(week == 3)

{

printf("Wednesday");

}

else if(week == 4)

{

printf("Thursday");

}

else if(week == 5)

{

printf("Friday");

}

else if(week == 6)

{

printf("Saturday");

}

else if(week == 7)

{

printf("Sunday");

}

else

{

printf("Invalid! Please enter week number between 1-7.");

}

return 0;

}

# data[].attributes.body
Qustion-07  (Write a C program to check whether a number is even or odd using if else)

#include <stdio.h>

int main()

{

int num;

printf("Enter the number:");

scanf("%d",&num);

if(num % 2 == 0)

printf("%d is even.",num);

else

printf("%d is odd.",num);

return 0;

}

# data[].attributes.body
Qustion-06  (Write a C program to check positive, negative or zero using simple if or if else)

#include <stdio.h>

int main()

{

int num;

printf("Enter the number:");
scanf("%d",&num);

if(num>0)

{

printf("The Number is Positive");

}

else if(num<0)

{

printf("The Number is Negative");

}

else

{

printf("The Number is Zero");

}

return 0;

}

# data[].attributes.body
Qustion-05  (How to find maximum or minimum between three numbers using if else in C programming)

#include <stdio.h>
int main()

{

int num1,num2,num3,max;

printf("Enter three numbers:");

scanf("%d%d%d",&num1, &num2,&num3);

if((num1>num2) && (num1>num3))

{

max=num1;

}

else if((num2>num1) && (num2>num3))

{

max=num2;

}

else if((num3>num1) && (num3>num2))

{

max = num3;

}

printf("Maximum number among all three numbers = %d",max);

return 0;

}

# data[].attributes.body
Qustion-04  (How to find maximum or minimum between two numbers using if else in C programming.)

#include <stdio.h>

int main()

{

int num1, num2;

printf("Enter your 1st number: ");

scanf("%d", &num1);

printf("Enter your 2nd number: ");

scanf("%d", &num2);

if(num1 > num2)

{

printf("%d is maximum", num1);

}

else

{

printf("%d is maximum", num2);

}

return 0;

}

# data[].attributes.body
Qustion-03  (How to find power using pow function of a number in C programming)

#include <math.h>

#include <stdio.h>
int main()

{
float base, exp, result;

printf("Enter a base number: ");

scanf("%f",&base);

printf("Enter an exponent:");

scanf("%f",&exp);

result = pow(base, exp);

printf("%f",result);

return 0;

}

# data[].attributes.body
Qustion-02  (Convert temperature from Celsius to Fahrenheit)

#include <stdio.h>

int main()

{
float C,F;

printf("Please provide your centigrade temperature:");

scanf("%f",&C);

F=(C*1.8)+32;

printf("The Fahrenheit temperature is %f",F);

return 0;

}

# data[].attributes.body
Qustion-01  (How to find area of a triangle in C programming)

#include <stdio.h>

int main()

{

float base, height, area;

printf("Enter the base of the triangle:");

scanf("%f", &base);

printf("Enter the height of the triangle:");

scanf("%f", &height);

area = 0.5 * base * height;

printf("The area of the triangle is %f",area);

return 0;

}

# data[].attributes.body
problem 11:
#include <stdio.h>

int main() {
int num;

// Input number
printf("Input number: ");
scanf("%d", &num);

// Check whether number is positive, negative, or zero using switch case
switch(num > 0) {
case 1:
printf("%d is positive\n", num);
break;
case 0:
switch(num < 0) {
case 1:
printf("%d is negative\n", num);
break;
case 0:
printf("%d is zero\n", num);
break;
}
break;
}

return 0;
}

# data[].attributes.body
problem 10:
#include <stdio.h>

main() {
printf("Press Number of the month from 1 to 12 = ");
int month, days;
scanf("%d",&month);

switch(month){
case 1:
days = 31;
break;
case 2:
days = 28;
break;
case 3:
days = 30;
break;
case 4:
days = 31;
break;
case 5:
days = 30;
break;
case 6:
days = 31;
break;
case 7:
days = 30;
break;
case 8:
days = 31;
break;
case 9:
days = 30;
break;
case 10:
days = 31;
break;
case 11:
days = 30;
break;
case 12:
days = 31;
break;

default:
printf("Enter number between 1 to 12");
break;

}
printf("Total number of days = %d\n", days);

return 0;
}

# data[].attributes.body
problem 8:
#include <stdio.h>

int main()
{
int day;
printf("Enter number of day:");
scanf("%d",&day);

if(day==1){
printf("Sunday");
}
else if(day==2){
printf("Monday");
}
else if(day==3){
printf("Tuesday");
}
else if(day==4){
printf("Wednesday");
}
else if(day==5){
printf("Thursday");
}

else if(day==6){
printf("Friday");
}
else if(day==7){
printf("Saturday");

# data[].attributes.body
problem 7:
#include <stdio.h>

int main()
{
int num;
printf("Enter number :");
scanf("%d",&num);

if(num%2==0){
printf("Even Number");}

else {
printf("Odd");
}
return 0;
}

# data[].attributes.body
problem 6:
#include <stdio.h>

int main()
{
int num;
printf("Enter number :");
scanf("%d",&num);

if(num>0){
printf("Positive");}

else if (num<0){
printf("Negative");
}
else if (num==0){
printf("This is 0");
}
else{
printf("You are pro");
}
return 0;
}

# data[].attributes.body
problem 5:
#include <stdio.h>

int main()
{
float num1,num2,num3;
printf("Enter number 1:");
scanf("%f",&num1);

printf("Enter number 2:");
scanf("%f",&num2);

printf("Enter number 3:");
scanf("%f",&num3);

if(num1>num2){
if(num1>num3){
printf("Num 1 is big=%f",num1);}}

else if(num2>num3){
if (num2>num1){
printf("Num 2 is big=%f",num2);}}
else if(num3>num2){
if (num3>num1){
printf("Num 3 is big=%f",num3);}}

else{
printf("Num Equal");
}
return 0;
}

# data[].attributes.body
problem 4:
int main()
{
float num1,num2;
printf("Enter number 1:");
scanf("%f",&num1);

printf("Enter number 2:");
scanf("%f",&num2);

if(num1>num2){
printf("Num 1 is big=%f",num1);}

else if(num1<num2){
printf("Num 2 is big=%f",num2);}
else{
printf("Num is Equal");
}
return 0;
}

# data[].attributes.body
problem 3:
#include <stdio.h>

int main() {
int base, exponent, result;

printf("Enter the base: ");
scanf("%d", &base);

printf("Enter the exponent: ");
scanf("%d", &exponent);

result = pow(base, exponent);

printf("result=%d",result);

return 0;
}

# data[].attributes.body
problem 2:
int main()
{
float C;
float F;

printf("Enter Celcius=");
scanf("%f",&C);

F = (C*9/5)+32;
printf("F=%f",F);
return 0;
}

# data[].attributes.body
problem 1:
#include <stdio.h>

int main() {
float base,hight,area;
printf("enter the value of base\n");
scanf("%f",&base);
printf("enter the value of hight\n");
scanf("%f",&hight);
area=(base*hight)*1/2;
printf("area=%f",area);

return 0;
}

# data[].attributes.body
problem 12 :
#include <stdio.h>

int main() {
float num1, num2, result;
char op;

printf("Enter two numbers and an operator (+, -, *, /) separated by spaces: ");
scanf("%f %c %f", &num1, &op, &num2);

switch(op) {
case '+':
result = num1+num2;
printf("Result = %f",result);
break;
case '-':
result = num1-num2;
printf("Result = %f",result);
break;
case '*':
result = num1*num2;
printf("Result = %f",result);
break;
case '/':
if (num2 == 0) {
printf("Math Error");
return 0;
} else {
result = num1/num2;
printf("Result = %f",result);
}
break;
default:
printf("Invalid operator");
return 0;
}

return 0;
}

# data[].attributes.body
Problem 11

#include <stdio.h>

int main() {
int num;

printf("Enter a number: ");
scanf("%d", &num);

switch (num > 0 ? 1 : (num < 0 ? -1 : 0)) {
case 1:
printf("%d is positive.\n", num);
break;
case -1:
printf("%d is negative.\n", num);
break;
case 0:
printf("%d is zero.\n", num);
break;
}

return 0;
}

# data[].attributes.body
Problem 10

#include <stdio.h>

int main() {
int month;

printf("Enter month number (1-12): ");
scanf("%d", &month);

switch (month) {
case 1:
printf("January has 31 days.\n");
break;
case 2:
printf("February has 28 days.\n");
break;
case 3:
printf("March has 31 days.\n");
break;
case 4:
printf("April has 30 days.\n");
break;
case 5:
printf("May has 31 days.\n");
break;
case 6:
printf("June has 30 days.\n");
break;
case 7:
printf("July has 31 days.\n");
break;
case 8:
printf("August has 31 days.\n");
break;
case 9:
printf("September has 30 days.\n");
break;
case 10:
printf("October has 31 days.\n");
break;
case 11:
printf("November has 30 days.\n");
break;
case 12:
printf("December has 31 days.\n");
break;
default:
printf("Invalid month number.\n");
break;
}

return 0;
}

# data[].attributes.body
Problem 08

#include <stdio.h>

int main() {
int week_number;

printf("Enter week number (1-7): ");
scanf("%d", &week_number);

if(week_number == 1) {
printf("Monday\n");
} else if(week_number == 2) {
printf("Tuesday\n");
} else if(week_number == 3) {
printf("Wednesday\n");
} else if(week_number == 4) {
printf("Thursday\n");
} else if(week_number == 5) {
printf("Friday\n");
} else if(week_number == 6) {
printf("Saturday\n");
} else if(week_number == 7) {
printf("Sunday\n");
} else {
printf("Invalid week number\n");
}

return 0;
}

# data[].attributes.body
Problem 07

#include <stdio.h>

int main() {
int number;

printf("Enter a number: ");
scanf("%d", &number);

if(number % 2 == 0) {
printf("%d is even\n", number);
} else {
printf("%d is odd\n", number);
}

return 0;
}

# data[].attributes.body
problem 06

#include <stdio.h>

int main() {
int num;

printf("Enter a number: ");
scanf("%d", &num);

if(num > 0) {
printf("%d is a positive number.", num);
}
else if(num < 0) {
printf("%d is a negative number.", num);
}
else {
printf("You entered zero.");
}

return 0;
}

# data[].attributes.body
problem 05

#include <stdio.h>

int main() {
float num1, num2, num3, max;

printf("Enter the first number: ");
scanf("%f", &num1);

printf("Enter the second number: ");
scanf("%f", &num2);

printf("Enter the third number: ");
scanf("%f", &num3);

if(num1 >= num2) {
if(num1 >= num3) {
max = num1;
}
else {
max = num3;
}
}
else {
if(num2 >= num3) {
max = num2;
}
else {
max = num3;
}
}

printf("%.2f is the maximum number.", max);

return 0;
}

# data[].attributes.body
Problem 04
#include <stdio.h>

int main() {
float num1, num2;

printf("Enter the first number: ");
scanf("%f", &num1);

printf("Enter the second number: ");
scanf("%f", &num2);

if(num1 > num2) {
printf("%.2f is the maximum number.", num1);
}
else {
printf("%.2f is the maximum number.", num2);
}

return 0;
}

# data[].attributes.body
Problem 03
#include <stdio.h>

int main() {
float base, exponent, result;

printf("Enter the base: ");
scanf("%f", &base);

printf("Enter the exponent: ");
scanf("%f", &exponent);

result = pow(base, exponent);

printf("%f raised to the power %f is: %f", base, exponent, result);

return 0;
}

# data[].attributes.body
Problem 02

#include <stdio.h>

int main() {
float celsius, fahrenheit;

printf("Enter the temperature in Celsius: ");
scanf("%f", &celsius);

fahrenheit = (celsius * 9/5) + 32;

printf("The temperature in Fahrenheit is: %f", fahrenheit);

return 0;
}

# data[].attributes.body
problem 1

#include <stdio.h>

int main() {
float base, height, area;

printf("Enter the base: ");
scanf("%f", &base);

printf("Enter the height: ");
scanf("%f", &height);

area = 0.5 * base * height;

printf("The area of the triangle is: %f", area);
return 0;
}

# data[].attributes.body
Md.Harun-or-Rasid
0242220005291021
** problem No 1
#include <stdio.h>

int main() {
float base , height,area;

printf("Enter base of the triangle:");
scanf("%f",&base);

printf("Enter height of the triangle:");
scanf("%f",&height);

area =0.5*base*height;
printf("Area of the triangle = %f sq. units ",area);

return 0;
}

** problem No 2
#include <stdio.h>

int main() {
float Celsius,Fahrenheit;

printf("Enter temperature in Celsius =");
scanf("%f",&Celsius);

Fahrenheit = Celsius*9/5) + 32 ;
printf("Temperature in Fahrenheit = %.2f F",Fahrenheit);

return 0;
}

** problem No 3

#include <stdio.h>

int main() {
double  base,exp,result;
printf("Enter a base number:");
scanf("%lf",&base);

printf("Enter an exponent:");
scanf("%lf",&exp);

result = pow(base, exp);
printf("%lf",result);

return 0;
}

** problem No 4
#include <stdio.h>

int main() {
float num1 ,num2;

printf("Input num1: ");
scanf("%f",&num1);

printf("Input num2: ");
scanf("%f",&num2);

if(num1 > num2){
printf("Maximum = %f",num1);
}
else{
printf("Maximum = %.2f",num2);
}

return 0;
}

** problem No 5
#include <stdio.h>

int main() {
float num1 ,num2 , num3;

printf("Input num1: ");
scanf("%f",&num1);

printf("Input num2: ");
scanf("%f",&num2);

printf("Input num3: ");
scanf("%f",&num3);

if(num1 > num2 && num1 > num3){
printf("Maximum = %.2f",num1);
}

else if(num2 > num3){
printf("Maximum = %.2f",num2);
}
else {
printf("Maximum = %.2f",num3);
}

return 0;
}

** problem No 6
#include <stdio.h>

int main() {
float number;

printf("Input number: ");
scanf("%f",&number);

if(number > 0){
printf("%.2f is positive ",number);
}

else if(number < 0){
printf("%.2f is Negetive ",number);
}
else {
printf("Number is Zero");
}

return 0;
}

** problem No 7
#include <stdio.h>

int main() {
int number;

printf("Input number: ");
scanf("%d",&number);

if(number % 2 == 0){
printf("%d is even number ",number);
}

else if(number % 2 == 1){
printf("%d is odd number ",number);
}
else {
printf("Number is Zero");
}

return 0;
}

** problem No 8
#include <stdio.h>

int main()
{
int week;

printf("Input week number:): ");
scanf("%d", &week);

if(week == 1)
{
printf("Monday");
}
else if(week == 2)
{
printf("Tuesday");
}
else if(week == 3)
{
printf("Wednesday");
}
else if(week == 4)
{
printf("Thursday");
}
else if(week == 5)
{
printf("Friday");
}
else if(week == 6)
{
printf("Saturday");
}
else if(week == 7)
{
printf("Sunday");
}
else
{
printf("Invalid Input! Please enter week number between 1-7.");
}

return 0;
}

** problem No 9
#include <stdio.h>

int main() {
float a,b,c,Root1,Root2,d;

printf("Input a = ");
scanf("%f",&a);

printf("Input b = ");
scanf("%f",&b);

printf("Input c = ");
scanf("%f",&c);

d = sqrt(b*b - 4*a*c);

Root1 = (-b + d)/(2*a);
Root2 = (-b - d)/(2*a);

printf("Root1 = %f ",Root1);
printf("Root1 = %f ",Root2);

return 0;
}

** problem No 10
#include <stdio.h>

int main() {
int month ,days;

printf("Enter number: ");
scanf("%d",&month);
switch(month){
case 1:
days = 31;
printf("Total number of days %d",days);
break;
case 2:
days = 28 ;
printf("Total number of days %d",days);
break;
case 3:
days = 31 ;
printf("Total number of days %d",days);
break;
case 4:
days = 30 ;
printf("Total number of days %d",days);
break;
case 5:
days = 31 ;
printf("Total number of days %d",days);
break;
case 6:
days = 30 ;
printf("Total number of days %d",days);
break;
case 7:
days = 31 ;
printf("Total number of days %d",days);
break;
case 8:
days = 30 ;
printf("Total number of days %d",days);
break;
case 9:
days = 31 ;
printf("Total number of days %d",days);
break;
case 10:
days = 30 ;
printf("Total number of days %d",days);
break;
case 11:
days = 31 ;
printf("Total number of days %d",days);
break;
case 12:
days = 30 ;
printf("Total number of days %d",days);
break;

default:
printf("Enter number between 1 to 12");
break;

}

return 0;
}

** problem No 11
#include <stdio.h>

int main() {
int number ;
printf("Input number:");
scanf("%d",&number);
switch (number>0){
case 1:
printf("%d is positive",number);
break;

case 0:
if (number == 0){
printf("Number is %d ",number);
}
else {
printf("%d is negetive ",number);
}
break;
}

return 0;
}

** problem No 12
#include <stdio.h>

int main() {
float num1 ,num2 , result ;
char op ;

printf("operator:");
scanf("%c",&op);

printf("Number 1:");
scanf("%f",&num1);

printf("Number 2:");
scanf("%f",&num2);

switch (op){
case '+':
result = num1+num2;
printf("%f",result);
break;

case '-':
result = num1-num2;
printf("%f",result);
break;

case '*':
result = num1*num2;
printf("%f",result);
break;

case '/':
result = num1/num2;
printf("%f",result);
break;
default :
printf("the operator is unvaild");
}
return 0;
}

# data[].attributes.body
MD.Abdullah Al Galib Shaikot
0242220005291033
#include <stdio.h>

int main() {
float num1, num2, result;
char op;

printf("Enter two numbers and an operator (+, -, *, /) separated by spaces: ");
scanf("%f %c %f", &num1, &op, &num2);

switch(op) {
case '+':
result = num1+num2;
printf("Result = %f",result);
break;
case '-':
result = num1-num2;
printf("Result = %f",result);
break;
case '*':
result = num1*num2;
printf("Result = %f",result);
break;
case '/':
if (num2 == 0) {
printf("Math Error");
return 0;
} else {
result = num1/num2;
printf("Result = %f",result);
}
break;
default:
printf("Invalid operator");
return 0;
}

return 0;
}

# data[].attributes.body
MD.Abdullah Al Galib Shaikot
0242220005291033

#include <stdio.h>

int main() {
int number ;
printf("Input number:");
scanf("%d",&number);
switch (number>0){
case 1:
printf("%d is positive",number);
break;

case 0:
if (number == 0){
printf("Number is %d ",number);
}
else {
printf("%d is negetive ",number);
}
break;
}

return 0;

# data[].attributes.body
MD.Abdullah Al Galib Shaikot
0242220005291033

#include <stdio.h>

int main() {
int month ,days;

printf("Enter number: ");
scanf("%d",&month);
switch(month){
case 1:
days = 31;
printf("Total number of days %d",days);
break;
case 2:
days = 28 ;
printf("Total number of days %d",days);
break;
case 3:
days = 31 ;
printf("Total number of days %d",days);
break;
case 4:
days = 30 ;
printf("Total number of days %d",days);
break;
case 5:
days = 31 ;
printf("Total number of days %d",days);
break;
case 6:
days = 30 ;
printf("Total number of days %d",days);
break;
case 7:
days = 31 ;
printf("Total number of days %d",days);
break;
case 8:
days = 30 ;
printf("Total number of days %d",days);
break;
case 9:
days = 31 ;
printf("Total number of days %d",days);
break;
case 10:
days = 30 ;
printf("Total number of days %d",days);
break;
case 11:
days = 31 ;
printf("Total number of days %d",days);
break;
case 12:
days = 30 ;
printf("Total number of days %d",days);
break;

default:
printf("Enter number between 1 to 12");
break;

}

return 0;
}

# data[].attributes.body
MD.Abdullah Al Galib Shaikot
0242220005291033
#include <stdio.h>

int main() {
float a,b,c,Root1,Root2,d;

printf("Input a = ");
scanf("%f",&a);

printf("Input b = ");
scanf("%f",&b);

printf("Input c = ");
scanf("%f",&c);

d = sqrt(b*b - 4*a*c);

Root1 = (-b + d)/(2*a);
Root2 = (-b - d)/(2*a);

printf("Root1 = %f ",Root1);
printf("Root1 = %f ",Root2);

return 0;
}

# data[].attributes.body
MD.Abdullah Al Galib Shaikot
0242220005291033
#include <stdio.h>

int main()
{
int week;

printf("Input week number:");
scanf("%d", &week);

if(week == 1)
{
printf("Monday");
}
else if(week == 2)
{
printf("Tuesday");
}
else if(week == 3)
{
printf("Wednesday");
}
else if(week == 4)
{
printf("Thursday");
}
else if(week == 5)
{
printf("Friday");
}
else if(week == 6)
{
printf("Saturday");
}
else if(week == 7)
{
printf("Sunday");
}
else
{
printf("Invalid Input! Please enter week number between 1-7.");
}

return 0;
}

# data[].attributes.body
MD.Abdullah Al Galib Shaikot
0242220005291033
#include <stdio.h>

int main() {
int number;

printf("Input number: ");
scanf("%d",&number);

if(number % 2 == 0){
printf("%d is even number ",number);
}

else if(number % 2 == 1){
printf("%d is odd number ",number);
}
else {
printf("Number is Zero");
}

return 0;
}

# data[].attributes.body
MD.Abdullah Al Galib Shaikot
0242220005291033
#include <stdio.h>

int main() {
float number;

printf("Input number: ");
scanf("%f",&number);

if(number > 0){
printf("%.2f is positive ",number);
}

else if(number < 0){
printf("%.2f is Negetive ",number);
}
else {
printf("Number is Zero");
}

return 0;
}

# data[].attributes.body
MD.Abdullah Al Galib Shaikot
0242220005291033
#include <stdio.h>

int main() {
float num1 ,num2 , num3;

printf("Input num1: ");
scanf("%f",&num1);

printf("Input num2: ");
scanf("%f",&num2);

printf("Input num3: ");
scanf("%f",&num3);

if(num1 > num2 && num1 > num3){
printf("Maximum = %.2f",num1);
}

else if(num2 > num3){
printf("Maximum = %.2f",num2);
}
else {
printf("Maximum = %.2f",num3);
}

return 0;
}

# data[].attributes.body
MD.Abdullah Al Galib Shaikot
0242220005291033
#include <stdio.h>

int main() {
float num1 ,num2;

printf("Input num1: ");
scanf("%f",&num1);

printf("Input num2: ");
scanf("%f",&num2);

if(num1 > num2){
printf("Maximum = %f",num1);
}
else{
printf("Maximum = %.2f",num2);
}

return 0;
}

# data[].attributes.body
MD.Abdullah Al Galib Shaikot
0242220005291033
#include <stdio.h>

int main() {
double  base,exp,result;
printf("Enter a base number:");
scanf("%lf",&base);

printf("Enter an exponent:");
scanf("%lf",&exp);

result = pow(base, exp);
printf("%lf",result);

return 0;
}

# data[].attributes.body
MD.Abdullah Al Galib Shaikot
0242220005291033
#include <stdio.h>

int main() {
float Celsius,Fahrenheit;

printf("Enter temperature in Celsius =");
scanf("%f",&Celsius);

Fahrenheit = (Celsius*9/5) + 32 ;
printf("Temperature in Fahrenheit = %.2f F",Fahrenheit);

return 0;
}

# data[].attributes.body
MD.Abdullah Al Galib Shaikot
0242220005291033

.#include <stdio.h>

int main() {
float base , height,area;

printf("Enter base of the triangle:");
scanf("%f",&base);

printf("Enter height of the triangle:");
scanf("%f",&height);

area =0.5*base*height;
printf("Area of the triangle = %f sq. units ",area);

return 0;
}

# data[].attributes.body
Problem 1
#include <stdio.h>

int main() {
float base , height,area;

printf("Enter base of the triangle:");
scanf("%f",&base);

printf("Enter height of the triangle:");
scanf("%f",&height);

area =0.5*base*height;
printf("Area of the triangle = %f sq. units ",area);

return 0;
}
Problem 2
#include <stdio.h>

int main() {
float Celsius,Fahrenheit;

printf("Enter temperature in Celsius =");
scanf("%f",&Celsius);

Fahrenheit  Celsius*9/5) + 32 ;
printf("Temperature in Fahrenheit = %.2f F",Fahrenheit);

return 0;
}
Problem 3

#include <stdio.h>
#include <math.h>
int main() {
double base,exponent,result;
printf("enter the value of base,exponent");
scanf("%lf%lf",&base,&exponent);
result= pow(base,exponent);
printf("the power is = %.2lf",result);

return 0;
}

Problem 4

#include <stdio.h>

int main() {
float num1 ,num2;

printf("Input num1: ");
scanf("%f",&num1);

printf("Input num2: ");
scanf("%f",&num2);

if(num1 > num2){
printf("Maximum = %f",num1);
}
else{
printf("Maximum = %.2f",num2);
}

return 0;
}
Problem 5
#include <stdio.h>

int main() {
float num1 ,num2 , num3;

printf("Input num1: ");
scanf("%f",&num1);

printf("Input num2: ");
scanf("%f",&num2);

printf("Input num3: ");
scanf("%f",&num3);

if(num1 > num2 && num1 > num3){
printf("Maximum = %.2f",num1);
}

else if(num2 > num3){
printf("Maximum = %.2f",num2);
}
else {
printf("Maximum = %.2f",num3);
}

return 0;
}
Problem 6
#include <stdio.h>

int main() {
float number;

printf("Input number: ");
scanf("%f",&number);

if(number > 0){
printf("%.2f is positive ",number);
}

else if(number < 0){
printf("%.2f is Negetive ",number);
}
else {
printf("Number is Zero");
}

return 0;
}
Problem 7

#include <stdio.h>

int main() {
int num;

printf("Enter a number: ");
scanf("%d", &num);

if (num % 2 == 0) {
printf("%d is even.", num);
}
else {
printf("%d is odd.", num);
}

return 0;
}

Problem 8
#include <stdio.h>

int main()
{
int week;

printf("Input week number:): ");
scanf("%d", &week);

if(week == 1)
{
printf("Monday");
}
else if(week == 2)
{
printf("Tuesday");
}
else if(week == 3)
{
printf("Wednesday");
}
else if(week == 4)
{
printf("Thursday");
}
else if(week == 5)
{
printf("Friday");
}
else if(week == 6)
{
printf("Saturday");
}
else if(week == 7)
{
printf("Sunday");
}
else
{
printf("Invalid Input! Please enter week number between 1-7.");
}

return 0;
}
Problem 9

#include <stdio.h>

int main() {
float a,b,c,Root1,Root2,d;

printf("Input a = ");
scanf("%f",&a);

printf("Input b = ");
scanf("%f",&b);

printf("Input c = ");
scanf("%f",&c);

d = sqrt(b*b - 4*a*c);

Root1 = (-b + d)/(2*a);
Root2 = (-b - d)/(2*a);

printf("Root1 = %f ",Root1);
printf("Root1 = %f ",Root2);

return 0;
}

Problem 11

#include <stdio.h>

int main() {
int num;

printf("Enter a number: ");
scanf("%d", &num);

switch(num > 0) {
case 1:
printf("%d is positive\n", num);
break;
case 0:
switch(num < 0) {
case 1:
printf("%d is negative\n", num);
break;
case 0:
printf("The number is zero\n");
break;
}
break;
}

return 0;
}
Problem 12

#include <stdio.h>

int main() {
// Write C code here
float num1,num2;
char oparat;
printf("enter an oparat (+,-,*,/0) : ");
scanf("%c",&oparat);
printf("enter two numbers");
scanf("%f %f",&num1,&num2);
switch (oparat)
{
case('+'):
{
printf("%f+%f=%f/n",num1,num2,num1+num2);
break;
}
case('-'):
{
printf("%f-%f=%f/n",num1,num2,num1-num2);
break;
}
case('*'):
{
printf("%f*%f=%f/n",num1,num2,num1*num2);
break;
}
case('/'):
{
printf("%f/%f=%f/n",num1,num2,num1/num2);
break;
}
default:
printf("not vaild oparat");
}

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
int weeknumber;
printf("enter the value of weeknumber");
scanf("%d",&weeknumber);
if (weeknumber==1)
printf("week day name is saturday");
else if (weeknumber==2)
printf("week day name is sunday");
else if (weeknumber==3)
printf("week day name is monday");
else if (weeknumber==4)
printf("week day name is thusday");
else if (weeknumber==5)
printf("week day name is wednesday");
else if (weeknumber==6)
printf("week day name is thursday");
else if (weeknumber==7)
printf("week day name is friday");
else
printf("input the right weeknumber");

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
int number;
printf("enter the value of number");
scanf("%d",&number);
if (number %2==0)
printf("the number is even value");
else if (number %2==1)
printf("the number is odd value");
else
printf("math error");

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
float number;
printf("enter the value of number");
scanf("%f",&number);
if (number==0)
printf("the number is zero");
else if(number>0)
printf("the number is positive");
else
printf("the number is negative");

return 0;
}

# data[].attributes.body
// Problem 1
#include <stdio.h>

int main() {
float base , height,area;

printf("Enter base of the triangle:");
scanf("%f",&base);

printf("Enter height of the triangle:");
scanf("%f",&height);

area =0.5*base*height;
printf("Area of the triangle = %f sq. units ",area);

return 0;
}

// Problem 2
#include <stdio.h>

int main() {
float Celsius,Fahrenheit;

printf("Enter temperature in Celsius =");
scanf("%f",&Celsius);

Fahrenheit  Celsius*9/5) + 32 ;
printf("Temperature in Fahrenheit = %.2f F",Fahrenheit);

return 0;
}

// Problem 4

#include <stdio.h>

int main() {
float num1 ,num2;

printf("Input num1: ");
scanf("%f",&num1);

printf("Input num2: ");
scanf("%f",&num2);

if(num1 > num2){
printf("Maximum = %f",num1);
}
else{
printf("Maximum = %.2f",num2);
}

return 0;
}

// Problem 5
#include <stdio.h>

int main() {
float num1 ,num2 , num3;

printf("Input num1: ");
scanf("%f",&num1);

printf("Input num2: ");
scanf("%f",&num2);

printf("Input num3: ");
scanf("%f",&num3);

if(num1 > num2 && num1 > num3){
printf("Maximum = %.2f",num1);
}

else if(num2 > num3){
printf("Maximum = %.2f",num2);
}
else {
printf("Maximum = %.2f",num3);
}

return 0;
}

// Problem 6
#include <stdio.h>

int main() {
float number;

printf("Input number: ");
scanf("%f",&number);

if(number > 0){
printf("%.2f is positive ",number);
}

else if(number < 0){
printf("%.2f is Negetive ",number);
}
else {
printf("Number is Zero");
}

return 0;
}

// Problem 8
#include <stdio.h>

int main()
{
int week;

printf("Input week number:): ");
scanf("%d", &week);

if(week == 1)
{
printf("Monday");
}
else if(week == 2)
{
printf("Tuesday");
}
else if(week == 3)
{
printf("Wednesday");
}
else if(week == 4)
{
printf("Thursday");
}
else if(week == 5)
{
printf("Friday");
}
else if(week == 6)
{
printf("Saturday");
}
else if(week == 7)
{
printf("Sunday");
}
else
{
printf("Invalid Input! Please enter week number between 1-7.");
}

return 0;
}

// Problem 9

#include <stdio.h>

int main() {
float a,b,c,Root1,Root2,d;

printf("Input a = ");
scanf("%f",&a);

printf("Input b = ");
scanf("%f",&b);

printf("Input c = ");
scanf("%f",&c);

d = sqrt(b*b - 4*a*c);

Root1 = (-b + d)/(2*a);
Root2 = (-b - d)/(2*a);

printf("Root1 = %f ",Root1);
printf("Root1 = %f ",Root2);

return 0;
}

# data[].attributes.body
// 1 No problem
#include <stdio.h>

int main() {
float base , height,area;

printf("Enter base of the triangle:");
scanf("%f",&base);

printf("Enter height of the triangle:");
scanf("%f",&height);

area =0.5*base*height;
printf("Area of the triangle = %f sq. units ",area);

return 0;
}

// 2 No problem Celsius to Fahrenheit
#include <stdio.h>

int main() {
float Celsius,Fahrenheit;

printf("Enter temperature in Celsius =");
scanf("%f",&Celsius);

Fahrenheit =( Celsius*9/5) + 32 ;
printf("Temperature in Fahrenheit = %.2f F",Fahrenheit);

return 0;
}

// 4 No problem maximum or minimum between two numbers using if else

#include <stdio.h>

int main() {
float num1 ,num2;

printf("Input num1: ");
scanf("%f",&num1);

printf("Input num2: ");
scanf("%f",&num2);

if(num1 > num2){
printf("Maximum = %f",num1);
}
else{
printf("Maximum = %.2f",num2);
}

return 0;
}

// 5 No problem maximum or minimum between three numbers
#include <stdio.h>

int main() {
float num1 ,num2 , num3;

printf("Input num1: ");
scanf("%f",&num1);

printf("Input num2: ");
scanf("%f",&num2);

printf("Input num3: ");
scanf("%f",&num3);

if(num1 > num2 && num1 > num3){
printf("Maximum = %.2f",num1);
}

else if(num2 > num3){
printf("Maximum = %.2f",num2);
}
else {
printf("Maximum = %.2f",num3);
}

return 0;
}

// 6 No problem Logic to check negative, positive or zero
#include <stdio.h>

int main() {
float number;

printf("Input number: ");
scanf("%f",&number);

if(number > 0){
printf("%.2f is positive ",number);
}

else if(number < 0){
printf("%.2f is Negetive ",number);
}
else {
printf("Number is Zero");
}

return 0;
}

// 7 No problem even and odd number using  if...else
#include <stdio.h>

int main() {
int number;

printf("Input number: ");
scanf("%d",&number);

if(number % 2 == 0){
printf("%d is even number ",number);
}

else if(number % 2 == 1){
printf("%d is odd number ",number);
}
else {
printf("Number is Zero");
}

return 0;
}

// 8 No problem Logic to convert week number to day of week
#include <stdio.h>

int main()
{
int week;

printf("Input week number:): ");
scanf("%d", &week);

if(week == 1)
{
printf("Monday");
}
else if(week == 2)
{
printf("Tuesday");
}
else if(week == 3)
{
printf("Wednesday");
}
else if(week == 4)
{
printf("Thursday");
}
else if(week == 5)
{
printf("Friday");
}
else if(week == 6)
{
printf("Saturday");
}
else if(week == 7)
{
printf("Sunday");
}
else
{
printf("Invalid Input! Please enter week number between 1-7.");
}

return 0;
}

// 9 No problem Logic to find roots of quadratic equation

#include <stdio.h>

int main() {
float a,b,c,Root1,Root2,d;

printf("Input a = ");
scanf("%f",&a);

printf("Input b = ");
scanf("%f",&b);

printf("Input c = ");
scanf("%f",&c);

d = sqrt(b*b - 4*a*c);

Root1 = (-b + d)/(2*a);
Root2 = (-b - d)/(2*a);

printf("Root1 = %f ",Root1);
printf("Root1 = %f ",Root2);

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
float g,h,k;
printf("enter the value of three number g,h,k");
scanf("%f%f%f",&g,&h,&k);
if (g>=h && g>=k)
printf("maxium number is g");
else if (h>=g && h>k )
printf("maxium number is h");
else if(k>=g && k>=h)
printf("maxium number is k");

return 0;
}

# data[].attributes.body
#include <stdio.h>
int main() {
float g,h;
printf("enter the value of two number g,h");
scanf("%f%f",&g,&h);
if (g>h)
printf("maxium number is =%.2f",g);
else
printf("maxium number is =%.2f",h);

return 0;
}

# data[].attributes.body
#include <stdio.h>
#include <math.h>
int main() {
double base,exponent,result;
printf("enter the value of base,exponent");
scanf("%lf%lf",&base,&exponent);
result= pow(base,exponent);
printf("the power is = %.2lf",result);

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
int num;

printf("Enter a number: ");
scanf("%d", &num);

switch(num > 0) {
case 1:
printf("%d is positive\n", num);
break;
case 0:
switch(num < 0) {
case 1:
printf("%d is negative\n", num);
break;
case 0:
printf("The number is zero\n");
break;
}
break;
}

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
float centigrade,farhenheit;
printf("enter cetigrade value");
scanf("%f",&centigrade);
farhenheit= (1.8*centigrade)+32;
printf("convert centigrade into farhenheit= %.2f",farhenheit);

return 0;
}

# data[].attributes.body
Maesha Sadia
ID : 0242220005291015

# data[].attributes.body
#include <stdio.h>

int main() {
int month, days;

printf("Enter month number (1-12): ");
scanf("%d", &month);

switch(month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days = 31;
break;
case 4:
case 6:
case 9:
case 11:
days = 30;
break;
case 2:
days = 28;
break;
default:
printf("Invalid month number\n");
return 0;
}

printf("Number of days in month %d is %d\n", month, days);

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
int weekNum;

printf("Enter week number (1-7): ");
scanf("%d", &weekNum);

if (weekNum == 1)
printf("Monday\n");
else if (weekNum == 2)
printf("Tuesday\n");
else if (weekNum == 3)
printf("Wednesday\n");
else if (weekNum == 4)
printf("Thursday\n");
else if (weekNum == 5)
printf("Friday\n");
else if (weekNum == 6)
printf("Saturday\n");
else if (weekNum == 7)
printf("Sunday\n");
else
printf("Invalid week number. Please enter a number between 1 and 7.\n");

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
int num;

printf("Enter a number: ");
scanf("%d", &num);

if (num % 2 == 0) {
printf("%d is even.", num);
}
else {
printf("%d is odd.", num);
}

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
int num;

printf("Enter a number: ");
scanf("%d", &num);

if (num > 0) {
printf("%d is a positive number.", num);
}
else if (num < 0) {
printf("%d is a negative number.", num);
}
else {
printf("%d is zero.", num);
}

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
int num1, num2, num3;

// Prompt the user to enter the three numbers
printf("Enter the first number: ");
scanf("%d", &num1);

printf("Enter the second number: ");
scanf("%d", &num2);

printf("Enter the third number: ");
scanf("%d", &num3);

// Determine the maximum of the three numbers using nested if statements
if (num1 >= num2) {
if (num1 >= num3) {
printf("Maximum = %d\n", num1);
} else {
printf("Maximum = %d\n", num3);
}
} else {
if (num2 >= num3) {
printf("Maximum = %d\n", num2);
} else {
printf("Maximum = %d\n", num3);
}
}

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
float base,height,area;
printf("enter the value of base,height"),
scanf("%f%f",&base,&height);
area=0.5*base*height;
printf("area of triangle=%.2f",area);

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
int num1, num2;

// Prompt the user to enter the two numbers
printf("Enter the first number: ");
scanf("%d", &num1);

printf("Enter the second number: ");
scanf("%d", &num2);

// Determine the maximum of the two numbers using if-else
if (num1 > num2) {
printf("Maximum = %d\n", num1);
} else {
printf("Maximum = %d\n", num2);
}

return 0;
}

# data[].attributes.body
#include <stdio.h>
#include <math.h>

int main() {
double base, exponent, result;

// Prompt the user to enter the base and exponent
printf("Enter the base: ");
scanf("%lf", &base);

printf("Enter the exponent: ");
scanf("%lf", &exponent);

// Calculate the result using pow() function
result = pow(base, exponent);

// Display the result
printf("%.2lf^%.2lf = %.2lf\n", base, exponent, result);

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
float celsius, fahrenheit;

// Prompt the user to enter the temperature in Celsius
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);

// Convert Celsius to Fahrenheit
fahrenheit = (celsius * 9 / 5) + 32;

// Display the temperature in Fahrenheit
printf("%.2f Celsius = %.2f Fahrenheit\n", celsius, fahrenheit);

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
float base, height, area;

// Prompt the user to enter the base and height
printf("Enter base of the triangle: ");
scanf("%f", &base);

printf("Enter height of the triangle: ");
scanf("%f", &height);

// Calculate the area of the triangle
area = 0.5 * base * height;

// Display the area of the triangle
printf("Area of the triangle = %0.2f sq. units\n", area);

return 0;
}

# data[].attributes.body
#include <stdio.h>

int main() {
float a,b,c,d,x1,x2;
printf("enter the value of a,b,c");
scanf("%f%f%f",&a,&b,&c);

d= sqrt (b*b-4*a*c);

x1= (-b+d)/(2*a);
x2= (-b-d)/(2*a);

printf("x1= %f",x1);
printf("x2= %f",x2);

return 0;
}

# data[].attributes.body
Question 1-5
Answer:
1.
#include <stdio.h>
int main() {
int u,p;

printf("Enter your username \n");
scanf("%d",&u);
if(u==123){
printf(" ");
}
else {
printf("Wrong Username");
}

printf("Enter your Password \n");
scanf("%d",&p);
if(p==12548){

printf("Log in Successful");
}
else {
printf("Wrong Password");
}

return 0;
}

2.
#include <stdio.h>

int main() {
int total=40;
int boys=22;
int girls;
float per;

per=40*.7;
printf("Number of students secured grade A = %f\n",per);
printf("Number of boys secured A grade = 22\n");
girls=per-boys;
printf("Number of girls secured A grade = %d\n",girls);

return 0;
}
3.
#include <stdio.h>

int main() {
float numC,numA;
float percentage;
printf("Enter the number of total classes:\n");
scanf("%f",&numC);
printf("Enter the number of attendance:\n");
scanf("%f",&numA);

percentage=(numA/numC)*100;
printf("Youre attendance percentage = %f\n",percentage);
if(percentage>=60){
printf("Youre allowed in the exam");
}
else{
printf("Sorry! youre not allowed in the exam");
}
return 0;
}
4.
#include <stdio.h>

int main() {
int time_taken;

printf("Enter the time taken by a worker to complete a work :\n");
scanf("%d",&time_taken);
if(time_taken>=2 && time_taken<3){
printf("Highly efficient");
}
else if(time_taken>=3 && time_taken<4){
printf("Workers orderd to increase their speed");
}
else if(time_taken>=4 && time_taken<=5){
printf("Workers need to take training to improve their speed");
}
else if(time_taken>5){
printf("The worker must leave the company");
}
return 0;
}
5.#include <stdio.h>

int main() {
int s,p,m;
printf("how many song\n");
int song;
scanf("%d",&song);
if(song%3==0){
s=song/3;
p=song/3;
m=song/3;
}
else if(song%3==1){
s=(song/3)+1;
p=song/3;
m=song/3;

}
else if(song%3==2){
s=(song/3)+1;
p=(song/3)+1;
m=song/3;
}
printf("sajida=%d\n proma=%d\n mukta=%d",s,p,m);

return 0;
}

# data[].attributes.body
problem no.8
#include <stdio.h>

int main()
{
int week;

printf("Input week number:): ");
scanf("%d", &week);

if(week == 1)
{
printf("Monday");
}
else if(week == 2)
{
printf("Tuesday");
}
else if(week == 3)
{
printf("Wednesday");
}
else if(week == 4)
{
printf("Thursday");
}
else if(week == 5)
{
printf("Friday");
}
else if(week == 6)
{
printf("Saturday");
}
else if(week == 7)
{
printf("Sunday");
}
else
{
printf("Invalid Input! Please enter week number between 1-7.");
}

return 0;
}

# data[].attributes.body
problem no.7

#include <stdio.h>

int main() {
int number;

printf("Input number: ");
scanf("%d",&number);

if(number % 2 == 0){
printf("%d is even number ",number);
}

else if(number % 2 == 1){
printf("%d is odd number ",number);
}
else {
printf("Number is Zero");
}

return 0;
}