Sie sind auf Seite 1von 10

Bangladesh University of Business & Technology (BUBT)

Dhaka Commerce College Road, Mirpur-2, Dhaka-1216

C programming
Simple problems for beginners

Contents:
1. Find the average of any three numbers. 2. Find the bigger number of any two numbers. 3. Find the biggest number of any three numbers. 4. Find if the number is positive or negative. 5. Find if the number is odd or even. 6. Find grade (BUBT grading system). 7. Calculate summation of the series : 1+2+3+4+.+n 8. Calculate factorial of n! . 9. Convert Celsius temperature to Fahrenheit. 10. Convert Fahrenheit temperature to Celsius.

Problem#1: Find the average of any three numbers.

#include<stdio.h> int main() { int a,b,c,avg; printf(Input first number:); scanf(%d,&a); printf(Input second number:); scanf(%d,&b); printf(Input third number:); scanf(%d,&c);

avg=(a+b+c)/3; printf(Average=%d,avg); return 0; }

Problem#2: Find the bigger number of any two numbers.

#include<stdio.h>

int main() { int a,b; printf(Input first number:); scanf(%d,&a); printf(Input second number:); scanf(%d,&b);

if(a>b) printf(%d is bigger number.,a); else printf(%d is bigger number.,b);

return 0; }

Problem#3: Find the biggest number of any three numbers.

#include<stdio.h> int main()

{ int a,b,c; printf(Input first number:); scanf(%d,&a); printf(Input second number:); scanf(%d,&b); printf(Input third number:); scanf(%d,&c);

if((a>b) && (a>c)) printf(%d is biggest number.,a); else if((b>a) && (b>c)) printf(%d is biggest number.,b); else printf(%d is biggest number.,c);

return 0; }

Problem#4: Find if the number is positive or negative.

#include<stdio.h> int main() { int a; printf(Input number:); scanf(%d,&a);

if(a>=0) printf(Positive number.); else printf(Negative number.);

return 0; }

Problem#5: Find if the number is odd or even. #include<stdio.h> int main() { int a;

printf(Input number:); scanf(%d,&a);

if(a%2==0) printf(Odd number.); else printf(Even number.);

return 0; } Problem#6: Find grade (BUBT grading system).

#include<stdio.h> int main() { int a; printf(Enter number:); scanf(%d,&num);

if(a>=80) printf(Grade= A+);

else if(a>=75) printf(Grade= A); else if(a>=70) printf(Grade= A-); else if(a>=65) printf(Grade= B+); else if(a>=60) printf(Grade= B); else if(a>=55) printf(Grade= B-); else if(a>=50) printf(Grade= C+); else if(a>=45) printf(Grade= C); else if(a>=40) printf(Grade= D); else if(a<40) printf(Grade= F);

return 0; }

Problem#7: Calculate summation of the series: 1+2+3+4+.+n

#include<stdio.h> int main() { int n,i,sum=0; printf(Enter ending number:); scanf(%d,&n);

for( i=0 ; i<=n , i++ ) { sum=sum+1; } Printf(Summation of the series: 1+2+3+4+.+%d is %d,n,sum); return 0; }

Problem#8: Calculate factorial of n! .

#include<stdio.h> int main()

{ int n,i,fact=1; printf(Enter ending number:); scanf(%d,&n);

for( i=0 ; i<=n , i++ ) { fact=fact*i; } Printf(Factorial of %d! is %d,n,fact); return 0; }

Problem#9: Convert Celsius temperature to Fahrenheit.

#include<stdio.h> int main() { float c,f; printf(Enter Celsius temperature:); scanf(%f,&c);

f=(c-100)/5; printf(Fahrenheit temperature: %f,f);

return 0; }

Problem#10: Convert Fahrenheit temperature to Celsius.

#include<stdio.h> int main() { float c,f; printf(Enter Fahrenheit temperature:); scanf(%f,&f);

c=(f-32)/9; printf(Celsius temperature: %f,c);

return 0; }

Das könnte Ihnen auch gefallen