0% found this document useful (0 votes)
42 views5 pages

Q1. Code For Fibonaaci Series

The document contains 5 code snippets for common programming problems: 1) A Fibonacci series generator 2) A program to find the greatest number from an array 3) A factorial calculator 4) A string reversal program 5) A numbers swapping program

Uploaded by

PranayPendota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views5 pages

Q1. Code For Fibonaaci Series

The document contains 5 code snippets for common programming problems: 1) A Fibonacci series generator 2) A program to find the greatest number from an array 3) A factorial calculator 4) A string reversal program 5) A numbers swapping program

Uploaded by

PranayPendota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Q1.

Code for Fibonaaci series

#include <stdio.h>

int main(int argc, char *argv[])

int n, first = 0, second = 1, next, c;

n = atol(argv[1]);

printf("First %d terms of Fibonacci series are :-\n",n);

for ( c = 0 ; c < n ; c++ )

if ( c <= 1 )

next = c;

else

next = first + second;

first = second;

second = next;

printf("%d\n",next);

return 0;

Q2. Code for greatest number.


#include <stdio.h>

int main(int argc, char *argv[])

int c[10];

int i,temp,j,greatest;

j = 0;

for(i=1; i<argc; i++)

temp = atoi(argv[i]);

c[j] = temp;

j++;

greatest = c[0];

for (i = 0; i < 10; i++) {

if (c[i] > greatest) {

greatest = c[i];

printf("Greatest of ten numbers is %d", greatest);

return 0;

Q3. Code of n!
#include <stdio.h>

int main(int argc, char *argv[])

int n,i;

unsigned long long factorial = 1;

n = atol(argv[1]);

for(i=1; i<=n; ++i)

factorial *= i;

printf("Factorial of %d = %llu", n, factorial);

Q4. Code for string reversal.

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

int main(int argc, char *argv[])

int k;

char temp;

int i,j=0;

int strsize = 0;
for (i=1; i<argc; i++) {

strsize += strlen(argv[i]);

if (argc > i+1)

strsize++;

char *cmdstring;

cmdstring = malloc(strsize);

cmdstring[0] = '\0';

for (k=1; k<argc; k++) {

strcat(cmdstring, argv[k]);

if (argc > k+1)

strcat(cmdstring, " ");

i = 0;

j = strlen(cmdstring) - 1;

while (i < j) {

temp = cmdstring[i];

cmdstring[i] = cmdstring[j];

cmdstring[j] = temp;

i++;

j--;

}
printf("\nReverse string is :%s", cmdstring);

return(0);

Q5. Code for swapping numbers.

#include <stdio.h>

int main(int argc, char *argv[])

double firstNumber, secondNumber, temporaryVariable;

firstNumber = atol(argv[1]);

secondNumber = atol(argv[2]);

temporaryVariable = firstNumber;

firstNumber = secondNumber;

secondNumber = temporaryVariable;

printf("\nAfter swapping, firstNumber = %.2lf\n", firstNumber);

printf("After swapping, secondNumber = %.2lf", secondNumber);

return 0;

You might also like