SlideShare a Scribd company logo
Common Problems
Solving using C Language
Instructor:
Arghodeep Paul
Firmware Engineer at BitBible Technologies Pvt. Ltd.
Content Author: Arghodeep Paul
License: OpenSource
Date: 01 August 2021
IF ELSE:
1. Check whether the user entered number is positive.
#include<stdio.h>
int main(){
int number;
printf("Enter a number:");
scanf("%d",&number);
if(number>0){
printf("%d is a positive number!",number);
}
else{
printf("%d is a negative number",number);
}
return 0;
}
2. Write a program to check whether a number is even
or odd.
#include<stdio.h>
int main(){
int num;
printf("Enter a number:");
scanf("%d",&num);
if(num%2==0){
printf("%d is an even number!",num);
}
else{
printf("%d is an odd number",num);
}
return 0;
}
FOR LOOP:
3. Write a program to display first 10 natural numbers
#include <stdio.h>
int main()
{
int i;
printf("The first 10 natural numbers are:n");
for (i=1;i<=10;i++)
{
printf("%d ",i);
}
printf("n");
return 0;
}
4. Write a program to find biggest among two numbers.
#include<stdio.h>
int main()
{
int n1,n2,sum;
printf("nEnter 1st number : ");
scanf("%d",&n1);
printf("nEnter 2nd number : ");
scanf("%d",&n2);
if(n1 > n2)
printf("n1st number is greatest.");
else
printf("n2nd number is greatest.");
return 0;
}
WHILE LOOP:
5. Write a program to display natural numbers upto a
given range.
#include <stdio.h>
int main()
{
int num,i;
printf("Enter a number : ");
scanf("%d", &num);
i = 0;
while (i <= num)
{
printf("n%d",i);
i++;
}
return 0;
}
6. Write a program to display sum of first 5 natural
number.
#include <stdio.h>
int main()
{
int num, i, sum = 0;
printf("Enter a positive number : ");
scanf("%d", &num);
i = 0;
while (i <= num)
{
sum = sum + i;
i++;
}
printf(" n Sum of first %d natural number is : %d", num,
sum);
return 0;
}
7. Write a program to generate the following series 1 4
9 16 …. 100
#include<stdio.h>
int main()
{
int i;
for(i=1;i<=10;i++)
{
printf("n%d",i*i);
}
return 0;
}
8. Write a program to find out sum of first 10 natural
numbers
int main()
{
int i, sum = 0;
i = 0;
while (i <= 10)
{
sum = sum + i;
i++;
}
printf(" n Sum of first 10 natural number is : %d", sum);
return 0;
}
9. Write a program to read 10 numbers and find their
sum and average
#include <stdio.h>
int main()
{
int i,n,sum=0;
float avg;
printf("Input the 10 numbers : n");
for (i=1;i<=10;i++)
{
printf("Number-%d :",i);
scanf("%d",&n);
sum +=n;
}
avg=sum/10.0;
printf("The sum of 10 no is : %dnThe Average
is : %fn",sum,avg);
return 0;
}
10. Find cube of the number upto a given integer
#include <stdio.h>
int main()
{
int i,ctr;
printf("Input number of terms : ");
scanf("%d", &ctr);
for(i=1;i<=ctr;i++)
{
printf("Number is : %d and cube of the %d is :%d n",i,i,
(i*i*i));
}
return 0;
}
11. Compute multiplication table of a given integer
#include <stdio.h>
int main()
{
int j,n;
printf("Input the number (Table to be calculated) : ");
scanf("%d",&n);
printf("nn");
for(j=1;j<=10;j++)
{
printf("%d X %d = %d n",n,j,n*j);
}
return 9;
}
12. Display n number of multiplication table vertically
#include <stdio.h>
int main()
{
int j,i,n;
printf("Input upto the table number starting from 1 : ");
scanf("%d",&n);
printf("Multiplication table from 1 to %d n",n);
for(i=1;i<=10;i++)
{
for(j=1;j<=n;j++)
{
if (j<=n-1)
printf("%dx%d = %d, ",j,i,i*j);
else
printf("%dx%d = %d",j,i,i*j);
}
printf("n");
}
return 0;
}
13. Check whether the entered year is leap year or not.
#include <stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);
// leap year if perfectly divisible by 400
if (year % 400 == 0) {
printf("%d is a leap year.", year);
}
// not a leap year if divisible by 100
// but not divisible by 400
else if (year % 100 == 0) {
printf("%d is not a leap year.", year);
}
// leap year if not divisible by 100
// but divisible by 4
else if (year % 4 == 0) {
printf("%d is a leap year.", year);
}
// all other years are not leap years
else {
printf("%d is not a leap year.", year);
}
return 0;
}
14. Find out the sum of odd numbers upto a given
range.
#include <stdio.h>
int main()
{
int i, n, sum=0;
/* Input range to find sum of odd numbers */
printf("Enter upper limit: ");
scanf("%d", &n);
/* Find the sum of all odd number */
for(i=1; i<=n; i+=2)
{
sum += i;
}
printf("Sum of odd numbers = %d", sum);
return 0;
}
15. Write a program to print the series 0,1,3,6,10 upto
N
#include<stdio.h>
int main()
{
int i,j=1,k=1,n;
printf("nEnter number of terms:");
scanf("%d",&n);
printf("n");
printf(“%dt”,0);
for(i=0;i<n;i++)
{
printf("%dt",k);
j=j+1;
k=k+j;
}
return 0;
}
16. Find factorial of a user given number
#include <stdio.h>
int main()
{
int c, n, f = 1;
printf("Enter a number to calculate its factorial:");
scanf("%d", &n);
for (c = 1; c <= n; c++)
f = f * c;
printf("Factorial of %d = %dn", n, f);
return 0;
}
PATTERN:
17. Write a program to generate a pyramid pattern.
#include <stdio.h>
int main() {
int i, space, rows, k = 0;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i, k = 0) {
for (space = 1; space <= rows - i; ++space)
{printf(" ");
}
while (k != 2 * i - 1) {
printf("* ");
++k;
}
printf("n");
}
return 0;
}
18. Write a program to generate a ring angle like
pattern with numbers.
#include <stdio.h>
int main() {
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i)
{for (j = 1; j <= i; ++j) {
printf("%d ", j);
}
printf("n");
}
return 0;
}
FUNCTION:
19. Create a user defined function addition() to add
two user input numbers.
#include<stdio.h>
int main() {
int num1, num2, res;
printf("nEnter the two numbers : ");
scanf("%d %d", &num1, &num2);
//Call Function Sum With Two Parameters
res = addition(num1, num2);
printf("nAddition of two number is : %d",res);
return (0);
}
int addition(int num1, int num2)
{int num3;
num3 = num1 + num2;
return (num3);
}
20. Find maximum of two numbers entered by user
using function.
#include <stdio.h>
int max(int num1, int num2);
int main()
{
int num1, num2, maximum;
printf("Enter any two numbers: ");
scanf("%d%d", &num1, &num2);
maximum = max(num1, num2);
printf("nMaximum = %dn", maximum);
return 0;
}
int max(int num1, int num2)
{
return (num1 > num2 ) ? num1 : num2;
}
21. Find out average of two numbers using function.
#include <stdio.h>
float average(int x, int
y){return (float)(x + y)/2;
}
int main(){
int number1, number2;
float avg;
printf("Enter the first number: ");
scanf("%d",&number1);
printf("Enter the second number: ");
scanf("%d",&number2);
avg = average(number1, number2);
printf("The Average of %d and %d
is: %.2f",number1,number2,avg);
return 0;
}
ARRAY:
22. Write a program to store elements in an array and
print.
#include <stdio.h>
void main()
{
int arr[10];
int i;
printf("nnRead and Print elements of an array:n");
printf(" n");
printf("Input 10 elements in the array :n");
for(i=0; i<10; i++)
{
printf("element - %d : ",i);
scanf("%d", &arr[i]);
}
printf("nElements in array are: ");
for(i=0; i<10; i++)
{
printf("%d ", arr[i]);
}
printf("n");
}
23. Store elements upto n in an array and show in
reversed order.
#include <stdio.h>
#define MAX_SIZE 100
int main()
{
int arr[MAX_SIZE];
int size, i;
printf("Enter size of the array: ");
scanf("%d", &size);
printf("Enter elements in array: ");
for(i=0; i<size; i++)
{
scanf("%d", &arr[i]);
}
printf("nArray in reverse order: ");
for(i = size-1; i>=0; i--)
{
printf("%dt", arr[i]);
}
return 0;
}
24. Find the sum of all elements in an array.
#include <stdio.h>
void main()
{
int a[100];
int i, n, sum=0;
printf("nnFind sum of all elements of array:n");
printf(" n");
printf("Input the number of elements to be stored in the
array :");
scanf("%d",&n);
printf("Input %d elements in the array :n",n);
for(i=0;i<n;i++)
{
printf("element - %d : ",i);
scanf("%d",&a[i]);
}
for(i=0; i<n; i++)
{
sum += a[i];
}
printf("Sum of all elements stored in the array is : %dnn",
sum);
}
25. Find out the smallest element in an array.
#include <stdio.h>
int main()
{
int arr[] = {25, 11, 7, 75, 56};
int length = sizeof(arr)/sizeof(arr[0]);
int min = arr[0];
for (int i = 0; i < length; i++) {
//Compare elements of array with min
if(arr[i] < min)
min = arr[i];
}
printf("Smallest element present in given array: %dn", min);
return 0;
}
Thank You….. :)
Sincerely…
Arghodeep Paul

More Related Content

What's hot

B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
Prasadu Peddi
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
RAJWANT KAUR
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
Leandro Schenone
 
C programs
C programsC programs
C programs
Minu S
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
Sazzad Hossain, ITP, MBA, CSCA™
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
Rahul Pandit
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
Sowri Rajan
 
C Programming
C ProgrammingC Programming
C Programming
Sumant Diwakar
 
programs
programsprograms
programs
Vishnu V
 
Progr3
Progr3Progr3
Progr3
SANTOSH RATH
 
The solution manual of c by robin
The solution manual of c by robinThe solution manual of c by robin
The solution manual of c by robin
Abdullah Al Naser
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
manoj11manu
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
yogini sharma
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
DR B.Surendiran .
 
C basics
C basicsC basics
C basics
MSc CST
 
c-programming-using-pointers
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointers
Sushil Mishra
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
Lakshmi Sarvani Videla
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
argusacademy
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
sandeep kumbhkar
 

What's hot (20)

B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
C programs
C programsC programs
C programs
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
C Programming
C ProgrammingC Programming
C Programming
 
programs
programsprograms
programs
 
Progr3
Progr3Progr3
Progr3
 
The solution manual of c by robin
The solution manual of c by robinThe solution manual of c by robin
The solution manual of c by robin
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
C basics
C basicsC basics
C basics
 
c-programming-using-pointers
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointers
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 

Similar to Common problems solving using c

PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
Ashutoshprasad27
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
Ashutoshprasad27
 
C file
C fileC file
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
C Language Programs
C Language Programs C Language Programs
C Language Programs
Mansi Tyagi
 
C lab
C labC lab
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
Vishal Singh
 
C programming
C programmingC programming
C programming
Samsil Arefin
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
Zaibi Gondal
 
Cpds lab
Cpds labCpds lab
Programming egs
Programming egs Programming egs
Programming egs
Dr.Subha Krishna
 
C programs
C programsC programs
C programs
Vikram Nandini
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
Ashishchinu
 
Najmul
Najmul  Najmul
Najmul
Najmul Ashik
 
Progr2
Progr2Progr2
Progr2
SANTOSH RATH
 
Array Programs.pdf
Array Programs.pdfArray Programs.pdf
Array Programs.pdf
RajKamal557276
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
DebiPanda
 
C
CC
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
Wingston
 
Hargun
HargunHargun

Similar to Common problems solving using c (20)

PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
 
C file
C fileC file
C file
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
C Language Programs
C Language Programs C Language Programs
C Language Programs
 
C lab
C labC lab
C lab
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
C programming
C programmingC programming
C programming
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Programming egs
Programming egs Programming egs
Programming egs
 
C programs
C programsC programs
C programs
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
Najmul
Najmul  Najmul
Najmul
 
Progr2
Progr2Progr2
Progr2
 
Array Programs.pdf
Array Programs.pdfArray Programs.pdf
Array Programs.pdf
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
C
CC
C
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Hargun
HargunHargun
Hargun
 

More from ArghodeepPaul

Microprocessor questions converted
Microprocessor questions convertedMicroprocessor questions converted
Microprocessor questions converted
ArghodeepPaul
 
Windows script host
Windows script hostWindows script host
Windows script host
ArghodeepPaul
 
Windows batch scripting
Windows batch scriptingWindows batch scripting
Windows batch scripting
ArghodeepPaul
 
C operators
C operatorsC operators
C operators
ArghodeepPaul
 
C taking user input
C taking user inputC taking user input
C taking user input
ArghodeepPaul
 
C storage classes
C storage classesC storage classes
C storage classes
ArghodeepPaul
 
C datatypes
C datatypesC datatypes
C datatypes
ArghodeepPaul
 
C variables and constants
C variables and constantsC variables and constants
C variables and constants
ArghodeepPaul
 
C program structure
C program structureC program structure
C program structure
ArghodeepPaul
 
Computer programming tools and building process
Computer programming tools and building processComputer programming tools and building process
Computer programming tools and building process
ArghodeepPaul
 
Algorithm pseudocode flowchart program notes
Algorithm pseudocode flowchart program notesAlgorithm pseudocode flowchart program notes
Algorithm pseudocode flowchart program notes
ArghodeepPaul
 
notes on Programming fundamentals
notes on Programming fundamentals notes on Programming fundamentals
notes on Programming fundamentals
ArghodeepPaul
 

More from ArghodeepPaul (12)

Microprocessor questions converted
Microprocessor questions convertedMicroprocessor questions converted
Microprocessor questions converted
 
Windows script host
Windows script hostWindows script host
Windows script host
 
Windows batch scripting
Windows batch scriptingWindows batch scripting
Windows batch scripting
 
C operators
C operatorsC operators
C operators
 
C taking user input
C taking user inputC taking user input
C taking user input
 
C storage classes
C storage classesC storage classes
C storage classes
 
C datatypes
C datatypesC datatypes
C datatypes
 
C variables and constants
C variables and constantsC variables and constants
C variables and constants
 
C program structure
C program structureC program structure
C program structure
 
Computer programming tools and building process
Computer programming tools and building processComputer programming tools and building process
Computer programming tools and building process
 
Algorithm pseudocode flowchart program notes
Algorithm pseudocode flowchart program notesAlgorithm pseudocode flowchart program notes
Algorithm pseudocode flowchart program notes
 
notes on Programming fundamentals
notes on Programming fundamentals notes on Programming fundamentals
notes on Programming fundamentals
 

Recently uploaded

Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Self-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptxSelf-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptx
iemerc2024
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
obonagu
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Adaptive synchronous sliding control for a robot manipulator based on neural ...
Adaptive synchronous sliding control for a robot manipulator based on neural ...Adaptive synchronous sliding control for a robot manipulator based on neural ...
Adaptive synchronous sliding control for a robot manipulator based on neural ...
IJECEIAES
 

Recently uploaded (20)

Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Self-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptxSelf-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptx
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Adaptive synchronous sliding control for a robot manipulator based on neural ...
Adaptive synchronous sliding control for a robot manipulator based on neural ...Adaptive synchronous sliding control for a robot manipulator based on neural ...
Adaptive synchronous sliding control for a robot manipulator based on neural ...
 

Common problems solving using c

  • 1. Common Problems Solving using C Language Instructor: Arghodeep Paul Firmware Engineer at BitBible Technologies Pvt. Ltd. Content Author: Arghodeep Paul License: OpenSource Date: 01 August 2021
  • 2. IF ELSE: 1. Check whether the user entered number is positive. #include<stdio.h> int main(){ int number; printf("Enter a number:"); scanf("%d",&number); if(number>0){ printf("%d is a positive number!",number); } else{ printf("%d is a negative number",number); } return 0; }
  • 3. 2. Write a program to check whether a number is even or odd. #include<stdio.h> int main(){ int num; printf("Enter a number:"); scanf("%d",&num); if(num%2==0){ printf("%d is an even number!",num); } else{ printf("%d is an odd number",num); } return 0; }
  • 4. FOR LOOP: 3. Write a program to display first 10 natural numbers #include <stdio.h> int main() { int i; printf("The first 10 natural numbers are:n"); for (i=1;i<=10;i++) { printf("%d ",i); } printf("n"); return 0; }
  • 5. 4. Write a program to find biggest among two numbers. #include<stdio.h> int main() { int n1,n2,sum; printf("nEnter 1st number : "); scanf("%d",&n1); printf("nEnter 2nd number : "); scanf("%d",&n2); if(n1 > n2) printf("n1st number is greatest."); else printf("n2nd number is greatest."); return 0; }
  • 6. WHILE LOOP: 5. Write a program to display natural numbers upto a given range. #include <stdio.h> int main() { int num,i; printf("Enter a number : "); scanf("%d", &num); i = 0; while (i <= num) { printf("n%d",i); i++; }
  • 7. return 0; } 6. Write a program to display sum of first 5 natural number. #include <stdio.h> int main() { int num, i, sum = 0; printf("Enter a positive number : "); scanf("%d", &num); i = 0; while (i <= num) { sum = sum + i; i++;
  • 8. } printf(" n Sum of first %d natural number is : %d", num, sum); return 0; } 7. Write a program to generate the following series 1 4 9 16 …. 100 #include<stdio.h> int main() { int i; for(i=1;i<=10;i++) { printf("n%d",i*i); } return 0; }
  • 9. 8. Write a program to find out sum of first 10 natural numbers int main() { int i, sum = 0; i = 0; while (i <= 10) { sum = sum + i; i++; } printf(" n Sum of first 10 natural number is : %d", sum);
  • 10. return 0; } 9. Write a program to read 10 numbers and find their sum and average #include <stdio.h> int main() { int i,n,sum=0; float avg; printf("Input the 10 numbers : n"); for (i=1;i<=10;i++) { printf("Number-%d :",i); scanf("%d",&n); sum +=n; } avg=sum/10.0; printf("The sum of 10 no is : %dnThe Average is : %fn",sum,avg); return 0;
  • 11. } 10. Find cube of the number upto a given integer #include <stdio.h> int main() { int i,ctr; printf("Input number of terms : "); scanf("%d", &ctr); for(i=1;i<=ctr;i++) { printf("Number is : %d and cube of the %d is :%d n",i,i, (i*i*i));
  • 12. } return 0; } 11. Compute multiplication table of a given integer #include <stdio.h> int main() { int j,n; printf("Input the number (Table to be calculated) : "); scanf("%d",&n); printf("nn"); for(j=1;j<=10;j++) { printf("%d X %d = %d n",n,j,n*j); } return 9; }
  • 13. 12. Display n number of multiplication table vertically #include <stdio.h> int main() { int j,i,n; printf("Input upto the table number starting from 1 : "); scanf("%d",&n); printf("Multiplication table from 1 to %d n",n); for(i=1;i<=10;i++) { for(j=1;j<=n;j++) { if (j<=n-1) printf("%dx%d = %d, ",j,i,i*j); else
  • 14. printf("%dx%d = %d",j,i,i*j); } printf("n"); } return 0; } 13. Check whether the entered year is leap year or not. #include <stdio.h> int main() { int year; printf("Enter a year: "); scanf("%d", &year);
  • 15. // leap year if perfectly divisible by 400 if (year % 400 == 0) { printf("%d is a leap year.", year); } // not a leap year if divisible by 100 // but not divisible by 400 else if (year % 100 == 0) { printf("%d is not a leap year.", year); } // leap year if not divisible by 100 // but divisible by 4 else if (year % 4 == 0) { printf("%d is a leap year.", year); } // all other years are not leap years else { printf("%d is not a leap year.", year); } return 0; }
  • 16. 14. Find out the sum of odd numbers upto a given range. #include <stdio.h> int main() { int i, n, sum=0; /* Input range to find sum of odd numbers */ printf("Enter upper limit: "); scanf("%d", &n); /* Find the sum of all odd number */ for(i=1; i<=n; i+=2) { sum += i; } printf("Sum of odd numbers = %d", sum); return 0; }
  • 17. 15. Write a program to print the series 0,1,3,6,10 upto N #include<stdio.h> int main() { int i,j=1,k=1,n; printf("nEnter number of terms:"); scanf("%d",&n); printf("n"); printf(“%dt”,0); for(i=0;i<n;i++) { printf("%dt",k); j=j+1; k=k+j; } return 0; }
  • 18. 16. Find factorial of a user given number #include <stdio.h> int main() { int c, n, f = 1; printf("Enter a number to calculate its factorial:"); scanf("%d", &n); for (c = 1; c <= n; c++) f = f * c; printf("Factorial of %d = %dn", n, f); return 0; }
  • 19. PATTERN: 17. Write a program to generate a pyramid pattern. #include <stdio.h> int main() { int i, space, rows, k = 0; printf("Enter the number of rows: "); scanf("%d", &rows); for (i = 1; i <= rows; ++i, k = 0) { for (space = 1; space <= rows - i; ++space) {printf(" "); } while (k != 2 * i - 1) { printf("* "); ++k; } printf("n"); } return 0; }
  • 20. 18. Write a program to generate a ring angle like pattern with numbers. #include <stdio.h> int main() { int i, j, rows; printf("Enter the number of rows: "); scanf("%d", &rows); for (i = 1; i <= rows; ++i) {for (j = 1; j <= i; ++j) { printf("%d ", j); } printf("n"); } return 0; }
  • 21. FUNCTION: 19. Create a user defined function addition() to add two user input numbers. #include<stdio.h> int main() { int num1, num2, res; printf("nEnter the two numbers : "); scanf("%d %d", &num1, &num2); //Call Function Sum With Two Parameters res = addition(num1, num2); printf("nAddition of two number is : %d",res); return (0); }
  • 22. int addition(int num1, int num2) {int num3; num3 = num1 + num2; return (num3); } 20. Find maximum of two numbers entered by user using function. #include <stdio.h> int max(int num1, int num2); int main() { int num1, num2, maximum; printf("Enter any two numbers: "); scanf("%d%d", &num1, &num2); maximum = max(num1, num2); printf("nMaximum = %dn", maximum); return 0; } int max(int num1, int num2)
  • 23. { return (num1 > num2 ) ? num1 : num2; } 21. Find out average of two numbers using function. #include <stdio.h> float average(int x, int y){return (float)(x + y)/2; } int main(){ int number1, number2; float avg; printf("Enter the first number: "); scanf("%d",&number1); printf("Enter the second number: "); scanf("%d",&number2); avg = average(number1, number2); printf("The Average of %d and %d is: %.2f",number1,number2,avg); return 0; }
  • 24. ARRAY: 22. Write a program to store elements in an array and print. #include <stdio.h> void main() { int arr[10]; int i; printf("nnRead and Print elements of an array:n"); printf(" n"); printf("Input 10 elements in the array :n"); for(i=0; i<10; i++) { printf("element - %d : ",i); scanf("%d", &arr[i]); }
  • 25. printf("nElements in array are: "); for(i=0; i<10; i++) { printf("%d ", arr[i]); } printf("n"); }
  • 26. 23. Store elements upto n in an array and show in reversed order. #include <stdio.h> #define MAX_SIZE 100 int main() { int arr[MAX_SIZE]; int size, i; printf("Enter size of the array: "); scanf("%d", &size); printf("Enter elements in array: "); for(i=0; i<size; i++) { scanf("%d", &arr[i]); } printf("nArray in reverse order: "); for(i = size-1; i>=0; i--) { printf("%dt", arr[i]); } return 0; }
  • 27. 24. Find the sum of all elements in an array. #include <stdio.h> void main() { int a[100]; int i, n, sum=0; printf("nnFind sum of all elements of array:n"); printf(" n"); printf("Input the number of elements to be stored in the array :"); scanf("%d",&n); printf("Input %d elements in the array :n",n);
  • 28. for(i=0;i<n;i++) { printf("element - %d : ",i); scanf("%d",&a[i]); } for(i=0; i<n; i++) { sum += a[i]; } printf("Sum of all elements stored in the array is : %dnn", sum); }
  • 29. 25. Find out the smallest element in an array. #include <stdio.h> int main() { int arr[] = {25, 11, 7, 75, 56}; int length = sizeof(arr)/sizeof(arr[0]); int min = arr[0]; for (int i = 0; i < length; i++) { //Compare elements of array with min if(arr[i] < min) min = arr[i]; } printf("Smallest element present in given array: %dn", min); return 0; }