You are on page 1of 3

/ To Calculate the Area of a Circle # include <iostream.h> int main( ) { float PI = 3.

14; int rad; cout<< "Enter the radius" ; cin>>rad; cout<< "Area of the circle is "<< PI * rad * rad; return 0; } Find the greatest number in given three numbers? Answer: #include<stdio.h> int main(){ int a,b,c,big; printf("\nEnter 3 numbers:"); scanf("%d %d %d",&a,&b,&c); big=(a>b&&a>c?a:b>c?b:c); printf("\nThe biggest number is:%d",big); return 0; } 3) Write a program to check whether a give number is even or odd /*Programming in C...*/ #include <stdio.h> int main(void) { int n ; printf("enter a number :"); scanf("%d",&n); if(n%2==0) { printf("no is even\n"); } else printf("no. is odd\n"); return 0; } 4) int Num = 5; if(Num % 2 == 0) { // It's even } else { // It's odd }

5) sum of all odd numbers #include<iostream.h> void main() { int n,i; int addeven=0; int addodd=1; printf("\nEnter a number\n"); scanf("%d",&n); fflush(stdin); for(i=2;i<=n;i++) { if(i%2==0) addeven+=i; else addodd+=i; } printf("\nThe sum of odd numbers is %d \nThe sum of even numbers is %d\n",addeve n,addodd); } 6) fibbonacci series #include<stdio.h> int main() { int f1,f2,f3,k,n; printf("Enter the last element\n"); scanf("%d",&n); f1=1; f2=2; f3=f1+f2; while(f3<n) { f1=f2; f2=f3; f3=f1+f2; k=f2; while(k<f3-1 && k<=n-1) { k++; printf("%4d",k); } } return 0; } Manjiri Join Date: Nov 2006 Posts: 40 #5: Nov 27 '06 re: problem with fibonacci series

Try out with this ... U will get the ans... #include<stdio.h> int main() { int f1,f2,f3,k,n; printf("Enter the last element\n"); scanf("%d",&n); f1=1; f2=2; f3=f1+f2; while(f3<n) { f1=f2; f2=f3; f3=f1+f2; k=f2; while(k<f3-1 && k<=n-1) { k++; printf("%4d",k); } } return 0; } rs_from_1_to_n%27#ixzz17kZRG4TA

You might also like