SlideShare a Scribd company logo
2
Most read
3
Most read
6
Most read
Prathamesh Deshpande
G-(04)
Q.1 Write a program to print the following pattern
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
C programming code:
#include<stdio.h>
int main()
{
int i,j;
char input,temp='1';
printf("Enter number you want in triangle at last row: ");
scanf("%c",&input);
for(i=1;i<=(input-'1'+1);++i)
{
for(j=1;j<=i;++j)
printf("%c",temp);
++temp;
printf("n");
}
return 0;
}
Output:
Q.2 Write a program to find bigger of three integers.
C programming code:
#include <stdio.h>
int main()
{
int array[100], maximum, size, c, location = 1;
printf("Enter the number of elements in arrayn");
scanf("%d", &size);
printf("Enter %d integersn", size);
for (c = 0; c < size; c++)
scanf("%d", &array[c]);
maximum = array[0];
for (c = 1; c < size; c++)
{
if (array[c] > maximum)
{
maximum = array[c];
location = c+1;
}
}
printf("Maximum element is present at location %d and it's value is
%d.n", location, maximum);
return 0;
}
Output:
Q.3 Write a program to calculate GCD between two numbers.
C programming code:
#include <stdio.h>
int gcd(int n1, int n2);
int main()
{
int n1, n2;
printf("Enter two positive integers: ");
scanf("%d%d", &n1, &n2);
printf("GCD of %d and %d = %d", n1, n2, gcd(n1,n2));
return 0;
}
int gcd(int n1, int n2)
{
if (n2!=0)
return gcd(n2, n1%n2);
else
return n1;
}
Output:
Q.4 Write a program to find transpose of matrix.
C programming code:
#include <stdio.h>
int main()
{
int m, n, c, d, matrix[10][10], transpose[10][10];
printf("Enter the number of rows and columns of matrixn");
scanf("%d%d", &m, &n);
printf("Enter the elements of matrixn");
for (c = 0; c < m; c++)
for(d = 0; d < n; d++)
scanf("%d",&matrix[c][d]);
for (c = 0; c < m; c++)
for( d = 0 ; d < n ; d++ )
transpose[d][c] = matrix[c][d];
printf("Transpose of entered matrix :-n");
for (c = 0; c < n; c++) {
for (d = 0; d < m; d++)
printf("%dt",transpose[c][d]);
printf("n");
}
return 0;
}
Output:
Q.5 Write a program which deletes an element from an array & display all other elements.
C programming code:
#include <stdio.h>
int main()
{
int array[100], position, c, n;
printf("Enter number of elements in arrayn");
scanf("%d", &n);
printf("Enter %d elementsn", n);
for ( c = 0 ; c < n ; c++ )
scanf("%d", &array[c]);
printf("Enter the location where you wish to delete elementn");
scanf("%d", &position);
if ( position >= n+1 )
printf("Deletion not possible.n");
else
{ for ( c = position - 1 ; c < n - 1 ; c++ )
array[c] = array[c+1];
printf("Resultant array isn");
for( c = 0 ; c < n - 1 ; c++ )
printf("%dn", array[c]);
}
return 0;
}
Output:
Q.6 Write a program to calculate XA+YB where A & B are matrix & X=2, Y=3.
C programming code:
#include <stdio.h>
int main()
{
int m, n, c, d, first[10][10], second[10][10], sum[10][10];
printf("Enter the number of rows and columns of matrixn");
scanf("%d%d", &m, &n);
printf("Enter the elements of first matrixn");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
scanf("%d", &first[c][d]);
printf("Enter the elements of second matrixn");
for (c = 0; c < m; c++)
for (d = 0 ; d < n; d++)
scanf("%d", &second[c][d]);
printf("Sum of entered matrices:-n");
for (c = 0; c < m; c++)
{ for (d = 0 ; d < n; d++)
{ sum[c][d] = (2*(first[c][d]))+(3*(second[c][d]));
printf("%dt", sum[c][d]);
}
printf("n");
} return 0;
}
Output:
Q.7 Write a program to calculate the total amount of money in the piggybank, given that coins of
Rs.10,
Rs.5, Rs.2, RS.1.
C programming code:
#include<stdio.h>
int main()
{
int a, b, c, d, e;
printf("Enter no. coins of Rs10 Rs5 Rs2 Rs1 n");
scanf("%d%d%d%d",&a,&b,&c,&d);
e = (10*a)+(5*b)+(2*c)+d;
printf("Sum of money in piggybank = %dn",e);
return 0;
}
Output:
Q.8 Write a program to calculate sum of squares of first n even no.
C programming code:
#include<stdio.h>
int main()
{
int i, j, sum = 0, n;
printf("Enter no of terms");
scanf("%d",&n);
printf("nEven numbers and their square:n");
for(i =1; i <=n; i++)
{ if(i % 2 == 0)
{ j = i * i;
printf("%dtt%d",i,j);
printf("n");
sum = sum + j;
}
}
printf("nnSum of even numbers square is: %d",sum);
return 0;
}
Output:
Q.9 Write a program to calculate exp(X,Y) using recursive functions.
C programming code:
#include <stdio.h>
long power (int, int);
int main()
{
int Y, X;
long result;
printf("Enter a number X : ");
scanf("%d", &X);
printf("Enter it's power Y : ");
scanf("%d", &Y);
result = power(X, Y);
printf("%d^%d is %ld", X, Y, result);
return 0;
}
long power (int X, int Y)
{
if (Y)
{
return (X * power(X, Y - 1));
}
return 1;
}
Output:
Q.10 Write a program to enter a number from 1 to 7 & display it’s corresponding day of week using
Switch - case statement.
C programming code:
#include <stdio.h>
int main()
{
int week;
printf("Enter day of week to get it's corresponding day (1-7): ");
scanf("%d", &week);
switch(week)
{
case 1: printf("MONDAY");
break;
case 2: printf("TUESDAY");
break;
case 3: printf("WEDNESDAY");
break;
case 4: printf("THURSDAY");
break;
case 5: printf("FRIDAY");
break;
case 6: printf("SATURDAY");
break;
case 7: printf("SUNDAY");
break;
default: printf("Invalid input! Please enter week number
between 1-7");
}
return 0;
}
Output:

More Related Content

What's hot (20)

PPTX
C if else
Ritwik Das
 
PPTX
Presentation on Function in C Programming
Shuvongkor Barman
 
PPTX
convex hull
ravikirankalal
 
PPTX
Functions in C
Kamal Acharya
 
PPTX
Tower Of Hanoi
Vinit Dantkale
 
PPTX
Introduction Of C++
Sangharsh agarwal
 
PPTX
19. Data Structures and Algorithm Complexity
Intro C# Book
 
PPTX
Structure in C
Kamal Acharya
 
PPT
Constants in C Programming
programming9
 
PPTX
File in C language
Manash Kumar Mondal
 
PPTX
Loops in C Programming Language
Mahantesh Devoor
 
PDF
Function overloading ppt
Prof. Dr. K. Adisesha
 
PDF
file handling c++
Guddu Spy
 
PDF
Let us c chapter 4 solution
rohit kumar
 
PDF
Chapter 3 : Balagurusamy Programming ANSI in C
BUBT
 
PPT
Python ppt
Rohit Verma
 
PPTX
C function
thirumalaikumar3
 
PPTX
UNIT II DBMS.pptx
NIVETHA37590
 
PPTX
Dijkstra's Algorithm
Rashik Ishrak Nahian
 
C if else
Ritwik Das
 
Presentation on Function in C Programming
Shuvongkor Barman
 
convex hull
ravikirankalal
 
Functions in C
Kamal Acharya
 
Tower Of Hanoi
Vinit Dantkale
 
Introduction Of C++
Sangharsh agarwal
 
19. Data Structures and Algorithm Complexity
Intro C# Book
 
Structure in C
Kamal Acharya
 
Constants in C Programming
programming9
 
File in C language
Manash Kumar Mondal
 
Loops in C Programming Language
Mahantesh Devoor
 
Function overloading ppt
Prof. Dr. K. Adisesha
 
file handling c++
Guddu Spy
 
Let us c chapter 4 solution
rohit kumar
 
Chapter 3 : Balagurusamy Programming ANSI in C
BUBT
 
Python ppt
Rohit Verma
 
C function
thirumalaikumar3
 
UNIT II DBMS.pptx
NIVETHA37590
 
Dijkstra's Algorithm
Rashik Ishrak Nahian
 

Similar to C Programming Example (20)

PDF
Common problems solving using c
ArghodeepPaul
 
DOC
C-programs
SSGMCE SHEGAON
 
PDF
C- Programming Assignment practice set 2 solutions
Animesh Chaturvedi
 
PDF
Basic C Programming Lab Practice
Mahmud Hasan Tanvir
 
DOCX
Fuzail_File_C.docx
SyedFuzail14
 
PDF
PCA-2 Programming and Solving 2nd Sem.pdf
Ashutoshprasad27
 
DOCX
PCA-2 Programming and Solving 2nd Sem.docx
Ashutoshprasad27
 
DOCX
C file
simarsimmygrewal
 
PPTX
C programming
Samsil Arefin
 
PDF
C Programming lab
Vikram Nandini
 
PDF
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu
 
PDF
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu
 
PDF
sodapdf-converted into ppt presentation(1).pdf
MuhammadMaazShaik
 
PDF
C and Data Structures Lab Solutions
Srinivas Reddy Amedapu
 
PDF
C lab excellent
Srinivas Reddy Amedapu
 
PDF
C and Data Structures
Srinivas Reddy Amedapu
 
PDF
09 a1ec01 c programming and data structures
jntuworld
 
PDF
Mmt 001
sujatam8
 
DOC
C important questions
JYOTI RANJAN PAL
 
DOCX
Hargun
Mukund Trivedi
 
Common problems solving using c
ArghodeepPaul
 
C-programs
SSGMCE SHEGAON
 
C- Programming Assignment practice set 2 solutions
Animesh Chaturvedi
 
Basic C Programming Lab Practice
Mahmud Hasan Tanvir
 
Fuzail_File_C.docx
SyedFuzail14
 
PCA-2 Programming and Solving 2nd Sem.pdf
Ashutoshprasad27
 
PCA-2 Programming and Solving 2nd Sem.docx
Ashutoshprasad27
 
C programming
Samsil Arefin
 
C Programming lab
Vikram Nandini
 
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu
 
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu
 
sodapdf-converted into ppt presentation(1).pdf
MuhammadMaazShaik
 
C and Data Structures Lab Solutions
Srinivas Reddy Amedapu
 
C lab excellent
Srinivas Reddy Amedapu
 
C and Data Structures
Srinivas Reddy Amedapu
 
09 a1ec01 c programming and data structures
jntuworld
 
Mmt 001
sujatam8
 
C important questions
JYOTI RANJAN PAL
 
Ad

More from PRATHAMESH DESHPANDE (12)

PPTX
Boiler welding
PRATHAMESH DESHPANDE
 
PDF
To join the sheet metal for boiler
PRATHAMESH DESHPANDE
 
DOCX
How Helicopter work
PRATHAMESH DESHPANDE
 
PPTX
Gear shifter
PRATHAMESH DESHPANDE
 
PPTX
Honing, Lapping & Electroplating
PRATHAMESH DESHPANDE
 
PPTX
DYNAMIC FORCE ANALYSIS BEST PPT
PRATHAMESH DESHPANDE
 
PPTX
Energy transfer by work
PRATHAMESH DESHPANDE
 
PPTX
Types of fluid flow best ppt
PRATHAMESH DESHPANDE
 
DOC
Lifi technology
PRATHAMESH DESHPANDE
 
PPTX
Polarization of Light
PRATHAMESH DESHPANDE
 
PPTX
External gear & its application
PRATHAMESH DESHPANDE
 
PDF
Types of fluid flow
PRATHAMESH DESHPANDE
 
Boiler welding
PRATHAMESH DESHPANDE
 
To join the sheet metal for boiler
PRATHAMESH DESHPANDE
 
How Helicopter work
PRATHAMESH DESHPANDE
 
Gear shifter
PRATHAMESH DESHPANDE
 
Honing, Lapping & Electroplating
PRATHAMESH DESHPANDE
 
DYNAMIC FORCE ANALYSIS BEST PPT
PRATHAMESH DESHPANDE
 
Energy transfer by work
PRATHAMESH DESHPANDE
 
Types of fluid flow best ppt
PRATHAMESH DESHPANDE
 
Lifi technology
PRATHAMESH DESHPANDE
 
Polarization of Light
PRATHAMESH DESHPANDE
 
External gear & its application
PRATHAMESH DESHPANDE
 
Types of fluid flow
PRATHAMESH DESHPANDE
 
Ad

Recently uploaded (20)

PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Horarios de distribución de agua en julio
pegazohn1978
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 

C Programming Example

  • 1. Prathamesh Deshpande G-(04) Q.1 Write a program to print the following pattern 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 C programming code: #include<stdio.h> int main() { int i,j; char input,temp='1'; printf("Enter number you want in triangle at last row: "); scanf("%c",&input); for(i=1;i<=(input-'1'+1);++i) { for(j=1;j<=i;++j) printf("%c",temp); ++temp; printf("n"); } return 0; } Output: Q.2 Write a program to find bigger of three integers. C programming code: #include <stdio.h> int main() { int array[100], maximum, size, c, location = 1; printf("Enter the number of elements in arrayn"); scanf("%d", &size); printf("Enter %d integersn", size); for (c = 0; c < size; c++) scanf("%d", &array[c]); maximum = array[0]; for (c = 1; c < size; c++) { if (array[c] > maximum) { maximum = array[c]; location = c+1; } }
  • 2. printf("Maximum element is present at location %d and it's value is %d.n", location, maximum); return 0; } Output: Q.3 Write a program to calculate GCD between two numbers. C programming code: #include <stdio.h> int gcd(int n1, int n2); int main() { int n1, n2; printf("Enter two positive integers: "); scanf("%d%d", &n1, &n2); printf("GCD of %d and %d = %d", n1, n2, gcd(n1,n2)); return 0; } int gcd(int n1, int n2) { if (n2!=0) return gcd(n2, n1%n2); else return n1; } Output: Q.4 Write a program to find transpose of matrix. C programming code: #include <stdio.h> int main() { int m, n, c, d, matrix[10][10], transpose[10][10]; printf("Enter the number of rows and columns of matrixn"); scanf("%d%d", &m, &n); printf("Enter the elements of matrixn"); for (c = 0; c < m; c++) for(d = 0; d < n; d++) scanf("%d",&matrix[c][d]); for (c = 0; c < m; c++) for( d = 0 ; d < n ; d++ ) transpose[d][c] = matrix[c][d]; printf("Transpose of entered matrix :-n"); for (c = 0; c < n; c++) { for (d = 0; d < m; d++)
  • 3. printf("%dt",transpose[c][d]); printf("n"); } return 0; } Output: Q.5 Write a program which deletes an element from an array & display all other elements. C programming code: #include <stdio.h> int main() { int array[100], position, c, n; printf("Enter number of elements in arrayn"); scanf("%d", &n); printf("Enter %d elementsn", n); for ( c = 0 ; c < n ; c++ ) scanf("%d", &array[c]); printf("Enter the location where you wish to delete elementn"); scanf("%d", &position); if ( position >= n+1 ) printf("Deletion not possible.n"); else { for ( c = position - 1 ; c < n - 1 ; c++ ) array[c] = array[c+1]; printf("Resultant array isn"); for( c = 0 ; c < n - 1 ; c++ ) printf("%dn", array[c]); } return 0; } Output:
  • 4. Q.6 Write a program to calculate XA+YB where A & B are matrix & X=2, Y=3. C programming code: #include <stdio.h> int main() { int m, n, c, d, first[10][10], second[10][10], sum[10][10]; printf("Enter the number of rows and columns of matrixn"); scanf("%d%d", &m, &n); printf("Enter the elements of first matrixn"); for (c = 0; c < m; c++) for (d = 0; d < n; d++) scanf("%d", &first[c][d]); printf("Enter the elements of second matrixn"); for (c = 0; c < m; c++) for (d = 0 ; d < n; d++) scanf("%d", &second[c][d]); printf("Sum of entered matrices:-n"); for (c = 0; c < m; c++) { for (d = 0 ; d < n; d++) { sum[c][d] = (2*(first[c][d]))+(3*(second[c][d])); printf("%dt", sum[c][d]); } printf("n"); } return 0; } Output: Q.7 Write a program to calculate the total amount of money in the piggybank, given that coins of Rs.10, Rs.5, Rs.2, RS.1. C programming code: #include<stdio.h> int main() { int a, b, c, d, e; printf("Enter no. coins of Rs10 Rs5 Rs2 Rs1 n"); scanf("%d%d%d%d",&a,&b,&c,&d); e = (10*a)+(5*b)+(2*c)+d; printf("Sum of money in piggybank = %dn",e); return 0; }
  • 5. Output: Q.8 Write a program to calculate sum of squares of first n even no. C programming code: #include<stdio.h> int main() { int i, j, sum = 0, n; printf("Enter no of terms"); scanf("%d",&n); printf("nEven numbers and their square:n"); for(i =1; i <=n; i++) { if(i % 2 == 0) { j = i * i; printf("%dtt%d",i,j); printf("n"); sum = sum + j; } } printf("nnSum of even numbers square is: %d",sum); return 0; } Output: Q.9 Write a program to calculate exp(X,Y) using recursive functions. C programming code: #include <stdio.h> long power (int, int); int main() { int Y, X; long result; printf("Enter a number X : "); scanf("%d", &X); printf("Enter it's power Y : "); scanf("%d", &Y);
  • 6. result = power(X, Y); printf("%d^%d is %ld", X, Y, result); return 0; } long power (int X, int Y) { if (Y) { return (X * power(X, Y - 1)); } return 1; } Output: Q.10 Write a program to enter a number from 1 to 7 & display it’s corresponding day of week using Switch - case statement. C programming code: #include <stdio.h> int main() { int week; printf("Enter day of week to get it's corresponding day (1-7): "); scanf("%d", &week); switch(week) { case 1: printf("MONDAY"); break; case 2: printf("TUESDAY"); break; case 3: printf("WEDNESDAY"); break; case 4: printf("THURSDAY"); break; case 5: printf("FRIDAY"); break; case 6: printf("SATURDAY"); break; case 7: printf("SUNDAY"); break; default: printf("Invalid input! Please enter week number between 1-7"); } return 0; } Output: