Some Hard and important programs.
Volunteer Post by : Yosuf Rizvi
This Post is send by YOUSUF RIZVI and he send us some Hard and Important programs in very easy programming.
Special thing about this post is here is many methods for all programs so it is up to you that what program will you prefer for preparation.and a he also send output.
Volunteer Post by : Yosuf Rizvi
This Post is send by YOUSUF RIZVI and he send us some Hard and Important programs in very easy programming.
Special thing about this post is here is many methods for all programs so it is up to you that what program will you prefer for preparation.and a he also send output.
Code
1:
1.
Write a program to generate the Fibonacci series.
#include<stdio.h>
int
main(){
int k,r;
long int i=0l,j=1,f;
//Taking maximum numbers form user
printf("Enter the number range:");
scanf("%d",&r);
printf("FIBONACCI SERIES: ");
printf("%ld %ld",i,j); //printing firts two values.
for(k=2;k<r;k++){
f=i+j;
i=j;
j=f;
printf(" %ld",j);
} return 0;
}
Sample output:
Enter the number
range: 15
FIBONACCI
SERIES: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
Code
2:
1. Fibonacci
series using array.
#include<stdio.h>
int
main(){
int i,range;
long int arr[40];
printf("Enter the number range: ");
scanf("%d",&range);
arr[0]=0;
arr[1]=1;
for(i=2;i<range;i++){
arr[i] = arr[i-1] + arr[i-2];
}
printf("Fibonacci series is: ");
for(i=0;i<range;i++)
printf("%ld ",arr[i]);
return 0;
}
Sample output:
Enter the number
range: 20
Fibonacci series is:
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
Code
3:
1. Fibonacci
series in c using while loop.
#include<stdio.h>
int
main(){
int k=2,r;
long int i=0l,j=1,f;
printf("Enter the number range:");
scanf("%d",&r);
printf("Fibonacci series is: %ld %ld",i,j);
while(k<r){
f=i+j;
i=j;
j=f;
printf(" %ld",j);
k++;
}
return 0;
}
Sample output:
Enter the number
range: 10
Fibonacci series is:
0 1 1 2 3 5 8 13 21 34
Algorithm:
Write
a c program to check given string is palindrome number or not
#include<string.h>
#include<stdio.h>
int
main(){
char *str,*rev;
int i,j;
printf("\nEnter a string:");
scanf("%s",str);
for(i=strlen(str)-1,j=0;i>=0;i--,j++)
rev[j]=str[i];
rev[j]='\0';
if(strcmp(rev,str))
printf("\nThe string is not a palindrome");
else
printf("\nThe string is a palindrome");
return 0;
}
Definition of Palindrome string:
A
string is called palindrome if it symmetric. In other word a string is called
palindrome if string remains same if its characters are reversed. For example:
asdsa
If
we will reverse it will remain same i.e. asdsa
Example of string
palindrome: a,b, aa,aba,qwertrewq etc.
Write a c program to find out sum of digit of given number
#include<stdio.h>
int main(){
int
num,sum=0,r;
printf("Enter
a number: ");
scanf("%d",&num);
while(num){
r=num%10;
num=num/10;
sum=sum+r;
}
printf("Sum
of digits of number: %d",sum);
return 0;
}
Sample output:
Enter a number: 123
Sum of digits of
number: 6
Source code of simple
bubble sort implementation using array ascending order in c programming language
#include<stdio.h>
int
main(){
int s,temp,i,j,a[20];
printf("Enter total numbers of elements: ");
scanf("%d",&s);
printf("Enter %d elements: ",s);
for(i=0;i<s;i++)
scanf("%d",&a[i]);
//Bubble sorting algorithm
for(i=s-2;i>=0;i--){
for(j=0;j<=i;j++){
if(a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("After sorting: ");
for(i=0;i<s;i++)
printf(" %d",a[i]);
return 0;
}
Output:
Enter
total numbers of elements: 5
Enter
5 elements: 6 2 0 11 9
After
sorting: 0 2 6 9 11
Write a c program
which takes password from users
C source code for password:
#include<stdio.h>
#define
MAX 500
int
main(){
char password[MAX];
char p;
int i=0;
printf("Enter the password:");
while((p=getch())!= 13){
password[i++] = p;
printf("*");
}
password[i] = '\0';
if(i<6)
printf("\nWeak password");
printf("\nYou have entered: %s",password);
return 0;
}
Sample output:
Enter the password:*******
You have entered: fgt67m,