SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
Problems and solutions
1.1.1.1. ProgramProgramProgramProgram totototo findfindfindfind outoutoutout thethethethe temperaturetemperaturetemperaturetemperature inininin FahrenheitFahrenheitFahrenheitFahrenheit
#include <stdio.h>
void main()
{
float c, f;
printf("nEnter temperature in degree Centigrade: ");
scanf("%f", &c);
f = (1.8*c) + 32;
printf("n Temperature in degree Fahrenheit: %.2f", f);
getchar();
}
2.2.2.2.ProgramProgramProgramProgram totototo findfindfindfind outoutoutout thethethethe biggerbiggerbiggerbigger numbernumbernumbernumber betweenbetweenbetweenbetween thethethethe
twotwotwotwo numbersnumbersnumbersnumbers
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
printf("Enter a numbern");
scanf("%d",&a);
printf("Enter a numbern");
scanf("%d",&b);
if(a>b)
{
printf("%d is greater than %dn",a,b);
}
else if(a,b)
{
printf("%d is less than %dn",a,b);
}
else
{
printf("%d is equal to %dn",a,b);
}
getchar();
return 0;
}
3.3.3.3.ProgramProgramProgramProgram totototo findfindfindfind outoutoutout eveneveneveneven andandandand oddoddoddodd number.number.number.number.
#include <stdio.h>
int main()
{
int a;
printf("Enter a: n");
scanf("%d", &a);
/* logic */
if (a % 2 == 0)
{printf("The given number is EVENn");
}
else
{printf("The given number is ODDn");
}
return 0;
}
4.4.4.4. ProgramProgramProgramProgram forforforfor squaresquaresquaresquare ofofofof aaaa numbernumbernumbernumber
#include<stdio.h>
#include<conio.h>
void main()
{
long int m,n;
printf("Please enter the number");
scanf("%ld" ,&n);
m=n;
n=n*n;
printf("Square of entered number %ld = %ld ",m,n);
}
5.5.5.5. ProgramProgramProgramProgram forforforfor summationsummationsummationsummation ofofofof aaaa seriesseriesseriesseries
NormalNormalNormalNormal series(1+3+series(1+3+series(1+3+series(1+3+…………..+n)..+n)..+n)..+n)
#include <stdio.h>
#include <conio.h>
void main()
{
int i, N, sum = 0;
clrscr();
printf("Enter The last number of the series n");
scanf ("%d", &N);
for (i=1; i <= N; i++)
{
sum = sum + i;
}
printf ("Sum of first %d natural numbers = %dn", N, sum);
}
WhenWhenWhenWhen differencedifferencedifferencedifference isisisis 2222
#include <stdio.h>
#include <conio.h>
void main()
{
int i, N, sum = 0;
clrscr();
printf("Enter The last number of the series n");
scanf ("%d", &N);
for (i=1; i <= N; i=i+2)
{
sum = sum + i;
}
printf ("Sum of the series is = %dn", sum);
}
SquareSquareSquareSquare series(1^2+3^2+series(1^2+3^2+series(1^2+3^2+series(1^2+3^2+…………..+n^2)..+n^2)..+n^2)..+n^2)
#include<stdio.h>
int main()
{
int n,i;
int sum=0;
printf("Enter the last number os the n i.e. max values of series: ");
scanf("%d",&n);
sum = (n * (n + 1) * (2 * n + 1 )) / 6;
printf("Sum of the series : ");
for(i =1;i<=n;i++){
if (i != n)
printf("%d^2 + ",i);
else
printf("%d^2 = %d ",i,sum);
}
return 0;
}
6.6.6.6. FactorialFactorialFactorialFactorial ofofofof aaaa numbernumbernumbernumber
#include <stdio.h>
int main()
{
int c, n, fact = 1;
printf("n Enter a number to calculate it's factorial: ");
scanf("%d", &n);
for (c = 1; c <= n; c++)
fact = fact * c;
printf("Factorial of %d = %d n", n, fact);
return 0;
}
7.7.7.7. ProgramProgramProgramProgram forforforfor standardstandardstandardstandard deviationdeviationdeviationdeviation ofofofof aaaa numbernumbernumbernumber
#include <stdio.h>
#include <math.h>
float standard_deviation(float data[], int n);
int main()
{
int n, i;
float data[100];
printf("Enter number of datas to be calculated to ndetermine the standard deviation( should be
less than 100): ");
scanf("%d",&n);
printf("Enter elements: ");
for(i=0; i<n; ++i)
scanf("%f",&data[i]);
printf("n");
printf("Standard Deviation = %.2f", standard_deviation(data,n));
return 0;
}
float standard_deviation(float data[], int n)
{
float mean=0.0, sum_deviation=0.0;
int i;
for(i=0; i<n;++i)
{
mean+=data[i];
}
mean=mean/n;
for(i=0; i<n;++i)
sum_deviation+=(data[i]-mean)*(data[i]-mean);
return sqrt(sum_deviation/n);
}
8.8.8.8. WhetherWhetherWhetherWhether thethethethe yearyearyearyear isisisis leapleapleapleap yearyearyearyear orororor notnotnotnot
#include <stdio.h>
int main()
{
int year;
printf("n Enter a year to check whether it is a leap year or not: ");
scanf("%d", &year);
if ( year%4 == 0 )
printf("%d is a leap year.n", year);
else
printf("%d is not a leap year.n", year);
return 0;
}
9.9.9.9. WhetherWhetherWhetherWhether aaaa numbernumbernumbernumber isisisis aaaa primeprimeprimeprime numbernumbernumbernumber orororor notnotnotnot
#include<stdio.h>
int main()
{
int n, c = 2;
printf("n Enter a number to check if it is prime: ");
scanf("%d",&n);
for ( c = 2 ; c <= n - 1 ; c++ )
{
if ( n%c == 0 )
{
printf("%d is not prime.n", n);
break;
}
}
if ( c == n )
printf("%d is prime.n", n);
return 0;
}
10.10.10.10. TheTheTheThe biggestbiggestbiggestbiggest numbernumbernumbernumber amongamongamongamong threethreethreethree numbersnumbersnumbersnumbers
#include <stdio.h>
int main()
{int a, b, c;
printf("Enter a,b,c: n");
scanf("%d %d %d", &a, &b, &c);
if (a > b && a > c)
{printf("a is the biggest number");}
else if (b > a && b > c)
{printf("b is the biggest number ");}
else if (c > a && c > b)
{printf("c is the biggest number ");}
else {printf("all are equal or any two values are equal");}
return 0;
}
11.11.11.11. FibonacciFibonacciFibonacciFibonacci series.series.series.series.
#include<stdio.h>
main()
{
int n, first = 0, second = 1, next, c;
printf("n Enter the number of terms: ");
scanf("%d",&n);
printf("First %d terms of Fibonacci series are :-n",n);
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
printf("%dn",next);
}
return 0;
}
12.12.12.12. WhetherWhetherWhetherWhether thethethethe twotwotwotwo stringstringstringstring areareareare equalequalequalequal
#include<stdio.h>
#include<string.h>
main()
{
char a[100], b[100];
printf("Enter the first string to be compared: ");
gets(a);
printf("nEnter the second string : ");
gets(b);
if( strcmp(a,b) == 0 )
printf("Entered strings are equal.n");
else
printf("Entered strings are not equal.n");
return 0;
}
13.13.13.13. FindFindFindFind outoutoutout thethethethe lengthlengthlengthlength ofofofof aaaa stringstringstringstring
#include<stdio.h>
#include<string.h>
main()
{
char a[100];
int length;
printf("Enter a string to calculate it's length: ");
gets(a);
length = strlen(a);
printf("Length of entered string is = %dn",length);
return 0;
}
14.14.14.14. WhetherWhetherWhetherWhether aaaa particularparticularparticularparticular charactercharactercharactercharacter existsexistsexistsexists inininin aaaa stringstringstringstring
(frequency):(frequency):(frequency):(frequency):
#include <stdio.h>
int main(){
char c[1000],ch;
int i,count=0;
printf("Enter a string: ");
gets(c);
printf("Enter a characeter to find frequency: ");
scanf("%c",&ch);
for(i=0;c[i]!='0';++i)
{
if(ch==c[i])
++count;
}
printf("Frequency of %c = %d", ch, count);
return 0;
}
15.15.15.15. FindFindFindFind outoutoutout thethethethe maximummaximummaximummaximum andandandand minimumminimumminimumminimum numbernumbernumbernumber inininin anananan
arrayarrayarrayarray ::::
[maximum][maximum][maximum][maximum]
#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 number %d and it's value is %d.n", location,
maximum);
return 0;
}
[Minimum][Minimum][Minimum][Minimum]
#include <stdio.h>
int main()
{
int array[100], minimum, 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]);
minimum = array[0];
for ( c = 1 ; c < size ; c++ )
{
if ( array[c] < minimum )
{
minimum = array[c];
location = c+1;
}
}
printf("Minimum element is present at location number %d and it's value is %d.n", location,
minimum);
return 0;
}
16.16.16.16. FindFindFindFind outoutoutout powerpowerpowerpower valuevaluevaluevalue
#include <stdio.h>
int main()
{
int base, exp;
long int value=1;
printf("Enter base number and exponent respectively: ");
scanf("%d%d", &base, &exp);
while (exp!=0)
{
value*=base;
--exp;
}
printf("Answer = %d", value);
}
17.17.17.17. ProgramProgramProgramProgram forforforfor salarysalarysalarysalary sheetsheetsheetsheet
#include<stdio.h>
#include<conio.h>
struct employ
{
char name[20];
int id,bp;
float tot,hra,dr;
};
void main()
{
struct employ list[20],temp;
char name[30];
int n,i,j,m;
printf("Enter the number of employees: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("nEnter the name of employee: ");
scanf("%s",list[i].name);
printf("nEnter id number: ");
scanf("%d",&list[i].id);
printf("nEnter the basic pay: ");
scanf("%d",&list[i].bp);
list[i].dr=.2*list[i].bp;
list[i].hra=.6*list[i].bp;
list[i].tot=list[i].dr +list[i].hra+list[i].bp;
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(strcmp(list[j].name,list[j+1].name)>0)
{
temp=list[j];
list[j]=list[j+1];
list[j+1]=temp;
}
}
}
printf("Salary Sheet isn");
printf("NAME ID NO BASIC PAY SALARYnn");
for(i=0;i<n;i++)
printf("%st%dt%dt%fn",list[i].name,list[i].id,list[i].bp,list[i].tot);
getchar();
}
18.18.18.18. ProgramProgramProgramProgram forforforfor findfindfindfind thethethethe valuevaluevaluevalue totototo thethethethe followingfollowingfollowingfollowing equationequationequationequation ()()()()
#include<stdio.h>
#include<math.h>
int main(){
float a,b,c;
float d,root1,root2;
printf("Enter a, b and c of quadratic equation: ");
scanf("%f%f%f",&a,&b,&c);
d = b * b - 4 * a * c;
if(d < 0){
printf("Roots are complex number.n");
printf("Roots of quadratic equation are: ");
printf("%.3f%+.3fi",-b/(2*a),sqrt(-d)/(2*a));
printf(", %.3f%+.3fi",-b/(2*a),-sqrt(-d)/(2*a));
return 0;
}
else if(d==0){
printf("Both roots are equal.n");
root1 = -b /(2* a);
printf("Root of quadratic equation is: %.3f ",root1);
return 0;
}
else{
printf("Roots are real numbers.n");
root1 = ( -b + sqrt(d)) / (2* a);
root2 = ( -b - sqrt(d)) / (2* a);
printf("Roots of quadratic equation are: %.3f , %.3f",root1,root2);
}
return 0;
}
19.19.19.19. ConversionConversionConversionConversion ofofofof decimaldecimaldecimaldecimal numbernumbernumbernumber totototo binarybinarybinarybinary numbernumbernumbernumber
#include <stdio.h>
int main()
{
int n, c, k;
printf("Enter an integer in decimal number systemn");
scanf("%d", &n);
printf("%d in binary number system is:n", n);
for (c = 31; c >= 0; c--)
{
k = n >> c;
if (k & 1)
printf("1");
else
printf("0");
}
printf("n");
return 0;
}
20.20.20.20. ProgramProgramProgramProgram forforforfor studentsstudentsstudentsstudents gradinggradinggradinggrading usingusingusingusing structurestructurestructurestructure
#include<stdio.h>
#include<conio.h>
struct student
{
int rollno, marks1,marks2,marks3,marks4,marks5,tot;
char name[40],grade;
float per;
};
void main()
{
struct student s[15];
int i;
printf("t*Students Records*n");
for (i=0; i<15; i++)
{
printf("nEnter Student Roll Number: ");
scanf("%d", &s[i].rollno);
printf("nEnter Student name: ");
scanf("%s", s[i].name);
printf("nEnter Student 3 subject's marks: ");
scanf("%d%d%d", &s[i].marks1,&s[i].marks2,&s[i].marks3,&s[i].marks4,&s[i].marks5);
s[i].tot = s[i].marks1 + s[i].marks2 + s[i].marks3+s[i].marks4+s[i].marks5;
s[i].per = s[i].tot/5;
if(s[i].per>=75){
s[i].grade = 'A';
}
else if(s[i].per<75 && s[i].per>=60){
s[i].grade = 'B';
}
else if(s[i].per<60 && s[i].per>=50){
s[i].grade = 'C';
}
else if(s[i].per<50 && s[i].per>=40){
s[i].grade = 'D';
}
else if(s[i].per<40 && s[i].per>=33){
s[i].grade = 'E';
}
else {
s[i].grade = 'F';
}
}
for (i=0; i<5; i++)
{
printf("n==================================n");
printf("nStudent's Roll no. - %d", s[i].rollno);
printf("nStudent's Name - %s", s[i].name);
printf("nStudent's Total Marks - %d", s[i].tot);
printf("nStudent's Percentage - %f", s[i].per);
printf("nStudent's Grade - %c", s[i].grade);
}
getch();
}
21.21.21.21. TakeTakeTakeTake somesomesomesome inputinputinputinput andandandand findfindfindfind sumsumsumsum andandandand averageaverageaverageaverage
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum=0,n,x;
printf("nHow many numbers you want to input? : ",n);
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("nEnter numbers to add: ",x);
scanf("%d",&x);
sum=sum+x;
}
printf("nSum is: %d",sum);
printf("nAverage is: %d",sum/n);
}
22.22.22.22. WriteWriteWriteWrite aaaa programprogramprogramprogram totototo sortsortsortsort somesomesomesome numbersnumbersnumbersnumbers inininin ascendingascendingascendingascending
orderorderorderorder
#include <stdio.h>
int main()
{
int n, array[1000], c, d, t;
printf("Enter number of elementsn");
scanf("%d", &n);
printf("Enter %d integersn", n);
for (c = 0; c < n; c++) {
scanf("%d", &array[c]);
}
for (c = 1 ; c <= n - 1; c++) {
d = c;
while ( d > 0 && array[d] < array[d-1]) {
t = array[d];
array[d] = array[d-1];
array[d-1] = t;
d--;
}
}
printf("Sorted list in ascending order:n");
for (c = 0; c <= n - 1; c++) {
printf("%dn", array[c]);
}
return 0;
}
23.23.23.23. WriteWriteWriteWrite aaaa programprogramprogramprogram totototo findfindfindfind totototo reversereversereversereverse stringstringstringstring
#include<stdio.h>
#include<string.h>
main()
{
char arr[100];
printf("n Enter a string to reverse: ");
gets(arr);
strrev(arr);
printf("Reverse of entered string is n%sn",arr);
return 0;
}
24.24.24.24. TakeTakeTakeTake somesomesomesome inputinputinputinput inininin aaaa tabletabletabletable andandandand displaydisplaydisplaydisplay themthemthemthem (two(two(two(two
dimensionaldimensionaldimensionaldimensional array)array)array)array) andandandand add/multiplyadd/multiplyadd/multiplyadd/multiply themthemthemthem
#include<stdio.h>
int main()
{
int matrix1[12][12], matrix2[12][12], sum[12][12],multi[12][12], i, j, m,n,p,q;
printf("Enter the order of first matrix: ");
scanf("%d%d",&m,&n);
printf("Enter the order of second matrix: ");
scanf("%d%d",&p,&q);
if(m!=p && n!=q){
printf("Order of matrix did not matched!!");
}
printf("Enter first matrix: n");
for(i = 0 ; i < m; i++){
for(j = 0; j < n; j++)
scanf("%d", &matrix1[i][j]);
}
printf("Enter second matrix: n");
for(i = 0 ; i < p; i++){
for(j = 0; j < q; j++)
scanf("%d", &matrix2[i][j]);
}
for(i = 0 ; i < m; i++){
for(j = 0; j < n; j++)
sum[i][j] = matrix1[i][j] + matrix2[i][j];
}
printf("The sum of the matrix is :n");
for(i = 0 ; i < m; i++){
for(j = 0; j < n; j++){
printf("%d", sum[i][j]);
printf("t");
}
printf("n");
}
for(i = 0 ; i < m; i++){
for(j = 0; j < n; j++)
multi[i][j] = matrix1[i][j] * matrix2[i][j];
}
printf("The multiplication of the matrix is :n");
for(i = 0 ; i < m; i++){
for(j = 0; j < n; j++){
printf("%d", multi[i][j]);
printf("t");
}
printf("n");
}
return 0;
}
25.25.25.25. TakeTakeTakeTake inputinputinputinput andandandand findfindfindfind sumsumsumsum usingusingusingusing functionfunctionfunctionfunction
#include<stdio.h>
#include<conio.h>
void sum();
void main()
{
sum();
getchar();
}
void sum()
{
int n1,n2,s;
printf("nEnter two numbersn ");
scanf("%d%d",&n1,&n2);
s=n1+n2;
printf("n the sum is %d",s);
}
26.26.26.26. ProgramProgramProgramProgram forforforfor stringstringstringstring compare,compare,compare,compare, copycopycopycopy andandandand additionadditionadditionaddition
[Compare][Compare][Compare][Compare]
#include<stdio.h>
#include<string.h>
main()
{
char a[100], b[100];
printf("Enter the first stringn");
gets(a);
printf("Enter the second stringn");
gets(b);
if( strcmp(a,b) == 0 )
printf("Entered strings are equal.n");
else
printf("Entered strings are not equal.n");
return 0;
}
[Copy][Copy][Copy][Copy]
#include<stdio.h>
void copy_string(char*, char*);
main()
{
char source[100], target[100];
printf("Enter source stringn");
gets(source);
copy_string(target, source);
printf("Target string is "%s"n", target);
return 0;
}
void copy_string(char *target, char *source)
{
while(*source)
{
*target = *source;
source++;
target++;
}
*target = '0';
}
[Addition][Addition][Addition][Addition]
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char a[100], b[100];
printf("Enter the first stringn");
gets(a);
printf("Enter the second stringn");
gets(b);
strcat(a,b);
printf("String obtained on addition is %sn",a);
getchar();
return 0;
}
C Programming Exam problems & Solution by sazzad hossain

Más contenido relacionado

La actualidad más candente

C programs
C programsC programs
C programs
Minu S
 
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
Mainak Sasmal
 

La actualidad más candente (20)

C programs
C programsC programs
C programs
 
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
 
Function in C program
Function in C programFunction in C program
Function in C program
 
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
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
Chapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CChapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in C
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Chapter 5 Balagurusamy Programming ANSI in c
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in c
 
Strings in c
Strings in cStrings in c
Strings in c
 
Function in c
Function in cFunction in c
Function in c
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Input Output Management In C Programming
Input Output Management In C ProgrammingInput Output Management In C Programming
Input Output Management In C Programming
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C
 
String in c programming
String in c programmingString in c programming
String in c programming
 
Chapter 6 Balagurusamy Programming ANSI in c
Chapter 6  Balagurusamy Programming ANSI  in cChapter 6  Balagurusamy Programming ANSI  in c
Chapter 6 Balagurusamy Programming ANSI in c
 

Destacado

Persuasion vs. argument
Persuasion vs. argumentPersuasion vs. argument
Persuasion vs. argument
Tanya Appling
 
Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...
Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...
Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...
DATAVERSITY
 

Destacado (20)

Accounting Glossaries
Accounting GlossariesAccounting Glossaries
Accounting Glossaries
 
Decision theory
Decision theoryDecision theory
Decision theory
 
NTRODUCTION TO OPERATIONS RESEARCH
NTRODUCTION TO OPERATIONS RESEARCHNTRODUCTION TO OPERATIONS RESEARCH
NTRODUCTION TO OPERATIONS RESEARCH
 
Micro insurance: A tool for Poverty alleviation & management of Vulnerability...
Micro insurance: A tool for Poverty alleviation & management of Vulnerability...Micro insurance: A tool for Poverty alleviation & management of Vulnerability...
Micro insurance: A tool for Poverty alleviation & management of Vulnerability...
 
Tax deducted at source
Tax deducted at sourceTax deducted at source
Tax deducted at source
 
VAT Rules 1991 Bangladesh
VAT Rules 1991 BangladeshVAT Rules 1991 Bangladesh
VAT Rules 1991 Bangladesh
 
ICMAB question august 2013 All levels All questions
ICMAB question august 2013 All levels All questionsICMAB question august 2013 All levels All questions
ICMAB question august 2013 All levels All questions
 
Linear programing problem
Linear programing problemLinear programing problem
Linear programing problem
 
Compilation of vat act 1991 theory & math ICAB 2016
Compilation of vat act 1991 theory &  math ICAB 2016Compilation of vat act 1991 theory &  math ICAB 2016
Compilation of vat act 1991 theory & math ICAB 2016
 
Top 10 Wishes –What every Human Want Most
Top 10 Wishes –What every Human Want MostTop 10 Wishes –What every Human Want Most
Top 10 Wishes –What every Human Want Most
 
VAT ACT 1991 Bangladesh
VAT ACT 1991 BangladeshVAT ACT 1991 Bangladesh
VAT ACT 1991 Bangladesh
 
Persuasion vs. argument
Persuasion vs. argumentPersuasion vs. argument
Persuasion vs. argument
 
Kite runner revision
Kite runner revisionKite runner revision
Kite runner revision
 
Вusiness communication in China
Вusiness communication in ChinaВusiness communication in China
Вusiness communication in China
 
Your First Day Of Computers Class
Your First Day Of Computers ClassYour First Day Of Computers Class
Your First Day Of Computers Class
 
Duality
DualityDuality
Duality
 
Changes in Finance act-2016 BD
Changes in Finance act-2016 BDChanges in Finance act-2016 BD
Changes in Finance act-2016 BD
 
Ranjan sir lecture details (updated in light of FA 2016) RRH update
Ranjan sir lecture details (updated in light of FA 2016) RRH updateRanjan sir lecture details (updated in light of FA 2016) RRH update
Ranjan sir lecture details (updated in light of FA 2016) RRH update
 
Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...
Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...
Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...
 
Case solving 1 Case Study of Panera Bread
Case solving 1 Case Study of Panera BreadCase solving 1 Case Study of Panera Bread
Case solving 1 Case Study of Panera Bread
 

Similar a C Programming Exam problems & Solution by sazzad hossain

C basics
C basicsC basics
C basics
MSc CST
 

Similar a C Programming Exam problems & Solution by sazzad hossain (20)

All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
C file
C fileC file
C file
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
C lab
C labC lab
C lab
 
C Programming
C ProgrammingC Programming
C Programming
 
C programms
C programmsC programms
C programms
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Progr3
Progr3Progr3
Progr3
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
 
C basics
C basicsC basics
C basics
 
C programming function
C  programming functionC  programming function
C programming function
 
Najmul
Najmul  Najmul
Najmul
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
C Programming lab
C Programming labC Programming lab
C Programming lab
 

Más de Sazzad Hossain, ITP, MBA, CSCA™

Más de Sazzad Hossain, ITP, MBA, CSCA™ (20)

ITP CIRCULAR 2017 Income Tax Bangladesh - NBR
ITP CIRCULAR 2017 Income Tax Bangladesh - NBRITP CIRCULAR 2017 Income Tax Bangladesh - NBR
ITP CIRCULAR 2017 Income Tax Bangladesh - NBR
 
Auditors Tor for Cash incentive audit of BB
Auditors Tor for Cash incentive audit of BBAuditors Tor for Cash incentive audit of BB
Auditors Tor for Cash incentive audit of BB
 
Tax year 2024 Advance Taxation book by Khalid Petiwala
Tax year 2024 Advance Taxation book by Khalid PetiwalaTax year 2024 Advance Taxation book by Khalid Petiwala
Tax year 2024 Advance Taxation book by Khalid Petiwala
 
All CA Firms 23 October 2023
All CA Firms 23 October 2023All CA Firms 23 October 2023
All CA Firms 23 October 2023
 
আয়কর পরিপত্র ২০২৩-২৪
আয়কর পরিপত্র ২০২৩-২৪ আয়কর পরিপত্র ২০২৩-২৪
আয়কর পরিপত্র ২০২৩-২৪
 
সর্বজনীন পেনশন স্কীম বিধিমালা সংক্রান্ত গেজেট (আগস্ট ২০২৩)
সর্বজনীন পেনশন স্কীম বিধিমালা সংক্রান্ত গেজেট (আগস্ট ২০২৩) সর্বজনীন পেনশন স্কীম বিধিমালা সংক্রান্ত গেজেট (আগস্ট ২০২৩)
সর্বজনীন পেনশন স্কীম বিধিমালা সংক্রান্ত গেজেট (আগস্ট ২০২৩)
 
VAT Deduction at Source
VAT Deduction at SourceVAT Deduction at Source
VAT Deduction at Source
 
জীবনকে কয়েক ধাপ এগিয়ে নিতে চাইলে
জীবনকে কয়েক ধাপ এগিয়ে নিতে চাইলে জীবনকে কয়েক ধাপ এগিয়ে নিতে চাইলে
জীবনকে কয়েক ধাপ এগিয়ে নিতে চাইলে
 
Jun-2023 এস.আর.ও. নং- ১৯৫-২০১-আইন-২০২৩ Customs Act 1969
Jun-2023 এস.আর.ও. নং- ১৯৫-২০১-আইন-২০২৩ Customs Act 1969Jun-2023 এস.আর.ও. নং- ১৯৫-২০১-আইন-২০২৩ Customs Act 1969
Jun-2023 এস.আর.ও. নং- ১৯৫-২০১-আইন-২০২৩ Customs Act 1969
 
TDS Tax Deducted at Source Rule 2023 এস.আর.ও. নং ২০৬-২১০-আইন-২০২৩
TDS Tax Deducted at Source Rule 2023 এস.আর.ও. নং ২০৬-২১০-আইন-২০২৩TDS Tax Deducted at Source Rule 2023 এস.আর.ও. নং ২০৬-২১০-আইন-২০২৩
TDS Tax Deducted at Source Rule 2023 এস.আর.ও. নং ২০৬-২১০-আইন-২০২৩
 
২০২৩ সনের ১৩ নং আইন ব্যাংক- কোম্পানি (সংশোধন) আইন, ২০২৩
২০২৩ সনের ১৩ নং আইন ব্যাংক- কোম্পানি (সংশোধন) আইন, ২০২৩২০২৩ সনের ১৩ নং আইন ব্যাংক- কোম্পানি (সংশোধন) আইন, ২০২৩
২০২৩ সনের ১৩ নং আইন ব্যাংক- কোম্পানি (সংশোধন) আইন, ২০২৩
 
২০২৩ সনের ২২ নং আইন বাংলাদেশ শিল্প-নকশা আইন, ২০২৩
২০২৩ সনের ২২ নং আইন বাংলাদেশ শিল্প-নকশা আইন, ২০২৩২০২৩ সনের ২২ নং আইন বাংলাদেশ শিল্প-নকশা আইন, ২০২৩
২০২৩ সনের ২২ নং আইন বাংলাদেশ শিল্প-নকশা আইন, ২০২৩
 
২০২৩ সনের ২০ নং আইন এজেন্সি টু ইনোভেট (এটুআই) আইন, ২০২৩
২০২৩ সনের ২০ নং আইন এজেন্সি টু ইনোভেট (এটুআই) আইন, ২০২৩২০২৩ সনের ২০ নং আইন এজেন্সি টু ইনোভেট (এটুআই) আইন, ২০২৩
২০২৩ সনের ২০ নং আইন এজেন্সি টু ইনোভেট (এটুআই) আইন, ২০২৩
 
২০২৩ সনের ১৯ নং আইন বাংলাদেশ সরকারি-বেসরকারি অংশীদারিত্ব (সংশোধন) আইন, ২০২৩
২০২৩ সনের ১৯ নং আইন বাংলাদেশ সরকারি-বেসরকারি অংশীদারিত্ব (সংশোধন) আইন, ২০২৩২০২৩ সনের ১৯ নং আইন বাংলাদেশ সরকারি-বেসরকারি অংশীদারিত্ব (সংশোধন) আইন, ২০২৩
২০২৩ সনের ১৯ নং আইন বাংলাদেশ সরকারি-বেসরকারি অংশীদারিত্ব (সংশোধন) আইন, ২০২৩
 
এস.আর.ও নং ২২৪আইন-আয়কর-২০২৩
এস.আর.ও নং ২২৪আইন-আয়কর-২০২৩এস.আর.ও নং ২২৪আইন-আয়কর-২০২৩
এস.আর.ও নং ২২৪আইন-আয়কর-২০২৩
 
Govt Employee Taxation Rules এস.আর.ও নং ২২৫-আইন-আয়কর-৭-২০২৩.pdf
Govt Employee Taxation Rules এস.আর.ও নং ২২৫-আইন-আয়কর-৭-২০২৩.pdfGovt Employee Taxation Rules এস.আর.ও নং ২২৫-আইন-আয়কর-৭-২০২৩.pdf
Govt Employee Taxation Rules এস.আর.ও নং ২২৫-আইন-আয়কর-৭-২০২৩.pdf
 
TDS Rules, 2023 উৎসে কর বিধিমালা, ২০২৩
TDS Rules, 2023 উৎসে কর বিধিমালা, ২০২৩ TDS Rules, 2023 উৎসে কর বিধিমালা, ২০২৩
TDS Rules, 2023 উৎসে কর বিধিমালা, ২০২৩
 
২০২৩-২৪ অর্থবছরে ভ্যাট হার
২০২৩-২৪ অর্থবছরে ভ্যাট হার২০২৩-২৪ অর্থবছরে ভ্যাট হার
২০২৩-২৪ অর্থবছরে ভ্যাট হার
 
TDS on ITA 2023
TDS on ITA 2023  TDS on ITA 2023
TDS on ITA 2023
 
Mapping of ITA 2023 with ITO 1984
Mapping of ITA 2023 with ITO 1984Mapping of ITA 2023 with ITO 1984
Mapping of ITA 2023 with ITO 1984
 

Último

Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 

Último (20)

PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
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...
 
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"
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
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"
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

C Programming Exam problems & Solution by sazzad hossain

  • 1. Problems and solutions 1.1.1.1. ProgramProgramProgramProgram totototo findfindfindfind outoutoutout thethethethe temperaturetemperaturetemperaturetemperature inininin FahrenheitFahrenheitFahrenheitFahrenheit #include <stdio.h> void main() { float c, f; printf("nEnter temperature in degree Centigrade: "); scanf("%f", &c); f = (1.8*c) + 32; printf("n Temperature in degree Fahrenheit: %.2f", f); getchar(); } 2.2.2.2.ProgramProgramProgramProgram totototo findfindfindfind outoutoutout thethethethe biggerbiggerbiggerbigger numbernumbernumbernumber betweenbetweenbetweenbetween thethethethe twotwotwotwo numbersnumbersnumbersnumbers #include<stdio.h> #include<conio.h> int main() { int a,b;
  • 2. printf("Enter a numbern"); scanf("%d",&a); printf("Enter a numbern"); scanf("%d",&b); if(a>b) { printf("%d is greater than %dn",a,b); } else if(a,b) { printf("%d is less than %dn",a,b); } else { printf("%d is equal to %dn",a,b); } getchar(); return 0; } 3.3.3.3.ProgramProgramProgramProgram totototo findfindfindfind outoutoutout eveneveneveneven andandandand oddoddoddodd number.number.number.number. #include <stdio.h> int main()
  • 3. { int a; printf("Enter a: n"); scanf("%d", &a); /* logic */ if (a % 2 == 0) {printf("The given number is EVENn"); } else {printf("The given number is ODDn"); } return 0; } 4.4.4.4. ProgramProgramProgramProgram forforforfor squaresquaresquaresquare ofofofof aaaa numbernumbernumbernumber #include<stdio.h> #include<conio.h> void main() { long int m,n; printf("Please enter the number"); scanf("%ld" ,&n); m=n; n=n*n;
  • 4. printf("Square of entered number %ld = %ld ",m,n); } 5.5.5.5. ProgramProgramProgramProgram forforforfor summationsummationsummationsummation ofofofof aaaa seriesseriesseriesseries NormalNormalNormalNormal series(1+3+series(1+3+series(1+3+series(1+3+…………..+n)..+n)..+n)..+n) #include <stdio.h> #include <conio.h> void main() { int i, N, sum = 0; clrscr(); printf("Enter The last number of the series n"); scanf ("%d", &N); for (i=1; i <= N; i++) { sum = sum + i; }
  • 5. printf ("Sum of first %d natural numbers = %dn", N, sum); } WhenWhenWhenWhen differencedifferencedifferencedifference isisisis 2222 #include <stdio.h> #include <conio.h> void main() { int i, N, sum = 0; clrscr(); printf("Enter The last number of the series n"); scanf ("%d", &N);
  • 6. for (i=1; i <= N; i=i+2) { sum = sum + i; } printf ("Sum of the series is = %dn", sum); } SquareSquareSquareSquare series(1^2+3^2+series(1^2+3^2+series(1^2+3^2+series(1^2+3^2+…………..+n^2)..+n^2)..+n^2)..+n^2) #include<stdio.h> int main() { int n,i; int sum=0; printf("Enter the last number os the n i.e. max values of series: "); scanf("%d",&n); sum = (n * (n + 1) * (2 * n + 1 )) / 6; printf("Sum of the series : "); for(i =1;i<=n;i++){ if (i != n) printf("%d^2 + ",i); else printf("%d^2 = %d ",i,sum);
  • 7. } return 0; } 6.6.6.6. FactorialFactorialFactorialFactorial ofofofof aaaa numbernumbernumbernumber #include <stdio.h> int main() { int c, n, fact = 1; printf("n Enter a number to calculate it's factorial: "); scanf("%d", &n); for (c = 1; c <= n; c++) fact = fact * c; printf("Factorial of %d = %d n", n, fact); return 0; } 7.7.7.7. ProgramProgramProgramProgram forforforfor standardstandardstandardstandard deviationdeviationdeviationdeviation ofofofof aaaa numbernumbernumbernumber #include <stdio.h> #include <math.h> float standard_deviation(float data[], int n); int main() { int n, i;
  • 8. float data[100]; printf("Enter number of datas to be calculated to ndetermine the standard deviation( should be less than 100): "); scanf("%d",&n); printf("Enter elements: "); for(i=0; i<n; ++i) scanf("%f",&data[i]); printf("n"); printf("Standard Deviation = %.2f", standard_deviation(data,n)); return 0; } float standard_deviation(float data[], int n) { float mean=0.0, sum_deviation=0.0; int i; for(i=0; i<n;++i) { mean+=data[i]; } mean=mean/n; for(i=0; i<n;++i) sum_deviation+=(data[i]-mean)*(data[i]-mean); return sqrt(sum_deviation/n); }
  • 9. 8.8.8.8. WhetherWhetherWhetherWhether thethethethe yearyearyearyear isisisis leapleapleapleap yearyearyearyear orororor notnotnotnot #include <stdio.h> int main() { int year; printf("n Enter a year to check whether it is a leap year or not: "); scanf("%d", &year); if ( year%4 == 0 ) printf("%d is a leap year.n", year); else printf("%d is not a leap year.n", year); return 0; } 9.9.9.9. WhetherWhetherWhetherWhether aaaa numbernumbernumbernumber isisisis aaaa primeprimeprimeprime numbernumbernumbernumber orororor notnotnotnot #include<stdio.h> int main() { int n, c = 2; printf("n Enter a number to check if it is prime: "); scanf("%d",&n); for ( c = 2 ; c <= n - 1 ; c++ )
  • 10. { if ( n%c == 0 ) { printf("%d is not prime.n", n); break; } } if ( c == n ) printf("%d is prime.n", n); return 0; } 10.10.10.10. TheTheTheThe biggestbiggestbiggestbiggest numbernumbernumbernumber amongamongamongamong threethreethreethree numbersnumbersnumbersnumbers #include <stdio.h> int main() {int a, b, c; printf("Enter a,b,c: n"); scanf("%d %d %d", &a, &b, &c); if (a > b && a > c) {printf("a is the biggest number");} else if (b > a && b > c) {printf("b is the biggest number ");}
  • 11. else if (c > a && c > b) {printf("c is the biggest number ");} else {printf("all are equal or any two values are equal");} return 0; } 11.11.11.11. FibonacciFibonacciFibonacciFibonacci series.series.series.series. #include<stdio.h> main() { int n, first = 0, second = 1, next, c; printf("n Enter the number of terms: "); scanf("%d",&n); printf("First %d terms of Fibonacci series are :-n",n); for ( c = 0 ; c < n ; c++ ) { if ( c <= 1 ) next = c; else { next = first + second; first = second; second = next;
  • 12. } printf("%dn",next); } return 0; } 12.12.12.12. WhetherWhetherWhetherWhether thethethethe twotwotwotwo stringstringstringstring areareareare equalequalequalequal #include<stdio.h> #include<string.h> main() { char a[100], b[100]; printf("Enter the first string to be compared: "); gets(a); printf("nEnter the second string : "); gets(b); if( strcmp(a,b) == 0 ) printf("Entered strings are equal.n"); else printf("Entered strings are not equal.n"); return 0; }
  • 13. 13.13.13.13. FindFindFindFind outoutoutout thethethethe lengthlengthlengthlength ofofofof aaaa stringstringstringstring #include<stdio.h> #include<string.h> main() { char a[100]; int length; printf("Enter a string to calculate it's length: "); gets(a); length = strlen(a); printf("Length of entered string is = %dn",length); return 0; } 14.14.14.14. WhetherWhetherWhetherWhether aaaa particularparticularparticularparticular charactercharactercharactercharacter existsexistsexistsexists inininin aaaa stringstringstringstring (frequency):(frequency):(frequency):(frequency): #include <stdio.h> int main(){ char c[1000],ch; int i,count=0; printf("Enter a string: ");
  • 14. gets(c); printf("Enter a characeter to find frequency: "); scanf("%c",&ch); for(i=0;c[i]!='0';++i) { if(ch==c[i]) ++count; } printf("Frequency of %c = %d", ch, count); return 0; } 15.15.15.15. FindFindFindFind outoutoutout thethethethe maximummaximummaximummaximum andandandand minimumminimumminimumminimum numbernumbernumbernumber inininin anananan arrayarrayarrayarray :::: [maximum][maximum][maximum][maximum] #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]);
  • 15. 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 number %d and it's value is %d.n", location, maximum); return 0; } [Minimum][Minimum][Minimum][Minimum] #include <stdio.h> int main() { int array[100], minimum, 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]); minimum = array[0]; for ( c = 1 ; c < size ; c++ ) {
  • 16. if ( array[c] < minimum ) { minimum = array[c]; location = c+1; } } printf("Minimum element is present at location number %d and it's value is %d.n", location, minimum); return 0; } 16.16.16.16. FindFindFindFind outoutoutout powerpowerpowerpower valuevaluevaluevalue #include <stdio.h> int main() { int base, exp; long int value=1; printf("Enter base number and exponent respectively: "); scanf("%d%d", &base, &exp); while (exp!=0) { value*=base; --exp;
  • 17. } printf("Answer = %d", value); } 17.17.17.17. ProgramProgramProgramProgram forforforfor salarysalarysalarysalary sheetsheetsheetsheet #include<stdio.h> #include<conio.h> struct employ { char name[20]; int id,bp; float tot,hra,dr; }; void main() { struct employ list[20],temp; char name[30]; int n,i,j,m; printf("Enter the number of employees: "); scanf("%d",&n); for(i=0;i<n;i++) { printf("nEnter the name of employee: ");
  • 18. scanf("%s",list[i].name); printf("nEnter id number: "); scanf("%d",&list[i].id); printf("nEnter the basic pay: "); scanf("%d",&list[i].bp); list[i].dr=.2*list[i].bp; list[i].hra=.6*list[i].bp; list[i].tot=list[i].dr +list[i].hra+list[i].bp; } for(i=0;i<n;i++) { for(j=0;j<n-i-1;j++) { if(strcmp(list[j].name,list[j+1].name)>0) { temp=list[j]; list[j]=list[j+1]; list[j+1]=temp; } } } printf("Salary Sheet isn"); printf("NAME ID NO BASIC PAY SALARYnn"); for(i=0;i<n;i++) printf("%st%dt%dt%fn",list[i].name,list[i].id,list[i].bp,list[i].tot);
  • 19. getchar(); } 18.18.18.18. ProgramProgramProgramProgram forforforfor findfindfindfind thethethethe valuevaluevaluevalue totototo thethethethe followingfollowingfollowingfollowing equationequationequationequation ()()()() #include<stdio.h> #include<math.h> int main(){ float a,b,c; float d,root1,root2; printf("Enter a, b and c of quadratic equation: "); scanf("%f%f%f",&a,&b,&c); d = b * b - 4 * a * c; if(d < 0){ printf("Roots are complex number.n"); printf("Roots of quadratic equation are: ");
  • 20. printf("%.3f%+.3fi",-b/(2*a),sqrt(-d)/(2*a)); printf(", %.3f%+.3fi",-b/(2*a),-sqrt(-d)/(2*a)); return 0; } else if(d==0){ printf("Both roots are equal.n"); root1 = -b /(2* a); printf("Root of quadratic equation is: %.3f ",root1); return 0; } else{ printf("Roots are real numbers.n"); root1 = ( -b + sqrt(d)) / (2* a); root2 = ( -b - sqrt(d)) / (2* a); printf("Roots of quadratic equation are: %.3f , %.3f",root1,root2); } return 0; }
  • 21. 19.19.19.19. ConversionConversionConversionConversion ofofofof decimaldecimaldecimaldecimal numbernumbernumbernumber totototo binarybinarybinarybinary numbernumbernumbernumber #include <stdio.h> int main() { int n, c, k; printf("Enter an integer in decimal number systemn"); scanf("%d", &n); printf("%d in binary number system is:n", n); for (c = 31; c >= 0; c--) { k = n >> c; if (k & 1) printf("1"); else printf("0"); } printf("n"); return 0; } 20.20.20.20. ProgramProgramProgramProgram forforforfor studentsstudentsstudentsstudents gradinggradinggradinggrading usingusingusingusing structurestructurestructurestructure #include<stdio.h>
  • 22. #include<conio.h> struct student { int rollno, marks1,marks2,marks3,marks4,marks5,tot; char name[40],grade; float per; }; void main() { struct student s[15]; int i; printf("t*Students Records*n"); for (i=0; i<15; i++) { printf("nEnter Student Roll Number: "); scanf("%d", &s[i].rollno); printf("nEnter Student name: "); scanf("%s", s[i].name); printf("nEnter Student 3 subject's marks: "); scanf("%d%d%d", &s[i].marks1,&s[i].marks2,&s[i].marks3,&s[i].marks4,&s[i].marks5); s[i].tot = s[i].marks1 + s[i].marks2 + s[i].marks3+s[i].marks4+s[i].marks5; s[i].per = s[i].tot/5; if(s[i].per>=75){ s[i].grade = 'A'; }
  • 23. else if(s[i].per<75 && s[i].per>=60){ s[i].grade = 'B'; } else if(s[i].per<60 && s[i].per>=50){ s[i].grade = 'C'; } else if(s[i].per<50 && s[i].per>=40){ s[i].grade = 'D'; } else if(s[i].per<40 && s[i].per>=33){ s[i].grade = 'E'; } else { s[i].grade = 'F'; } } for (i=0; i<5; i++) { printf("n==================================n"); printf("nStudent's Roll no. - %d", s[i].rollno); printf("nStudent's Name - %s", s[i].name); printf("nStudent's Total Marks - %d", s[i].tot); printf("nStudent's Percentage - %f", s[i].per); printf("nStudent's Grade - %c", s[i].grade); }
  • 24. getch(); } 21.21.21.21. TakeTakeTakeTake somesomesomesome inputinputinputinput andandandand findfindfindfind sumsumsumsum andandandand averageaverageaverageaverage #include<stdio.h> #include<conio.h> void main() { int i,sum=0,n,x; printf("nHow many numbers you want to input? : ",n); scanf("%d",&n); for(i=1;i<=n;i++) { printf("nEnter numbers to add: ",x); scanf("%d",&x); sum=sum+x; } printf("nSum is: %d",sum); printf("nAverage is: %d",sum/n); } 22.22.22.22. WriteWriteWriteWrite aaaa programprogramprogramprogram totototo sortsortsortsort somesomesomesome numbersnumbersnumbersnumbers inininin ascendingascendingascendingascending orderorderorderorder
  • 25. #include <stdio.h> int main() { int n, array[1000], c, d, t; printf("Enter number of elementsn"); scanf("%d", &n); printf("Enter %d integersn", n); for (c = 0; c < n; c++) { scanf("%d", &array[c]); } for (c = 1 ; c <= n - 1; c++) { d = c; while ( d > 0 && array[d] < array[d-1]) { t = array[d]; array[d] = array[d-1]; array[d-1] = t; d--; } } printf("Sorted list in ascending order:n"); for (c = 0; c <= n - 1; c++) { printf("%dn", array[c]); } return 0; }
  • 26. 23.23.23.23. WriteWriteWriteWrite aaaa programprogramprogramprogram totototo findfindfindfind totototo reversereversereversereverse stringstringstringstring #include<stdio.h> #include<string.h> main() { char arr[100]; printf("n Enter a string to reverse: "); gets(arr); strrev(arr); printf("Reverse of entered string is n%sn",arr); return 0; } 24.24.24.24. TakeTakeTakeTake somesomesomesome inputinputinputinput inininin aaaa tabletabletabletable andandandand displaydisplaydisplaydisplay themthemthemthem (two(two(two(two dimensionaldimensionaldimensionaldimensional array)array)array)array) andandandand add/multiplyadd/multiplyadd/multiplyadd/multiply themthemthemthem #include<stdio.h> int main() { int matrix1[12][12], matrix2[12][12], sum[12][12],multi[12][12], i, j, m,n,p,q; printf("Enter the order of first matrix: "); scanf("%d%d",&m,&n); printf("Enter the order of second matrix: ");
  • 27. scanf("%d%d",&p,&q); if(m!=p && n!=q){ printf("Order of matrix did not matched!!"); } printf("Enter first matrix: n"); for(i = 0 ; i < m; i++){ for(j = 0; j < n; j++) scanf("%d", &matrix1[i][j]); } printf("Enter second matrix: n"); for(i = 0 ; i < p; i++){ for(j = 0; j < q; j++) scanf("%d", &matrix2[i][j]); } for(i = 0 ; i < m; i++){ for(j = 0; j < n; j++) sum[i][j] = matrix1[i][j] + matrix2[i][j]; } printf("The sum of the matrix is :n"); for(i = 0 ; i < m; i++){ for(j = 0; j < n; j++){ printf("%d", sum[i][j]); printf("t"); }
  • 28. printf("n"); } for(i = 0 ; i < m; i++){ for(j = 0; j < n; j++) multi[i][j] = matrix1[i][j] * matrix2[i][j]; } printf("The multiplication of the matrix is :n"); for(i = 0 ; i < m; i++){ for(j = 0; j < n; j++){ printf("%d", multi[i][j]); printf("t"); } printf("n"); } return 0; } 25.25.25.25. TakeTakeTakeTake inputinputinputinput andandandand findfindfindfind sumsumsumsum usingusingusingusing functionfunctionfunctionfunction #include<stdio.h> #include<conio.h> void sum(); void main()
  • 29. { sum(); getchar(); } void sum() { int n1,n2,s; printf("nEnter two numbersn "); scanf("%d%d",&n1,&n2); s=n1+n2; printf("n the sum is %d",s); } 26.26.26.26. ProgramProgramProgramProgram forforforfor stringstringstringstring compare,compare,compare,compare, copycopycopycopy andandandand additionadditionadditionaddition [Compare][Compare][Compare][Compare] #include<stdio.h> #include<string.h> main() { char a[100], b[100]; printf("Enter the first stringn"); gets(a);
  • 30. printf("Enter the second stringn"); gets(b); if( strcmp(a,b) == 0 ) printf("Entered strings are equal.n"); else printf("Entered strings are not equal.n"); return 0; } [Copy][Copy][Copy][Copy] #include<stdio.h> void copy_string(char*, char*); main() { char source[100], target[100]; printf("Enter source stringn"); gets(source); copy_string(target, source); printf("Target string is "%s"n", target); return 0; } void copy_string(char *target, char *source) { while(*source)
  • 31. { *target = *source; source++; target++; } *target = '0'; } [Addition][Addition][Addition][Addition] #include<stdio.h> #include<conio.h> #include<string.h> main() { char a[100], b[100]; printf("Enter the first stringn"); gets(a); printf("Enter the second stringn"); gets(b); strcat(a,b); printf("String obtained on addition is %sn",a); getchar(); return 0; }