Home >Education >Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad

# Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad

Date post:07-May-2015
Category:
View:367 times
Description:
C and Data Structures Lab Solutions, JNTU Hyderabad, Srinivas Reddy Amedapu, 09490 456 987, 08220 172 182, A.S.Reddy
Transcript:
• [email protected] Computer Programming Lab Solutions (as per JNTU Hyderabad Syllabus)Prepared by: Srinivas Reddy Amedapu, Full Time Research Scholar, CSE Department NATIONAL INSTITUTE OF TECHNOLOGY, TRICHY, TAMIL NADUDate: January 04, 2013 Email: [email protected], Phone: 08220 172 182 (TN), 09490 456 987 (AP)Week I (a) Write a program to find the sum of individual digits of a positive integer.#includevoid main(){ int num,d,sum,temp;printf("nEnter a positive integer : ");scanf("%d",&num);temp=num;sum=0;while(num){d=num%10;sum=sum+d;num/=10;}printf("nSum of digits of %d is %d",temp,sum);}Enter a positive integer : 1234Sum of digits of 1234 is 10Week I (b) A Fibonacci Sequence is defined as follows: the first and second terms in the sequence are0 and 1. Subsequent terms are found by adding the preceding two terms in the sequence. Write a Cprogram to generate the first n terms of the sequence.#includevoid main(){ int f1,f2,f3,n,i;printf("nHow many Fibonacci Sequence numbers you want? ");scanf("%d",&n);f1=0, f2=1;printf("nThe follwing are %d Fibonacci Numbersn",n);Srinivas Reddy Amedapu, Full Time Research Scholar, CSE DepartmentNATIONAL INSTITUTE OF TECHNOLOGY, TRICHY, TAMIL NADU1

of 55/55
Srinivas Reddy Amedapu, Full Time Research Scholar, CSE Department NATIONAL INSTITUTE OF TECHNOLOGY, TRICHY, TAMIL NADU 1 Computer Programming Lab Solutions (as per JNTU Hyderabad Syllabus) Prepared by: Srinivas Reddy Amedapu, Full Time Research Scholar, CSE Department NATIONAL INSTITUTE OF TECHNOLOGY, TRICHY, TAMIL NADU Date: January 04, 2013 Email: , Phone: 08220 172 182 (TN), 09490 456 987 (AP) Week I (a) Write a program to find the sum of individual digits of a positive integer. #include<stdio.h> void main() { int num,d,sum,temp; printf("\nEnter a positive integer : "); scanf("%d",&num); temp=num; sum=0; while(num) { d=num%10; sum=sum+d; num/=10; } printf("\nSum of digits of %d is %d",temp,sum); } Enter a positive integer : 1234 Sum of digits of 1234 is 10 Week I (b) A Fibonacci Sequence is defined as follows: the first and second terms in the sequence are 0 and 1. Subsequent terms are found by adding the preceding two terms in the sequence. Write a C program to generate the first n terms of the sequence. #include<stdio.h> void main() { int f1,f2,f3,n,i; printf("\nHow many Fibonacci Sequence numbers you want? "); scanf("%d",&n); f1=0, f2=1; printf("\nThe follwing are %d Fibonacci Numbers\n",n);
Embed Size (px)
Recommended

Documents

Documents

Documents

Documents

Documents

Documents

Documents

Documents

Documents

Documents

Documents

Documents

Documents

Documents

Documents

Documents

Documents

Documents