BCA Programmer
Question for you Print the number from 0 to n, n is given by user.
#include <stdio.h>
int main(){
int n;
printf("Enter n : ");
scanf("%d", &n);
for(int i=0;i<=n;i++){
printf("%d\n", i,n);
}
return 0;
}
BCA Programmer
Question 2 for you Print the number from n to 0, n is given by user.
#include <stdio.h>
int main(){
int n;
printf("Enter n : ");
scanf("%d", &n);
for(int i=n;i>=0;i--){
printf("%d\n", i,n);
}
return 0;
}C program to print the sum of FIrst n Natural Numbers.
#include <stdio.h>
int main() {
int n;
printf("enter number : ");
scanf("%d", &n);
int sum = 0;
for(int i=1; i<=n; i++){
sum = sum + i;
}
printf("sum is %d \n", sum);
return 0;
}C program to print table of n.
#include <stdio.h>
int main() {
int n;
printf("Enter number : ");
scanf("%d", &n);
printf("Table of %d is : \n");
for(int i=1;i<=10;i++){
printf("%d\n", n*i);
}
return 0;
}
C program to take num as input from user until user enters an odd number.
#include <stdio.h>
int main(){
int n;
do{
printf("Enter number : ");
scanf("%d",&n);
printf("%d\n",n);
if(n%2 !=0){
break;
}
} while(1);
return 0;
}C program to print all odd nums between 5 to 50.
#include <stdio.h>
int main() {
for(int i=5;i<=50;i++){
if (i%2 !=0){
printf("%d\n", i);
}
}
return 0;
}
π1
"C" program that reads a character and prints out whether or not
it is a vowel or a consonant.
#include <stdio.h>
int main(){
char ch;
printf("Enter letter : ");
scanf("%c", &ch);
if(ch =='a' ch =='e' ch =='i' ch =='o' ch =='u'
ch =='A' ch =='E' ch =='I' ch =='O'|| ch =='U'){
printf("%c is a Vowel\n", ch);
}
else {
printf("%c is a Consonent" ,ch);
}
return 0;
}
it is a vowel or a consonant.
#include <stdio.h>
int main(){
char ch;
printf("Enter letter : ");
scanf("%c", &ch);
if(ch =='a' ch =='e' ch =='i' ch =='o' ch =='u'
ch =='A' ch =='E' ch =='I' ch =='O'|| ch =='U'){
printf("%c is a Vowel\n", ch);
}
else {
printf("%c is a Consonent" ,ch);
}
return 0;
}
π1
C program to calculate factorial of n number.
#include <stdio.h>
int main() {
int n;
printf("Enter a number : ");
scanf("%d", &n);
int fact = 1;
for(int i=1;i<=n;i++){
fact = fact * i;
}
printf("Final factorial is %d ",fact);
return 0;
}
C program to print table of n number in reverse order.
#include <stdio.h>
int main(void) {
int n;
printf("Enter a number ");
scanf("%d", &n);
printf("Table of %d is : \n");
for(int i=10;i>=1;i--)
{
printf("%d\n", n*i);
}
return 0;
}
C program to calculate the sum of all numbers between 5 and 50 (including 5 & 50)
#include <stdio.h>
int main(void) {
int sum = 0;
for(int i=5;i<=50;i++)
sum = sum + i; //or we can use sum += i
{
printf("%d is the answer\n", sum);
}
return 0;
}
Write a C program that reads in three integers and prints "equal" if all three are equal, and "not equal" otherwise.
#include <stdio.h>
int main(){
int a,b,c;
printf("Enter number : ");
scanf("%d%d%d", &a,&b,&c);
if(a == b && b == c){
printf("Equal\n");
}
else {
printf("Not Equal\n");
}
return 0;
}
C program to print no is prime or non prime
#include <stdio.h>
int main() {
int n, i;
printf("Enter a positive integer: ");
scanf("%d", &n);
for (i = 2; i < n; i++) {
if (n % i == 0) {
printf("%d is not a prime number\n", n);
return 0;
}
}
printf("%d is a prime number\n", n);
return 0;
}
π2π₯1
print Hello world using function
@bca_programmer
#include <stdio.h>
//decleration /prototype
void printhello();
int main() {
printhello(); //function call
return 0;
}
//function decleration
void printhello(){
printf("Hello world\n");
}
@bca_programmer
it will print Hello world 4 times because we called function 4 times
@bca_programmer
#include <stdio.h>
void printhello();
int main() {
printhello();
printhello();
printhello();
printhello();
return 0;
}
void printhello(){
printf("Hello world\n");
}
@bca_programmer
print Namaste if user is Indian else print 'Bonjour' if user is French.
@bca_programmer
#include <stdio.h>
void Namaste();
void Bonjour();
int main() {
printf("Enter 'f' for french 'i' for indian : ");
char ch;
scanf("%c", &ch);
if(ch == 'i'){
Namaste();
}
else {
Bonjour();
}
return 0;
}
void Namaste(){
printf("Namaste\n");
}
void Bonjour(){
printf("Bonjour\n");
}
@bca_programmer
write a C program to sum two integer using function
@bca_programmer
#include <stdio.h>
int sum(int a,int b);
int main(){
int a, b;
printf("enter a : ");
scanf("%d", &a);
printf("enter b : ");
scanf("%d", &b);
int s = sum(a,b);
printf("%d is sum: ", s);
return 0;
}
int sum(int a,int b){
return a+b;
}@bca_programmer
drive-download-20230103T181420Z-001.zip
4.2 MB
π1π₯°1π1