Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Organizing Events at CASE: Suggestions for Efficient Planning, Lecture notes of Programming Methodologies

Suggestions from instructor Adeel Shabbir on how to organize events at CASE efficiently. topics such as dividing problems into smaller manageable parts, indoor and outdoor activities, and the use of functions to simplify code. The document also includes examples of factorial code and the calculation of sums of factorials of even numbers.

Typology: Lecture notes

2021/2022

Uploaded on 05/29/2022

manahil-urooj
manahil-urooj 🇵🇰

1 / 102

Toggle sidebar

Related documents


Partial preview of the text

Download Organizing Events at CASE: Suggestions for Efficient Planning and more Lecture notes Programming Methodologies in PDF only on Docsity! Instructor Adeel Shabbir ◦Functions Adeel Shabbir CASE 1 Programming in C WHAT HURTS MORE. THE PAIN OF HARD Work OR THE PAIN OF REGRET? I am President CASE and I want to organize different events at CASE.     You are Programmers.  I am not Interested in organizing event just for one time.  But next time I don't want to spend time on events on which I have already Spend a lot of time.  Give Suggestions so that with passage of time things become simple and manageable.  Do u remember story of ◦ LAKARHARA n us k Betay  Yes divide your problems into small problems and it becomes easy to solve small problems                                                                                     Indoor Activities  outdoor Activities  Sports  Trips outDoor Find Factorial of a number void main() { int r,c,f,n; n=5; f=1; for(c=1;c<=n;c=c+1) { f=f*c; } printf(“%d”,f); } void main() { int r,c,f,n; n=5; f=1; for(c=1;c<=n;c=c+1) { f=f*c; } printf(“%d”,f); } Lets Separate the Factorial code using { and } void main() { int r,c,f,n; n=5; { f=1; for(c=1;c<=n;c=c+1) { f=f*c; } printf(“%d”,f); } } void main() { int r,c,f,n; n=5; factorial() { f=1; for(c=1;c<=n;c=c+1) { f=f*c; } printf(“%d”,f); } } Lets put the factorial code separate from main Function factorial() { f=1; for(c=1;c<=n;c=c+1) { f=f*c; } printf(“%d”,f); } What is the value of n??? factorial() { n=5; f=1; for(c=1;c<=n;c=c+1) { f=f*c; } printf(“%d”,f); } Means this is a Fixed Code???  Int factorial(int n) { int c,f; f=1; for(c=1;c<=n;c=c+1) { f=f*c; } printf(“%d”,f); return f; } Void main() { int n,fn; scanf(“%d”,&n); fn=factorail(n); printf(“factorial of %d =%d”,n,fn); }  Cricket Team Example 2  Find if a number is even or odd  Find factorial of a number  Find sum of numbers  Print table of a number  Void main()  {  } void main() { int n; for(a=1;a<=100;a=a+1) { } } Int factorial(int n) { int c,f; f=1; for(c=1;c<=n;c=c+1) { f=f*c; } printf(“%d”,f); return f; } Table of a Number void table(int n) { int c,t; for(c=1;c<=10;c=c+1) { t=n*c; printf(“\n%d*%d= %d”,n,c,t); } } void main() { int a,b,n,fn; for(a=1;a<=100;a=a+1) { b=a%2; if(b==0) { //a is even } else { //a is odd } } } Even Odd void main() {int a,b,n,fn; for(a=1;a<=100;a=a+1) { b=a%2; if(b==0) { f=1; for(c=1;c<=a;c=c+1) { f=f*c; } printf(“%d”,f); } else { //a is odd } } } Factorial of Even Number void main() {int a,b,n,fn; for(a=1;a<=100;a=a+1) { b=a%2; if(b==0) { } else { for(c=1;c<=10;c=c+1) { t=a*c; printf(“\n%d*%d=%d”,a,c,t); } } } } Table of Odd Numbers Which code is Easy to read write Understand Debug change ????????????????????????  So Functions are to MAKE YOUR LIFE EASY.  Zindagi Assan ho jati ha Functions sa      You are forgetting one thing void main() {int a,b,n,fn; for(a=1;a<=100;a=a+1) { b=a%2; if(b==0) { f=1; for(c=1;c<=a;c=c+1) { f=f*c; } Sum=sum+fn; printf(“%d”,sum); } else {  for(c=1;c<=10;c=c+1) { t=n*c; printf(“\n%d*%d=%d”,n,c,t);  } } } } Even Odd void main() { int a,b,n,fn; for(a=1;a<=100;a=a+1) { b=a%2; if(b==0) { fn=factorial(a); sum=sum+fn; } else { Table(a); } } }  Find sum of series 1!+2!+3!+4!+5! void main() { int a,b,n,fn,sum; sum=0; for(a=2;a<=6;a=a+1) { fn=factorial(a); sum=sum+fn; } printf(“%d”,sum); }  Find sum of series 1!+3!+5!+7!+9! void main() { int a,b,n,fn,sum; sum=0; for(a=1;a<=10;a=a+2) { fn=factorial(a); sum=sum+fn; } printf(“%d”,sum); }  Find sum of series 1 /1!+ 1 / 2!+ 1 / 3!+ 1 /4!+ 1 / 5! void main() { int a,b,n,fn,sum; sum=0; for(a=1;a<=5;a=a+1) { fn=factorial(a); sum=sum+1/fn; } printf(“%d”,sum); }  Find sum of series  2 /1!+ 2 / 2!+ 2 / 3!+ 2 /4!+ 2 / 5! void main() { int a,b,n,fn,sum; sum=0; for(a=1;a<=5;a=a+1) { fn=factorial(a); sum=sum+a/fn; } printf(“%d”,sum); }  Find sum of series 1 /2!+ 2 / 4!+ 3 / 6!+ 4 /8!+ 5 / 10! void main() { int a,b,n,fn,sum; sum=0; for(a=1;a<=5;a=a+1) { b=2*a; fn=factorial(b); sum=sum+a/fn; } printf(“%d”,sum); } void main() { int a,b,n,fn,sum; sum=0; for(a=1;a<=5;a=a+1) { b=2*a; C=a*10; fn=factorial(b); sum=sum+c/fn; } printf(“%d”,sum); } void main() { int a,b,n,fn,sum; sum=0; b=2; c=10; for(a=1;a<=5;a=a+1) { fn=factorial(b); sum=sum+c/fn; b=b+2; c=c+10; } printf(“%d”,sum); }  Int sq(int n)  {  int c;  c=n*n;  return c;  } int power(int b,int p) { int c; int f=1; for(c=1;c<=5;c++) { f=f*2; } return c; } int power(int b,int p) { int c; int f=1; for(c=1;c<=p;c++) { f=f*2; } return c; } int power(int b,int p) { int c; int f=1; for(c=1;c<=p;c++) { f=f*b; } return c; } int read1darray(int *arr,int n) { int c; for(c=0;c<n;c++) { scanf(“%d”,&arr[a]); } } int print1darray(int *arr,int n) { int c; for(c=0;c<n;c++) { printf(“%d”,arr[a]); } } int read2darray(int arr[][5],int nr) { int r,c; for(r=0;r<nr;r++) { for(c=0;c<nr;c++) { scanf(“%d”,&arr[r][c]); } } }
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved