# Introduction to programming in C Week 3

Course Name: Introduction to programming in C

Question 1

#### Complete the function int find_factorial(int k) to find the factorial of the positive number k.The factorial of a positive integer k, denoted by k!, is the product of all positive integers less than or equal to k.k!=k×(k−1)×⋯×1.InputThe first line of input is a positive integer N.The next line contains N positive integers ki for i=1 to N.OutputFor each ki given as input, print factorial of ki.

Code:-

``````#include <stdio.h>

int find_factorial(int k){
int i,f = 1;
for(i=1;i<=k;i++)
f*=i;
return f;
}

int main(){
int n,k;
scanf("%d",&n);

for(int i=0;i<n;i++){
scanf("%d",&k);
printf("%d ", find_factorial(k));
}

return 0;
}
``````

These are Introduction to programming in C Assignment 3 Answers

Question 2

Write a C function to find the kth occurrence of an odd integer in a sequence of non-negative integers, and then call your function from main.
Your function should be according to the following declaration:
int find_odd(int k);

Input
——–
You are given the input in two lines:
The first line contains a positive integer k.
In the second line, you will be given a sequence of numbers terminated with a -1.
You have to find the kth occurrence of an odd integer in the sequence.
Note:  The -1 is not part of the sequence.

Output
———-
If there are k odd numbers in the sequence, then output the kth occurrence of an odd number in the sequence, if present. If there are less than k odd numbers in the sequence, output -1.
Sample Input
——————
2
1 4 3 6 5 2 3 4 1 -1
Sample Output
——————–
3

Code:-

``````#include <stdio.h>
int find_odd(int k){
int x0=1,cnt=0;
while(x0!=-1)
{
scanf("%d",&x0);
if(x0%2)
++cnt;
if(cnt==k)
{
return x0;
break;
}
}
return -1;
}
int main(){
int k;
scanf("%d",&k);
printf("%d",find_odd(k));
return 0;
}``````

These are Introduction to programming in C Assignment 3 Answers

Question 3

The two moving average is the sequence of averages of the last 2 entries.
For the first number, no average is output.
For example, if the sequence of numbers is a1,a2,a3,a4,a5
The 2-moving average is (a1+a2)/2,(a2+a3)/2,(a3+a4)/2,(a4+a5)/2.

Code:-

``````#include <stdio.h>
int main()
{
int x0,x1;
scanf("%d",&x0);
while(1)
{
scanf("%d",&x1);
if(x1==-1)
break;
printf("%.1f ",((x0+x1)/2.0));

x0=x1;
}
return 0;
}``````

These are Introduction to programming in C Assignment 3 Answers
{"ft_lang_label":"__label__en","ft_lang_prob":0.7357551,"math_prob":0.99440396,"size":2702,"snap":"2023-40-2023-50","text_gpt3_token_len":770,"char_repetition_ratio":0.12564863,"word_repetition_ratio":0.14578588,"special_character_ratio":0.303849,"punctuation_ratio":0.1641791,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9995024,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-25T23:23:24Z\",\"WARC-Record-ID\":\"<urn:uuid:05d3ce22-78c5-472e-8817-fc8c7165a768>\",\"Content-Length\":\"91345\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:33af2403-5dc2-43b8-98b7-185a65d20314>\",\"WARC-Concurrent-To\":\"<urn:uuid:aa9fd4ce-0a0b-4331-a76c-5329f1039438>\",\"WARC-IP-Address\":\"13.127.89.110\",\"WARC-Target-URI\":\"https://progiez.com/introduction-to-programming-in-c-assignment-3-answers\",\"WARC-Payload-Digest\":\"sha1:MGEZCE47WXHWC77AVU7CKSODIHJIL5PQ\",\"WARC-Block-Digest\":\"sha1:LVW5ESCP33KLNRU72F32GLZDORDNYPKL\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510100.47_warc_CC-MAIN-20230925215547-20230926005547-00534.warc.gz\"}"}