Contact : +88 01840-723661

|

Email : info@jakafind.com

C Programming Entire Topics Practice

C Programming Entire Topics Practice

 

Topics-01: Overview of C

Problem – 01

Printing “Hello World!”.

#include <stdio.h>
int main()
{
printf("Hello World!");
return 0;
}

Problem – 02

Printing two sentences on two different lines. (Using of \n)

#include <stdio.h>
int main()
{
printf("Hello\nWorld!");
return 0;
}

Problem – 03

Print a line in a quotation mark (For example: “Hello World”.)

#include <stdio.h>
int main()
{
printf("\"Hello World!\"");
return 0;
}

 

Topics-02 : Data Types and Variables

Problem – 01

Taking 2 integer numbers as input and then add, subtract, multiply and divide them.
Finally print the output results.

#include <stdio.h>
int main() {
float a, b, sum, sub, mul, dev;
printf("Enter First number: ");
scanf("%f", &a);
printf("Enter Second number: ");
scanf("%f", &b);
sum=a+b;
sub=a-b;
mul=a*b;
dev=a/b;
printf("The Two Number Addition is: %.4f\n", sum);
printf("The Two Number Substrction is: %.4f\n", sub);
printf("The Two Number Multification is: %.4f\n", mul);
printf("The Two Number Divided is: %.4f\n", dev);
return 0;
}

Problem – 02

Taking 3 float numbers and calculating the average of them.

#include <stdio.h>
int main()
{
float a,b,c, avr;
printf("Enter Three number: ");
scanf("%f %f %f", &a, &b, &c);
avr=(a+b+c)/3;
printf("The Floating Average Number is: %.4f\n", avr);
return 0;
}

Problem – 03

The length & breadth of a rectangle are input through the keyboard. Find out the
rectangle’s area.
#include <stdio.h>
int main() {
float lenth, breadth, area;
printf("Enter First number: ");
scanf("%f", &lenth);
printf("Enter Second number: ");
scanf("%f", &breadth);
area = lenth*breadth;
printf("The Rectangular Area is: %.4f\n", area);
return 0; }

Problem – 04

Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a
program to convert this temperature into Centigrade degrees.
fahrenheit=(celcius*9/5)+32
#include <stdio.h>
int main() {
float C,F;
printf("Enter Fahrenheit Value: ");
scanf("%f", &F);
C = (F-32)/1.8;
printf("The Centigrade Value : %.2f \n", C);
return 0; }

Problem – 05

The distance between Mirpur and Ashulia is input through the keyboard in meters. Write
a program to convert and print this distance in feet, inches and centimeters.
1 meter=100 cm
1 meter=39.37 inch
1 meter=3.21 feet
#include <stdio.h>
int main() {
float distance, vulue_cm, vulue_inch, vulue_feet;
printf("Enter The Distanc Mirpur and Ashulia at Meter: ");
scanf("%f", &distance);
vulue_cm = distance*100;
vulue_inch = distance*39.37;
vulue_feet = distance*3.21;
printf("The Value at cm is: %.2f cm\n",vulue_cm );
printf("The Value at inch is: %.2f inch\n",vulue_inch );
printf("The Value at feet is: %.2f feet\n",vulue_feet );
return 0; }

Problem – 06

Niloys basic salary is input through the keyboard. His dearness allowance is 40% of his
basic salary and house rent is 20% of his basic salary. Write a program to calculate his
gross salary.
gross_salary=basic_salary+dearness_allowence+house_rent.
#include <stdio.h>
int main() {
float salary, basic_salary, house_rant,total_sarary;
printf("Enter Your Salary:  ");
scanf("%f", &salary);
basic_salary = salary*.2;
house_rant = salary*.4;
total_sarary = salary + basic_salary+house_rant;
printf("Total Salary = %f",total_sarary);
return 0; }

Problem – 07

If the marks obtained by a student in five different subjects are input through the keyboard,
find out the aggregate marks and average marks obtained by the student.
Assume that the maximum marks that can be obtained by a student in each subject is 100.
#include <stdio.h>
int main() {
float sub1, sub2, sub3, sub4, sub5;
printf("Enter marks for Subject 1: ");
scanf("%f", &sub1);
printf("Enter marks for Subject 2: ");
scanf("%f", &sub2);
printf("Enter marks for Subject 3: ");
scanf("%f", &sub3);
printf("Enter marks for Subject 4: ");
scanf("%f", &sub4);
printf("Enter marks for Subject 5: ");
scanf("%f", &sub5);
float aggregateMarks = sub1 + sub2 + sub3 + sub4 + sub5;
float averageMarks = (float)aggregateMarks / 5;
printf("Aggregate Marks: %.2f\n", aggregateMarks);
printf("Average Marks: %.2f\n", averageMarks);
return 0; }

Problem – 08

Printing a character with its ASCII value.
#include <stdio.h>
int main() {
char ch;
printf("Enter any character : ");
scanf("%c", &ch);
printf("The ASCII value is : %d \n",ch);
return 0; }

Problem – 09

Beecrowd Problem 1001
https://www.beecrowd.com.br/judge/en/problems/view/1001
#include <stdio.h>
int main() {
int A, B, X;
scanf("%d %d", &A,&B);
X = A + B;
printf("X = %d\n", X);
return 0;}

Problem – 10

Beecrowd Problem 1002
https://www.beecrowd.com.br/judge/en/problems/view/1002
#include <stdio.h>
int main() {
double pi = 3.14159;
double R, area;
scanf("%lf", &R);
area = pi * R * R;
printf("A=%.4lf\n", area);
return 0;}

 

Topics-03 : Operator and Expression

Problem – 01

Find out the largest between three numbers using conditional operator.
#include <stdio.h>
int main() {
int a, b;
printf("Enter a Number: ");
scanf("%d", &a);
(a%2==0)? printf("Even"):printf("Odd");
return 0; }

Problem – 02

Find out if a number is odd or even using Ternary operator.
#include <stdio.h>
int main() {
int num1,num2,num3,largest;
printf("Enter Three iInteger Number: ");
scanf("%d %d %d",&num1,&num2,&num3);
largest = (num1 > num2 && num1 > num3)? num1 : (num2 > num3)? num2 : num3;
printf("The Largest number is : %d\n", largest);
return 0; }

Problem – 03

Find out if the input is an alphabet using Ternary operator.
#include <stdio.h>
int main() {
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
(ch>='a' && ch<='z') || (ch>='A' && ch<='Z') 
? printf("It is ALPHABET")
: printf("It is NOT ALPHABET");
return 0; }

Problem – 04

A computer manufacturing company has the following monthly compensation policy to the sales-person:
Minimum base salary: 1500.00
Bonus for every computer sold: 200.00
Commission on the total monthly sales: 2%
Write a program to calculate the gross salary for a sales person.
You will take input the price of each computer and the number of sold during the month.
#include <stdio.h>
int main() {
float salary, bonus, commission, price, sold, total_sarary;
salary=1500.00;
printf("Enter Each Computer Price: ");
scanf("%f", &price);
printf("Enter Total Computer Sold: ");
scanf(“%f”, &sold);
bonus = price*200;
commission = price*sold*.2;
total_sarary = salary + bonus + commission;
printf("Total Salary = %f\n",total_sarary);
return 0; }

Problem – 05

If the total selling price of 15 items and the total profit earned on
them is input through the keyboard, write a program to find the cost price of one item.
#include <stdio.h>
int main () {
float a, b, price;
printf("Enter 15 item Price: ");
scanf("%f", &a);
printf("Enter 15 item Profit: ");
scanf("%f", &b);
price=(a-b)/15;
printf("Cost of Each Product Price = %.2f", price);
return 0; }

Problem – 06

Beecrowd Problem 1007
https://www.beecrowd.com.br/judge/en/problems/view/1007
#include <stdio.h>
int main() {
int A, B, C, D;
int difference;
scanf("%d %d %d %d", &A, &B, &C, &D);
difference = (A * B) - (C * D);
printf("DIFERENCA = %d\n", difference);
return 0; }

Problem – 07

Beecrowd Problem 1008
https://www.beecrowd.com.br/judge/en/problems/view/1004
#include <stdio.h>
int main () {
int NUMBER,hours;
float amount,SALARY;
scanf("%d %d %f", &NUMBER, &hours, &amount);
SALARY = hours * amount;
printf("NUMBER = %d\n",NUMBER);
printf("SALARY = U$ %0.2f\n", SALARY);
return 0; }

 

Topics-04 : Conditional Statement


Problem – 01

Write a C program to find out if a number is odd or even using conditional operator.
#include <stdio.h>
int main() {
int num;
printf ("Enter an integer: ");
scanf("%d", &num);
if(num % 2 == 0)
printf("%d is an even number.", num);
else
printf("%d is a odd number.", num);
return 0; }

Problem – 02

Write a C program to input a character from the user and
check whether the given character is alphabet or not an alphabet using if else.
#include <stdio.h>
int main() {
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
if ((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))
printf("This is an ALPHABET\n");
else 
printf("This is NOT an ALPHABET\n");
return 0; }

Problem – 03

Write a program to check whether a triangle is valid or not,
when the three angles of the triangle are entered through the keyboard.
A triangle is valid if the sum of all the three angles is equal to 180 degrees. 
#include <stdio.h>
int main() {
float a, b, c;
printf ("Enter three angles of any triangle: ");
scanf("%f %f %f", &a, &b, &c);
if(a+b+c==180)
printf("This is a Triangle.");
else
printf("This is not a Triangle.");
return 0; }

Problem – 04

Write a C program to check leap years using if else.
#include<stdio.h>
int main() {
int year;
printf("Enter any year: ");
scanf("%d",&year);
if(year%400==0){
printf("It is a leap year = %d",year);
} else if(year%4==0 && year%100!=0){
printf("It is a leap year = %d",year);
} else printf("It is not a leap year");
return 0; }

Problem – 05

If the ages of Arif, Fahmid and Joy are input through the keyboard,
write a program to determine the youngest of the three.
#include <stdio.h>
int main() {
int alif, fahmid, joy;
printf("Enter the age of Alif: ");
scanf("%d", &alif);
printf("Enter the age of Fahmid: ");
scanf("%d", &fahmid);
printf("Enter the age of Joy: ");
scanf("%d", &joy);
if (alif < fahmid && alif < joy)
printf("Alif is the youngest person.\n");
else if (fahmid < joy)
printf("Fahmid is the youngest person.\n");
else
printf("Joy is the youngest person.\n");
return 0; }

Problem – 06

Write a C program to input marks of five subjects Physics, Chemistry,
Biology, Mathematics and Computer, calculate percentage and grade according to given conditions:
         If percentage >= 90% : Grade A
         If percentage >= 80% : Grade B
         If percentage >= 70% : Grade C
         If percentage >= 60% : Grade D
         If percentage >= 40% : Grade E
         If percentage < 40% : Grade F
#include<stdio.h>
int main(){
float c, p, b, m, co, avr_marks;
printf("Enter your chemistry marks: ");
scanf("%f", &c);
printf("Enter your physics marks: ");
scanf("%f", &p);
printf("Enter your biology marks: ");
scanf("%f", &b);
printf("Enter your mathematics marks: ");
scanf("%f", &m);
printf("Enter your computer marks: ");
scanf("%f", &co);
avr_marks = ((c+p+b+m+co)*100)/500;
if(avr_marks >=90)
printf("Grade A");
else if(avr_marks >=80)
printf("Grade B");
else if(avr_marks >=70)
printf("Grade C");
else if(avr_marks >=60)
printf("Grade D");
else if(avr_marks >=40)
printf("Grade E");
else if(avr_marks <40)
printf("Grade F");
else
printf ("Please Enter Your Subject Number.\n");
return 0; }

Problem – 07

An electric power distribution company charges its domestic consumers as follows:
Consumption Units Rate of Charge
0 – 200 Rs. 0.50 per unit
201 – 400 Rs. 100 plus Rs. 0.65 per unit excess of 200
401 – 600 Rs. 230 plus Rs. 0.80 per unit excess of 400
601 and above Rs. 390 plus Rs. 1.00 per unit excess of 600
Write a program that reads the power consumed by
a customer and prints the amount to be paid by the customer.
#include <stdio.h>
int main() {
int cus;
float units, bill;
printf("Enter Customer Id Number: ");
scanf("%d",&cus);
printf("Enter Total Customer Units: ");
scanf("%f", &units);
if(units <= 200)
bill = 0.50 * units;
else if(units >= 201 && units <= 400)
bill = 100 + 0.65 * (units - 200);
else if(units >= 401 && units <= 600)
bill = 230 + 0.80 * (units - 400);
else 
bill = 390 + 1.00 * (units - 600);
printf("\n Customer Number = %d", cus);
printf("\n Units consumed  = %.2f", units);
printf("\n Bill = %.2f", bill);
return 0; }

Problem – 08

Write a c program for +,-,*,/operation using switch case.
#include <stdio.h>
int main() {
char operator;
double a, b;
printf("Enter Any Opearator (+, -, *, /) : ");
scanf("%c", &operator);
printf("Enter Your First Number: ");
scanf("%lf", &a);
printf("Enter Your Second Number: ");
scanf("%lf", &b);
switch (operator){
case'+':
printf("\nAddition : %.2lf + %.2lf = %.2lf", a, b, a+b);
break;
case'-':
printf("\nSubstruction : %.2lf - %.2lf = %.2lf", a, b, a-b);
break;
case'*':
printf("\nMultification : %.2lf * %.2lf = %.2lf", a, b, a*b);
break;
case'/':
if(b==0) 
printf("\nSecond value is 0. So, The divided value is undefine");
else
printf("\nDivided : %.2lf / %.2lf = %.2lf", a, b, a/b);
break; }
return 0; }

Problem – 09

Beecrowd Problem 1038
https://www.beecrowd.com.br/judge/en/problems/view/1038
#include <stdio.h>
int main() {
int X, Y;
float price = 0;
scanf("%d %d", &X, &Y);
if (X == 1) {
price = (float) (4.00 * Y); }
else if (X == 2) {
price = (float) (4.50 * Y); }
else if (X == 3) {
price = (float) (5.00 * Y); }
else if (X == 4) {
price = (float) (2.00 * Y); }
else if (X == 5) {
price = (float) (1.50 * Y); }
printf("Total: R$ %.2f\n", price);
return 0; }

Problem – 10

Beecrowd Problem 1044
https://www.beecrowd.com.br/judge/en/problems/view/1044
#include <stdio.h> 
int main() { 
int num_a, num_b; 
scanf("%d %d", &num_a, &num_b); 
if (num_b % num_a == 0 || num_a % num_b == 0) { 
printf("Sao Multiplos\n"); 
} else { 
printf("Nao sao Multiplos\n"); }
return 0; }

Topics-05 : Loop

Problem – 01

BeeCrowd Problem: 1059
https://www.beecrowd.com.br/judge/en/problems/view/1059
#include <stdio.h>
int main() {
int i;
for(i=2; i<=100; i=i+2) {
printf("%d\n",i); }
return 0; }

Problem – 02

WAP to sum up numbers in a range. (For example: from 1 to 10).
#include <stdio.h>
int main() {
int a,sum=0;
for (a =2; a<=10; a+=2) {
sum += a; }
printf("The sum of the even numbers from 1 to 10 is: %d \n", sum);
return 0; }

Problem – 03

If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits. 
#include <stdio.h>
int main() {
int number;
int sum = 0;
printf("Enter a five-digit number: ");
scanf("%d", &number);
if (number < 10000 || number > 99999) {
printf("Invalid input. Please enter a five-digit number.\n"); }
while (number > 0) {
sum += number % 10;
number /= 10; }
printf("The sum of the digits of the entered number is: %d\n", sum);
return 0; }

Problem – 04

A five-digit number is entered through the keyboard.
Write a program to obtain the reversed number and to determine
whether  the original and reversed numbers are equal or not.
#include <stdio.h>
int main( ) {
int number, reverse=0, remainder, num;
printf("Enter a 5 digit number: ");
scanf("%d", &number);
if (number < 10000 || number > 99999) {
printf("Invalid input. Please enter a five-digit number.\n"); }
num=number;
while (num>0) {
remainder=num%10;
reverse=reverse*10+remainder;
num=num/10;}
printf("Reverse number is %d \n", reverse);
if(number == reverse)
printf("Reverse number is equal to actual number.\n");
else
printf("Reverse number is not equal to actual number.\n");
return 0; }

Problem – 05

Write a program to find the factorial value of any number entered through the keyboard.
#include <stdio.h> 
int main(){
int a, b = 1, num; 
printf("Input the number : "); 
scanf("%d", &num); 
for(a = 1; a <= num; a++) 
b = b * a;
printf("The Factorial of %d is: %d\n", num, b); 
return 0; }

Problem – 06

Write a program to print all prime numbers in a range.
#include <stdio.h> 
int main() {
int num, a, b, start, end; 
printf("Input starting number: ");
scanf("%d", &start);
printf("Input the ending number: ");
scanf("%d", &end); 
printf("The prime numbers between %d and %d are: \n", start, end);
for (num = start; num <= end; num++) { 
b = 0; 
for (a = 2; a <= num / 2; a++) { 
if (num % a == 0) { 
b++; 
break; } }
if (b == 0 && num != 1) 
printf("%d ", num); }
printf("\n"); 
return 0; }

Problem – 07

Check the following number prime or not by taking input from the user. 
#include <stdio.h>
int main() {
int a, num, prime;
prime = 1; 
printf("Enter any number to check prime or not: ");
scanf("%d", &num);
for(a=2; a<=num/2; a++) {
if(num%a==0) {
prime = 0;
break; } }
if(prime == 1 && num > 1) {
printf("\n%d is prime number", num); }
else {
printf("\n%d is composite number", num); }
return 0; }

Problem – 08

Print Fibonacci series up to a certain number by taking input from the user.

#include <stdio.h>
int main() {
int a, num;
int b1 = 0, b2 = 1;
int next = b1 + b2;
printf("Enter the number of terms: ");
scanf("%d", &num);
printf("Fibonacci Series: %d, %d, ", b1, b2);
for (a = 3; a <= num; ++a) {
printf("%d, ", next);
b1 = b2;
b2 = next;
next = b1 + b2;}
return 0; }

Problem – 09

#include<stdio.h>
int main() {
float x;
int i,sum=0;
for(i=1;i<=6;i++){
scanf("%f",&x);
if(x>0){
sum=sum+1; } }
printf("%d valores positivos\n",sum);
return 0; }

Problem – 10

Print the following pattern. 
     1 
     2 1 
     3 2 1
     4 3 2 1 
     5 4 3 2 1
#include <stdio.h>
int main() {
int a,b;
for (a = 1; a <= 5; a++) {
for (int b = a; b >=1; b--) {
printf(" %d ", b); }
printf("\n"); }
return 0; }

Topics-06 : Array

Problem – 01

Print an array that outputs only the odd number from the array.
#include <stdio.h>
int main(){
int a, b;
printf("Enter your any array size: ");
scanf("%d", &a);
int nur[a];
printf("Enter %d Numbers: ", a);
for(b=0;b<a;b++){
scanf("%d",&nur[b]);}
printf("Odd Numbers in Array are: ");
for(b=0;b<a;b++){
if(nur[b]%2!=0)
printf("%d ",nur[b]);}
return 0;}

Problem – 02

Write a program to sum up the even elements of an array.
#include <stdio.h>
int main() {
int a, b, sum=0;
printf("Enter your any array size: ");
scanf("%d", &a);
int nur[a];
printf("Enter %d Numbers: ", a);
for(b=0; b<a; b++)
scanf("%d", &nur[b]);
for(b=0; b<a; b++) {
if(nur[b]%2==0)
sum=sum+nur[b]; }
printf("Total Sum of Even values is: %d ",sum);
return 0; }

Problem – 03

Write a program

#include <stdio.h>
int main() {
int a, b, c, d;
printf("Enter your any array size: ");
scanf("%d", &a);
int nur[a];
printf("Enter %d Numbers: ", a);
for(b=0; b=0;d-- ) {
printf("%d ", nur[d]); }
return 0; }

Problem – 04

Write a program
#include <stdio.h>
int main() {
int a, b;
printf("Enter your any array size: ");
scanf(“%d”, &a);
int nur[a];
printf("Enter %d Numbers: ", a);
for(b=0; b<a; b++){
scanf("%d", &nur[b]);}
printf("The maximum numbers are: ");
int max = nur[0];
for(b=1; b>max;) {
max=nur[b];}
printf("%d", max);
return 0; }

 

Thank You!

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *