SlideShare uma empresa Scribd logo
1 de 6
Baixar para ler offline
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:

Mais conteúdo relacionado

Mais procurados

Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File Harjinder Singh
 
INDIAN SPACE RESEARCH ORGANIZATION (ISRO)
INDIAN SPACE RESEARCH ORGANIZATION (ISRO)INDIAN SPACE RESEARCH ORGANIZATION (ISRO)
INDIAN SPACE RESEARCH ORGANIZATION (ISRO)udit dixit
 
Python program For O level Practical
Python program For O level Practical Python program For O level Practical
Python program For O level Practical pavitrakumar18
 
Space Quiz (Prelims) - VIT Vellore by DBQC
Space Quiz (Prelims) - VIT Vellore by DBQCSpace Quiz (Prelims) - VIT Vellore by DBQC
Space Quiz (Prelims) - VIT Vellore by DBQCUjjwal Nath
 
Horizons (Finals) - Astronomy Quiz - IIITDMJ2018
Horizons (Finals) - Astronomy Quiz - IIITDMJ2018Horizons (Finals) - Astronomy Quiz - IIITDMJ2018
Horizons (Finals) - Astronomy Quiz - IIITDMJ2018Arnav Deep
 
Xi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsXi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsProf. Dr. K. Adisesha
 
10 mysterious places in the world
10 mysterious places in the world10 mysterious places in the world
10 mysterious places in the worlddipali mishra
 
Space Quiz (Finals) - VIT Vellore by DBQC
Space Quiz (Finals) - VIT Vellore by DBQCSpace Quiz (Finals) - VIT Vellore by DBQC
Space Quiz (Finals) - VIT Vellore by DBQCUjjwal Nath
 
Pattern printing-in-c(Jaydip Kikani)
Pattern printing-in-c(Jaydip Kikani)Pattern printing-in-c(Jaydip Kikani)
Pattern printing-in-c(Jaydip Kikani)Jaydip JK
 
Weird - General Quiz
Weird - General QuizWeird - General Quiz
Weird - General QuizArjun Rafale
 
Python matplotlib cheat_sheet
Python matplotlib cheat_sheetPython matplotlib cheat_sheet
Python matplotlib cheat_sheetNishant Upadhyay
 
ISRO (Indian Space Research Organization)
ISRO (Indian Space Research Organization)ISRO (Indian Space Research Organization)
ISRO (Indian Space Research Organization)Srikanth Gelli
 
IT Quiz Final @ eRz eRDeN 15, IT Fest, ITM Mayyil
IT Quiz Final @ eRz eRDeN 15, IT Fest, ITM MayyilIT Quiz Final @ eRz eRDeN 15, IT Fest, ITM Mayyil
IT Quiz Final @ eRz eRDeN 15, IT Fest, ITM MayyilShyju Chathampalli
 

Mais procurados (20)

Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
INDIAN SPACE RESEARCH ORGANIZATION (ISRO)
INDIAN SPACE RESEARCH ORGANIZATION (ISRO)INDIAN SPACE RESEARCH ORGANIZATION (ISRO)
INDIAN SPACE RESEARCH ORGANIZATION (ISRO)
 
Python program For O level Practical
Python program For O level Practical Python program For O level Practical
Python program For O level Practical
 
NumPy
NumPyNumPy
NumPy
 
Space Quiz (Prelims) - VIT Vellore by DBQC
Space Quiz (Prelims) - VIT Vellore by DBQCSpace Quiz (Prelims) - VIT Vellore by DBQC
Space Quiz (Prelims) - VIT Vellore by DBQC
 
Horizons (Finals) - Astronomy Quiz - IIITDMJ2018
Horizons (Finals) - Astronomy Quiz - IIITDMJ2018Horizons (Finals) - Astronomy Quiz - IIITDMJ2018
Horizons (Finals) - Astronomy Quiz - IIITDMJ2018
 
Xi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsXi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programs
 
Program Design
Program DesignProgram Design
Program Design
 
10 mysterious places in the world
10 mysterious places in the world10 mysterious places in the world
10 mysterious places in the world
 
Space Quiz (Finals) - VIT Vellore by DBQC
Space Quiz (Finals) - VIT Vellore by DBQCSpace Quiz (Finals) - VIT Vellore by DBQC
Space Quiz (Finals) - VIT Vellore by DBQC
 
Arrays
ArraysArrays
Arrays
 
APJ ABDUL KALAM
APJ ABDUL KALAM APJ ABDUL KALAM
APJ ABDUL KALAM
 
Ds lab handouts
Ds lab handoutsDs lab handouts
Ds lab handouts
 
Pattern printing-in-c(Jaydip Kikani)
Pattern printing-in-c(Jaydip Kikani)Pattern printing-in-c(Jaydip Kikani)
Pattern printing-in-c(Jaydip Kikani)
 
C++ file
C++ fileC++ file
C++ file
 
Weird - General Quiz
Weird - General QuizWeird - General Quiz
Weird - General Quiz
 
C program to implement linked list using array abstract data type
C program to implement linked list using array abstract data typeC program to implement linked list using array abstract data type
C program to implement linked list using array abstract data type
 
Python matplotlib cheat_sheet
Python matplotlib cheat_sheetPython matplotlib cheat_sheet
Python matplotlib cheat_sheet
 
ISRO (Indian Space Research Organization)
ISRO (Indian Space Research Organization)ISRO (Indian Space Research Organization)
ISRO (Indian Space Research Organization)
 
IT Quiz Final @ eRz eRDeN 15, IT Fest, ITM Mayyil
IT Quiz Final @ eRz eRDeN 15, IT Fest, ITM MayyilIT Quiz Final @ eRz eRDeN 15, IT Fest, ITM Mayyil
IT Quiz Final @ eRz eRDeN 15, IT Fest, ITM Mayyil
 

Semelhante a C Programming Example

Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solutionAzhar Javed
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)Ashishchinu
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkarsandeep kumbhkar
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programsPrasadu Peddi
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentalsZaibi Gondal
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab PracticeMahmud Hasan Tanvir
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given numberMainak Sasmal
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given numberMainak Sasmal
 
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.pdfAshutoshprasad27
 
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.docxAshutoshprasad27
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
 
Core programming in c
Core programming in cCore programming in c
Core programming in cRahul Pandit
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2Koshy Geoji
 
C basics
C basicsC basics
C basicsMSc CST
 

Semelhante a C Programming Example (20)

Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
C Programming
C ProgrammingC Programming
C Programming
 
C lab
C labC lab
C lab
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
C file
C fileC file
C file
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
C
CC
C
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
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
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
C basics
C basicsC basics
C basics
 

Mais de PRATHAMESH DESHPANDE (12)

Boiler welding
Boiler weldingBoiler welding
Boiler welding
 
To join the sheet metal for boiler
To join the sheet metal for boilerTo join the sheet metal for boiler
To join the sheet metal for boiler
 
How Helicopter work
How Helicopter workHow Helicopter work
How Helicopter work
 
Gear shifter
Gear shifterGear shifter
Gear shifter
 
Honing, Lapping & Electroplating
Honing, Lapping & ElectroplatingHoning, Lapping & Electroplating
Honing, Lapping & Electroplating
 
DYNAMIC FORCE ANALYSIS BEST PPT
DYNAMIC FORCE ANALYSIS BEST PPT DYNAMIC FORCE ANALYSIS BEST PPT
DYNAMIC FORCE ANALYSIS BEST PPT
 
Energy transfer by work
Energy transfer by workEnergy transfer by work
Energy transfer by work
 
Types of fluid flow best ppt
Types of fluid flow best pptTypes of fluid flow best ppt
Types of fluid flow best ppt
 
Lifi technology
Lifi technologyLifi technology
Lifi technology
 
Polarization of Light
Polarization of LightPolarization of Light
Polarization of Light
 
External gear & its application
External gear & its applicationExternal gear & its application
External gear & its application
 
Types of fluid flow
Types of fluid flowTypes of fluid flow
Types of fluid flow
 

Último

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Último (20)

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

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: