Write a program to reverse a number.
#include <stdio.h>int main(){int no, rev = 0;printf("\n Enter No to make it Reverse : ");scanf("%d", &no);while (no > 0){rev = (rev * 10) + (no % 10);no = no / 10;}printf("\n Reverse of entered no is : %d", rev);return 0;}
Write a program to generate first n number of Fibonacci series.
#include <stdio.h>int main(){int no = 10, i = 0, j = 1;printf(" %d %d", i, j);while (no > 0){printf(" %d", i + j);j = i + j;i = j - i;no--;}return 0;}
Write a C program to find the sum and average of different numbers which are accepted by user as many as user wants.
#include <stdio.h>int main(){int no,sum=0,i=0,val;printf("\n How Many Number You Want to Enter : ");scanf("%d",&no);while(i<no){printf("Enter No [%d]:",i+1);scanf("%d",&val);sum=sum+val;i++;}printf("\n Sum = %d",sum);printf("\n Sum = %.2f",((float)sum)/no);return 0;}
Write a program to check whether the given number is prime or not
#include<stdio.h>int main() {int no, i;printf("\n Enter No to check wheather its prime or not :");scanf("%d", & no);for (i = 2; i < no; i++) {if (no % i == 0) {printf("\n %d is not prime", no);break;}}if (no == i) {printf("\n %d is prime", no);}return 0;}
0 Comments