0% found this document useful (0 votes)
58 views

Simple C Progs

The document contains summaries of several C programs that perform tasks like: - Checking if a number is even or odd - Checking if a year is a leap year - Finding the sum of digits in a number - Checking if a number is Armstrong - Printing patterns like odd numbers, numbers in reverse order, Fibonacci series - Performing operations using functions
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Simple C Progs

The document contains summaries of several C programs that perform tasks like: - Checking if a number is even or odd - Checking if a year is a leap year - Finding the sum of digits in a number - Checking if a number is Armstrong - Printing patterns like odd numbers, numbers in reverse order, Fibonacci series - Performing operations using functions
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 11

Program To Read A Number And Find Whether The Given Number Is Even Or Odd. # include <stdio.h> # include <conio.

h> main() {int n,r; clrscr(); printf(ENTER A NUMBER ;); scanf(%d, &n); r=n%2; if(r= = 0) printf(the above given number is even number); else printf(the above given number is odd number); getch(); } Program to accept a year and check whether the given year IS leap year or not. # include <stdio.h> # include <conio.h> main( ) {int y; clrscr( ); printf(enter a year:); scanf(%d,&y); if(y%4==0& &y%100!=0|| y%400==0); printf(the above given year IS a leap year); else printf(the above given year IS not a leap year); getch(); }

Individual Digits # include <stdio.h> # include <conio.h> main( ) {int a,b,c,d; clrscr( ); printf ( Enter a two digit number :); scanf ( %d, &a); b=a/10; c=a%10; d=b+c; printf (sum of individual digits of given numbers id %, d); getch( ); } Program to accept a three digit number and print the sum of individual digits. # include <stdio.h> # include <conio.h> main( ) {int a,b,c,n, sum; clrscr( ); printf ( Enter a Three Digit Number:); scanf (%d,&n); a=n/100; b=( (n%100)/10); c=n%10; sum=a+b+c; printf ( Sum of Individual Digits of Given Numbers is %d, Sum); getch( ); } Program to accept a number and check the given number is Armstrong or not. # include <stdio.h> # include <conio.h> main( )

{int n, a, b, c, d; clrscr( ); printf ( Enter a Three Digit Number: ); scanf (%d, &n); a=n/100; b=((n/10)%10); c=n%10; d=a*a*a*+b*b*b +c*c*c; if (n= =d) printf (The Given Number is Armstrong number); else printf (The Given Number is Not Armstrong number); getch( ); } Program to print ODD numbers from 1 to 10 # include <stdio.h> # include <conio.h> main( ) {int i; clrscr( ); for (i=1; i<=10; i+=2) printf(%d\n,i); getch( ); } Program to print natural numbers from 1 to 10 in Reverse # include <stdio.h> # include <conio.h> main( ) {int i; clrscr( ); for (i=10; i>=1; i--) printf(%d\n,i);

getch( ); } Program to print sum of the natural numbers from 1 to 10. # include <stdio.h> # include <conio.h> main( ) {int n,sum=0,i; clrscr( ); for (i=1; i<=10; i++) sum=sum+i; printf(sum of natural numbers from 1 to 10 is %d\n,sum); getch( ); } Program to accept a number and print mathematical table of the given no. # include <stdio.h> # include <conio.h> main( ) {int i,t; clrscr( ); printf(which table u want:); scanf(%d,&t); for (i=1; i<=10; i++) printf(\n%d*%d=%d,t,i,i*t); getch( ); } Program to print 1 to 10 mathematical tables # include <stdio.h> # include <conio.h> main( ) {int i,j;

clrscr( ); for (i=1; i<=10; i++) for(j=1;j<=10;j++) printf(\n%d*%d=%d,i,j,i*j); getch( ); } Program to print fibonacci series . # include <stdio.h> # include <conio.h> main( ) {int a=0,b=1,c=0,i; clrscr( ); printf(%d,a); printf(\n%d,b); for (i=1; i<=10; i++) {c=a+b; printf(\n%d,c); a=b; b=c; }getch( ); } Program to print numeric pyramid # include <stdio.h> # include <conio.h> main() {int i,j; clrscr( ); for(i=1;i<=5;i++) {for(j=1;j<=i;j++) printf(%d,j); printf(\n); }getch(); }

Program to accept a character in the uppercase and print in lower case. # include <stdio.h> # include <conio.h> main( ) {char ch,c1; clrscr( ); printf(enter a cha in uppercase); ch=getchar(); c1=ch+32; printf(the given char in lowercasecase is); putchar(c1); getch(); } Program to natural number from 1 to 10 by using while loop. # include <stdio.h> # include <conio.h> main( ) {int a=0; clrscr(); while( a<10) { a=a+1; printf(%d\n,a); }getch(); } Program to accept two numbers and print sum of two numbers by using functions # include <stdio.h> # include <conio.h> main( ) {int a,b,c; clrscr(); printf(enter the value for a:)

scanf(%d,&a); printf(enter the value for b:) scanf(%d,&b); c=add(a,b); printf(sum of two numbers is %d,c); getch( ); }int add(int x, int y) { int z; z=x+y; return z; } Program to accept a number and find factorial of given number # include <stdio.h> # include <conio.h> main( ) {int n,f; clrscr( ); printf(enter a number:) scanf(%d,&n); f= fact(n); printf(factorial value is %d,f); getch(); }int fact(int n) {int i, fa=1; for(i=n;i>=1;i--) fa=fa*i; return fa; } Program to accept a number and check the given number Armstrong or not # include <stdio.h> # include <conio.h> main( ) {int n,arm; clrscr(); printf(enter any 3 digit number:) scanf(%d,&n); arm= armstrong(n);

if(arm= =n) printf(%d is Armstrong number,n); else printf(%d not a Armstrong number,n); getch( ); }int Armstrong (int n) {int a,b,c,d; a=n/100; b=((n/10)%10); c=n%10; d=a*a*a+b*b*b+c*c*c; return d; } Program to accept a number and print the sum of given and Reverse number # include <stdio.h> # include <conio.h> main( ) {int a,b,n; clrscr( ); printf(enter a number:) scanf(%d,&n); a=rev(n); printf(REVERSE OF A GIVEN NUMBER IS %d,a); b=add(n,a); printf(\n sum of a given and reverse number is %d,b); getch( ); }int rev( int n) {int r,rev=0,s; while(n>0) {r=n%10; rev=rev*10+r; n=n/10; }return rev; }int add(int n, int a) {

return n+a; } Program to accept 10 numbers and print first five numbers in original order and print last five numbers in reverse order. # include <stdio.h> # include <conio.h> main( ) {int i,a[10]; for(i=0;i<10;i++) {printf(enter value for a[%d],i); scanf(%d,&a[i]); }for(i=0;i<=4;i++) printf(\nA[%d]=%d,i,a[i]); for(i=9;i>=5;i--) printf(\nA[%d]=%d,i,a[i]); getch( ); } Program to print prime number between 1100 # include <stdio.h> # include <conio.h> main( ) { int i,n,c; clrscr( ); for(n=1;n<=100;n++) {c=0; for(i=1;i<=n;i++) if(n%i==0) c++; if(c==2) printf(\n%d,n); }getch( ); }

Program to accept a string and find the length of the string # include <stdio.h> # include <conio.h> main( ) { char name[80]; int i; clrscr( ); printf(enter a string ;); for(i=0;i<80&&((name[i]=getchar( ))! =\n);i++); printf(%d is the size of string,i); getch( ); }

Program to check whether a given number is Armstrong or not. # include <stdio.h> # include <conio.h> main( ) {int i,n,s,r,k; clrscr( ); printf(enter a number); scanf(%d,&n); k=n; s=0; while(n>0) {r=n%10; s=s+(r*r*r); n=n/10; }if(k==s) printf(given number is Armstrong %d,k); else printf(given number is not Armstrong %d,k); }getch();

Program to accept two numbers and interchange two values using functions. #include<conio.h> #include<stdio.h> void swap (int a, int b); main( ) {int a,b; clrscr( ); printf(enter value for a;); scanf(%d,&a); printf(enter value for b;); scanf(%d,&b); swap(a,b); getch( ); } void swap(int a,int b) }int c; c=a; a=b; b=c; printf(\na=%d,a); printf(\nb=%d,b); }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy