Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
cprograms

cprograms

Ratings: (0)|Views: 18|Likes:
Published by kschandra1610

More info:

Published by: kschandra1610 on Feb 01, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

02/01/2011

pdf

text

original

 
IB.TECH -COMPUTER PROGRAMMING LAB
Program1:/* Write a C program to find the sum of individual digits of a positive integer.*/
#include<stdio.h>#include<conio.h>void main(){int n,r,sum=0;clrscr(); printf("enter the number \n");scanf("%d",&n);do{r=n%10;sum=sum+r;n=n/10;}while(n>0); printf("sum of digits of integer numbers=%d",sum);getch();}
Program2:/* A Fibonacci Sequence is defined as follows: the first and second terms in thesequence are 0 and 1. Subsequent terms are found by adding the preceding twoterms in the sequence. Write a C program to generate the first n terms of thesequence.*/
#include<stdio.h>#include<conio.h>void main(){int n,f0,f1,f2,i;clrscr(); printf("enter the number \n");scanf("%d",&n);f0=0;f1=1; printf("%d\t%d\t",f0,f1);for(i=1;i<=(n-2);i++){f2=f0+f1; printf("%2d",f2);f0=f1;f1=f2;
 
}getch();}
Program3:/* Write a C program to generate all the prime numbers between 1 and n, where n isa value supplied by the user. */
#include<stdio.h>#include<conio.h>void main(){int i,j,n,cnt=0;clrscr(); printf("enter the number \n");scanf("%d",&n);for(i=1;i<=n;i++){if(i==1){continue;}for(j=1;j<=i;j++){if(i%j==0)cnt++;}if(cnt==2) printf("%d\n",i);cnt=0;}getch();}
Program4:/* Write a C program toe find the roots of a quadratic equation. */
#include<stdio.h>#include<conio.h>#include<math.h>main(){int r1,r2,a,b,c;clrscr(); printf("enter the values of a,b,c\n");
 
scanf("%d%d%d",&a,&b,&c);if((b*b)==(4*a*c)){r1=-b/(2*a);r2=-b/(2*a); printf("the roots are r1=%d,r2=%d",r1,r2);}else if((b*b)>(4*a*c)){r1=(-b+sqrt((b*b)-(4*a*c)))/(2*a);r2=(-b-sqrt((b*b)-(4*a*c)))/(2*a); printf("the roots are r1=%d,r2=%d",r1,r2);}else{ printf("roots are imajinary\n");}getch();}
Program5:/* Write a C program to calculate the following Sum:Sum=1-x2/2! +x4/4!-x6/6!+x8/8!-x10/10! */
#include<stdio.h>#include<conio.h>#include<math.h>main(){int i,j;int n,m;double x;int sum=0;clrscr(); printf("enter x value to evalute serise \n");scanf("%lf",&x);scanf("%d",&n);for(i=0,j=0;j<=n;i++,j=j+2){sum=sum+(pow(-1,i)*pow(x,j)/fact(j));} printf("sum=%d",sum);}int fact(int m){if(m==0||m==1)

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->