100% found this document useful (1 vote)
43 views

Control Structure Program

The document contains C code for several programs that perform operations like finding the largest of three numbers, checking if a character is a vowel, reversing a number, calculating sums of digits and numbers, finding factorials, printing tables, checking for prime numbers, generating Fibonacci sequences, and more.

Uploaded by

pankajusb
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 DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
43 views

Control Structure Program

The document contains C code for several programs that perform operations like finding the largest of three numbers, checking if a character is a vowel, reversing a number, calculating sums of digits and numbers, finding factorials, printing tables, checking for prime numbers, generating Fibonacci sequences, and more.

Uploaded by

pankajusb
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 DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

/* Program to find the largest among three numbers */ vowel", ch); #include<stdio.

h> main() { int a,b,c,large; printf(\nEnter three integers: ); scanf(%d%d%d,&a,&b,&c); } large=a>b?(a>c?a:c):(b>c?b:c); printf(\nLargeest number: %d\n\n,large); } /* Program to Check Whether a Character is a Vowel or not by using switch Statement */ #include <stdio.h> main() { char ch; printf("\nEnter any character: "); scanf("%c", &ch); switch (ch) { case 'a': case 'A': printf("\n\n%c is a vowel", ch); break; case 'e': case 'E': printf("\n\n%c is a vowel", ch); break; case 'i': case 'I': printf("\n\n%c is a vowel", ch); break; case 'o': case 'O': printf("\n\n%c is a vowel", ch); break; case 'u': }

case 'U': printf("\n\n%c is a break; default: printf("\n\n%c is not a vowel", ch); } getch();

/* Program to find the Reverse of a number */ #include <stdio.h> main() { long n; int rev=1,rem; printf("\nEnter any number: "); scanf("%ld", &n); printf("\nReverse no. is:\n\n"); while (n > 0) { rem = n % 10; n = n / 10; Rev=rev*10+rem; } printf("%d", rev); getch();

/* Program to Find the Sum of Digits of a Positive Integer */ #include <stdio.h> main() { long n; int digit, sum = 0; printf("\nEnter any number: "); scanf("%d", &n); while (n > 0) {

digit = n%10; n = n/10; sum = sum + digit; } printf("\n\nSum of digits: %d", sum); getch(); } /* Program to Find the Sum of Even and Odd Numbers from First 100 Positive Integers */ #include <stdio.h> main() { int i, sumEven=0, sumOdd=0; for (i=0; i<=100; i++) if (i%2 == 0) sumEven = sumEven + i; else sumOdd = sumOdd + i; printf("\nSum of first even 100 numbers: %d\n", sumEven); printf("\nSum of first odd 100 numbers: %d\n", sumOdd); getch(); } /* Program to Find the Sum of First 100 Positive Integers */ #include <stdio.h> main() { int i, sum=0; printf("\n\tSum of first 100 positive numbers\n"); for(i=0; i<=100; i++) sum = sum + i; printf("\nSum = %d", sum); getch(); }

/* Program to find the factorial of a number */ #include<stdio.h> main() { int num,i; long int factorial=1; printf(\nEnter an integer number: ); scanf(%d,&num); for(i=1;i<=num;i++) factorial*=i; printf(\nFactorial= %ld\n\n,factorial); } /**** Program to Print a Table of any Number ****/ #include <stdio.h> main() { int n, mul, i; printf("\nEnter any no.: "); scanf("%d", &n); for(i=1; i<=10; i++) { mul = n*i; printf("\n\n%d\tx\t%d\t=\t%d", n, i, mul); } getch(); } /*Program to Print First N Prime Numbers*/ #include <stdio.h> main() { int i, j, n; printf("\nEnter how many prime numbers you want to print: "); scanf("%d", &n); printf("\n2"); for (i=2; i<=n; i++) for (j=2; j<=i; j++) { if(i%j == 0) break;

else { printf("\n%d", i); break; } } getch(); } /* Program to find the sum of digits of a number */ #include<stdio.h> main() { int num,i,remainder,sum=0; printf(\nEnter the number: ); scanf(%d,&num); while(num>0) { remainder=num%10; sum+=remainder; num/=10; } printf(\nSum of digits: %d\n\n,sum); } /* Program to reverse a number */

/* Program to print the prime numbers within a range */ #include<stdio.h> main() { int rangeStart,rangeEnd,i,j,flag; printf(\nStart of range: ); scanf(%d,&rangeStart); printf(\nEnd of range: ); scanf(%d,&rangeEnd); for(i=rangeStart;i<=rangeEnd;i++) { flag=0; for(j=2;j<=i/2;j++) I f(i%j==0) flag=1; if(flag==0) printf(%d\t,i); } printf(\n\n); } /* Program to check whther the given number is prime or not */ #include<stdio.h>

#include<stdio.h> main() { int num,rem,temp,reverse=0; printf(\nEnter the number: ); scanf(%d,&num); temp=num; while(temp>0) { rem=temp%10; reverse=reverse*10+rem; temp/=10; } printf(\nThe reverse of the number: %d\n\n,reverse); } main() { int num,i,flag=0; printf(\nEnter the num: ); scanf(%d,&num); for(i=2;i<=num/2;i++) if(num%i==0) flag=1; if(flag==0) printf(\nThe given number is prime!\n\n); else printf(\nThe given number is not prime!\n\n); }

/* Program to generate n Fibonacci numbers */ #include<stdio.h> main() { int first=0,second=1,third,n,i; printf(\nEnter the value of n: ); scanf(%d,&n); printf(\nThe fibonacci series is \n); for(i=0;i<n;i++) { third=first+second; printf(%d\t,first); first=second; second=third; } printf(\n\n); }

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