×
You can use excuses to convince others, but how will you convince yourself?
--Your friends at LectureNotes
Close

Note for Programming in C - C By Amit Jena

  • Programming in C - C
  • Note
  • Gandhi Institute of Technology and Management -
  • Computer Science Engineering
  • 737 Views
  • 15 Offline Downloads
  • Uploaded 1 year ago
Amit Jena
Amit Jena
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-1

1 Objective : 1 To find the sum of individual digits of a given number Description: Sum of the individual digits means adding all the digits of a number Ex: 123 sum of digits is 1+2+3=6 Algorithm: Step 1: start Step 2: read n Step 3: initialize the s=0 Step 4: if n<0 goto Step 7 Step 5: if n!=0 goto Step 6 else goto step 7 Step 6: store n%10 value in p Add p value to s Assign n/10 value to n Goto Step 5 Step 7: print the output Step 8:stop

Text from page-2

2 Flowchart: START S=0 READ N TRUE OUTPU T IF N<0 FALSE WHILE N! =0 TRUE STOP P=N%10 S=S+P N=N/10

Text from page-3

3 Program: #include<stdio.h> main() { int n,s,p; clrscr(); printf("enter the vaue for n:\n"); scanf("%d",&n); s=0; if(n<0) printf("The given number is not valid"); else { while(n!=0) /* check the given value =0 or not */ { p=n%10; n=n/10; s=s+p; } printf("sum of individual digits is %d",s); } getch(); } Output: 1.Enter the value for n: 333 Sum of individual digits is 9 2.Enter the value for n: 4733 Sum of individual digits is 17 3. Enter the value for n: -111 The given number is not valid Conclusion : The program is error free VIVA QUESATIONS: 1) What is the mean of sum of the individual digits? Ans: Sum of the individual digits means adding each digit in a number 2) What is positive integer? Ans: if the integer value is grater than zero then it is called positive integer 3) Define preprocessor ? Ans: Before compiling a process called preprocessing is done on the source code by a program called the preprocessor.

Text from page-4

4 Objective:2 To print the Fibonacci series for 1 to n value Description A fibonacci series is defined as follows The first term in the sequence is 0 The second term in the sequence is 1 The sub sequent terms 1 found by adding the preceding two terms in the sequence Formula: let t1,t2,…………tn be terms in fibinacci sequence t1=0, t2=1 tn=tn-2+tn-1……where n>2 algorithm: Step 1: start Step 2: initialize the a=0, b=1 Step 3: read n Step 4: if n== 1 print a go to step 7. else goto step 5 Step 5: if n== 2 print a, b go to step 7 else print a,b Step 6: initialize i=3 i) if i<= n do as follows. If not goto step 7 c=a+b print c a=b b=c increment I value goto step 6(i) Step 7: stop

Lecture Notes